Correct web server check

This commit is contained in:
jacob.eva 2023-09-21 18:31:00 +01:00
parent 814f854040
commit 78072dcce7
No known key found for this signature in database
GPG Key ID: 0B92E083BBCCAA1E

View File

@ -18,23 +18,18 @@ index=0
for vhost in ${domains[@]}; do # for each vhost for vhost in ${domains[@]}; do # for each vhost
[ ! -d "$certdir[$index]" ] && # if default cert dir for the vhost doesn't exist [ ! -d "$certdir[$index]" ] && # if default cert dir for the vhost doesn't exist
certdir[$index]=$(certbot certificates 2>/dev/null | grep "Domains:.* \(\*\.$domain\|$vhost\)\(\s\|$\)" -A 2 | awk '/Certificate Path/ {print $3}' | head -n1) # set cert dir for certificate certdir[$index]=$(certbot certificates 2>/dev/null | grep "Domains:.* \(\*\.$domain\|$vhost\)\(\s\|$\)" -A 2 | awk '/Certificate Path/ {print $3}' | head -n1) # set cert dir for certificate
((index++)) ((index++))
[ ! -d "$certdir[$index]" ] && # if there is no certificate for the domain [ ! -d "$certdir[$index]" ] && # if there is no certificate for the domain
case "$(netstat -tulpn | grep ":80\s")" in if [ systemctl is-active --quiet nginx ]
*nginx*) # if nginx is running then
pacman -S --noconfirm python3-certbot-nginx pacman -S --noconfirm python3-certbot-nginx
certbot -d "$vhost" certonly --nginx --register-unsafely-without-email --agree-tos # request cert with nginx certbot -d "$vhost" certonly --nginx --register-unsafely-without-email --agree-tos # request cert with nginx
;; else
#*apache*) # if apache is running pacman -S --noconfirm certbot
# pacman -S --noconfirm python3-certbot-apache certbot -d "$vhost" certonly --standalone --register-unsafely-without-email --agree-tos # request cert with certbot
# certbot -d "$vhost" certonly --apache --register-unsafely-without-email --agree-tos # request cert with apache fi
# ;; esac
*) # otherwise
pacman -S --noconfirm certbot
certbot -d "$vhost" certonly --standalone --register-unsafely-without-email --agree-tos # request cert with certbot
;;
esac
[ ! -d "$certdir[$index]" ] && echo "Error locating or installing SSL certificate." && exit 1 [ ! -d "$certdir[$index]" ] && echo "Error locating or installing SSL certificate." && exit 1
done done