From ac274cee343b783a12698e510787ce26d93ac3ac Mon Sep 17 00:00:00 2001 From: bprieshof Date: Wed, 11 Dec 2019 11:53:57 +0100 Subject: [PATCH] Add 'Scripts/EnableSSL.sh' --- Scripts/EnableSSL.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Scripts/EnableSSL.sh diff --git a/Scripts/EnableSSL.sh b/Scripts/EnableSSL.sh new file mode 100644 index 0000000..8286ff3 --- /dev/null +++ b/Scripts/EnableSSL.sh @@ -0,0 +1,26 @@ +#Setting Vars +domain=DomainName +domainwww=DomainWWW +email=Email +webserver=WebServer +webservice=WebServer +if [ $webservice = apache ]; then + webservice=apache2 +fi + +#Backing-up and removing current config +sed -n '/#beginConf/,/#endConf/p' /etc/"$webservice"/sites-enabled/"domain" > /tmp/"$domain"-config +sed -n -i '/#beginConf/{:a;N;/#endConf/!ba;N;s/.*\n/#ConfHere1\n/};p' /etc/"$webservice"/sites-enabled/"domain" +systemctl restart $webservice + +#Enabling SSL +if [ $domainwww = 1 ]; then + certbot --"$webserv" -n -d "$domain" -d "www.$domain" -m "$email" --hsts --redirect --no-eff-email --agree-tos +elif [ $domainwww = 0 ]; then + certbot --"$webserv" -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/"$domain"-config' -e '/#ConfHere/c\' /etc/"$webservice"/sites-enabled/"domain" + +systemctl restart $webservice \ No newline at end of file