Files
VPS-scripts_Web-V2/Scripts/EnableSSL.sh

30 lines
1.2 KiB
Bash

#Setting Vars
confname=CONFname
domain=DOMAINname
domainwww=DomainWWW
email=Email
webserv=WebServer
webservice=WebServer
#Correcting service name for Apache
if [ $webservice = apache ]; then
webservice=apache2
fi
#Backing-up and removing current config
sed -n '/#beginConf/,/#endConf/p' /etc/"$webservice"/sites-available/"$confname"_nossl > /tmp/"$confname"-config
sed -n -i '/#beginConf/{:a;N;/#endConf/!ba;N;s/.*\n/#ConfHere\n/};p' /etc/"$webservice"/sites-available/"$confname"_nossl
systemctl reload $webservice
#Enabling SSL
if [ $domainwww = 1 ]; then
certbot --"$webserv" certonly -n -d "$domain" -d "www.$domain" -m "$email" --hsts --redirect --no-eff-email --agree-tos
elif [ $domainwww = 0 ]; then
certbot --"$webserv" certonly -n -d "$domain" -m "$email" --hsts --redirect --no-eff-email --agree-tos
fi
#Restoring config
sed -i -e "0,/^#ConfHere/s/\(^#Conf.*\)/#ConfHere1 /" -e "/#ConfHere1/ r /tmp/"$confname"-config" -e '/#ConfHere/c\' /etc/"$webservice"/sites-available/"$confname"_ssl
rm /etc/"$webservice"/sites-enabled/"$confname"
ln -s /etc/"$webservice"/sites-available/"$confname"_ssl /etc/"$webservice"/sites-enabled/"$confname"
systemctl reload $webservice