config/bash: new (iridion) helpers
This commit is contained in:
parent
67eb994037
commit
a5cfef796c
|
@ -14,6 +14,8 @@ alias scr="$sudo systemctl daemon-reload && $sudo systemctl reload-or-restart"
|
||||||
alias hist='history | less'
|
alias hist='history | less'
|
||||||
alias m='mv -vi'
|
alias m='mv -vi'
|
||||||
|
|
||||||
|
alias nginx-edit="sudo vi /etc/nginx/nginx.conf && nginx -t && sudo systemctl reload nginx"
|
||||||
|
|
||||||
# Fast Find
|
# Fast Find
|
||||||
ff() {
|
ff() {
|
||||||
name=$1
|
name=$1
|
||||||
|
@ -22,6 +24,12 @@ ff() {
|
||||||
find "$@" -name "*$name*"
|
find "$@" -name "*$name*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xtrace () {
|
||||||
|
set -x
|
||||||
|
"$@"
|
||||||
|
set +x
|
||||||
|
}
|
||||||
|
|
||||||
highlight() { echo "[4m$1[0m"; }
|
highlight() { echo "[4m$1[0m"; }
|
||||||
status() {
|
status() {
|
||||||
highlight 'System'
|
highlight 'System'
|
||||||
|
|
|
@ -1,6 +1,43 @@
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
alias localip="ip addr show | grep -E '(ens|eth)' | grep -oP '"'(?<=inet\s)\d+(\.\d+){3}'"' | head -1"
|
alias localip="ip addr show | grep -E '(ens|eth)' | grep -oP '"'(?<=inet\s)\d+(\.\d+){3}'"' | head -1"
|
||||||
|
ip=$(localip)
|
||||||
|
|
||||||
|
logs() {
|
||||||
|
if test $# -eq 0
|
||||||
|
then
|
||||||
|
lnav $(pwd | cut -d '/' -f1-5)/{logs,document_errors}
|
||||||
|
else
|
||||||
|
for site in $(find /home -maxdepth 3 -name "*$1*")
|
||||||
|
do cd $site
|
||||||
|
lnav logs
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor() {
|
||||||
|
file=gatus.yaml
|
||||||
|
echo 'customer-endpoint: &customer
|
||||||
|
interval: 10m
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
endpoints:' >$file
|
||||||
|
for user in $(list users)
|
||||||
|
do group="$(hestia v-list-user $user | head -3 | cut -d':' -f2 | tr -s ' ' | sed 'N;s/\n/:/;N;s/\n / (/;s/$/)/')"
|
||||||
|
for domain in $(hestia v-list-web-domains $user | grep "$ip" | awk '{print $1}')
|
||||||
|
do echo '- name: "'$domain'"
|
||||||
|
<<: *customer
|
||||||
|
group: "'$group'"
|
||||||
|
url: "https://'$domain'"' >>$file
|
||||||
|
done
|
||||||
|
for domain in $(hestia v-list-mail-domains $user | tail +3 | awk '{print $1}')
|
||||||
|
do echo '- name: "Mail '$domain'"
|
||||||
|
<<: *customer
|
||||||
|
group: "'$group'"
|
||||||
|
url: "https://mail.'$domain'"' >>$file
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
letsencrypt() {
|
letsencrypt() {
|
||||||
if test $# -eq 0
|
if test $# -eq 0
|
||||||
|
@ -10,7 +47,6 @@ letsencrypt() {
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
(
|
(
|
||||||
ip=$(localip)
|
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for user
|
for user
|
||||||
do
|
do
|
||||||
|
@ -20,15 +56,22 @@ letsencrypt() {
|
||||||
for domain in $(hestia v-list-mail-domains $user | tail +3 | awk '{print $1}')
|
for domain in $(hestia v-list-mail-domains $user | tail +3 | awk '{print $1}')
|
||||||
do hestia v-list-mail-domain-ssl $user $domain | grep -q . || hestia v-add-letsencrypt-domain $user $domain '' yes
|
do hestia v-list-mail-domain-ssl $user $domain | grep -q . || hestia v-add-letsencrypt-domain $user $domain '' yes
|
||||||
done
|
done
|
||||||
for domain in $(hestia v-list-web-domains $user | grep $ip | awk '{print $1}')
|
for domain in $(hestia v-list-web-domains $user | grep "$ip" | awk '{print $1}')
|
||||||
do #echo commented out due to command echoing in hestia alias
|
do #echo commented out due to command echoing in hestia alias
|
||||||
#echo "Checking $user $domain" >&2
|
#echo "Checking $user $domain" >&2
|
||||||
hestia v-list-web-domain $user $domain | grep -q REDIRECT && continue
|
hestia v-list-web-domain $user $domain | grep -q REDIRECT && continue
|
||||||
#hestia v-list-mail-domain-ssl $user $domain | grep -q . || hestia v-add-letsencrypt-domain $user $domain '' yes
|
#hestia v-list-mail-domain-ssl $user $domain | grep -q . || hestia v-add-letsencrypt-domain $user $domain '' yes
|
||||||
hestia v-list-web-domain-ssl $user $domain | grep -q . && continue
|
hestia v-list-web-domain-ssl $user $domain | grep . >/dev/null && continue
|
||||||
#echo "Generating Certificate" >&2
|
#echo "Generating Certificate" >&2
|
||||||
hestia v-add-letsencrypt-domain $user $domain $(hestia v-list-web-domain $user $domain | grep ALIAS | tr -s ' ' | cut -d' ' -f2- | tr ' ' ',')
|
hestia v-add-letsencrypt-domain $user $domain $(hestia v-list-web-domain $user $domain | grep ALIAS | tr -s ' ' | cut -d' ' -f2- | tr ' ' ',')
|
||||||
done
|
done
|
||||||
|
echo "Waiting an hour to not trigger letsencrypt rate limits..."
|
||||||
|
time=0
|
||||||
|
while test $time -lt 2000
|
||||||
|
do sleep 100
|
||||||
|
sudo -v
|
||||||
|
time=$((time + 100))
|
||||||
|
done
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
@ -46,7 +89,7 @@ list() {
|
||||||
done
|
done
|
||||||
else if test -t 1
|
else if test -t 1
|
||||||
then sudo "$HESTIA/bin/v-list-$type" "$@" | column -t
|
then sudo "$HESTIA/bin/v-list-$type" "$@" | column -t
|
||||||
else sudo "$HESTIA/bin/v-list-$type" "$@" | tail +3 | awk '{print $1}'
|
else sudo "$HESTIA/bin/v-list-$type" "$@" | tail +3 | $(if test $type = users; then echo "grep -v yes"; else echo cat; fi) | awk '{print $1}'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -56,7 +99,7 @@ hestia() {
|
||||||
test "$1" = "-x" && shift && set -x
|
test "$1" = "-x" && shift && set -x
|
||||||
command=$1
|
command=$1
|
||||||
shift
|
shift
|
||||||
echo '>' sudo $(which $command) "$@" >&2
|
echo '>' sudo "$(which $command)" "$@" >&2
|
||||||
export SHELLOPTS
|
export SHELLOPTS
|
||||||
sudo --preserve-env=SHELLOPTS timeout 30s $(which $command) "$@"
|
sudo --preserve-env=SHELLOPTS timeout 30s $(which $command) "$@"
|
||||||
set +x
|
set +x
|
||||||
|
|
Loading…
Reference in New Issue