Update ssl-certificate.sh

This commit is contained in:
rieger::CLOUD
2018-04-20 15:33:39 +02:00
committed by GitHub
parent 0d029f7933
commit 0f62e91e70

View File

@@ -35,39 +35,39 @@ echo "Verify that both ports (80 + 443) are forwarded to this server!"
echo "And verify, your dyndns points to your IP either!" echo "And verify, your dyndns points to your IP either!"
echo "Then retry..." echo "Then retry..."
} }
#add the letsencrypt repository to the server ###add the letsencrypt repository to the server
add-apt-repository ppa:certbot/certbot -y add-apt-repository ppa:certbot/certbot -y
update_and_clean update_and_clean
#install letsencrypt ###install letsencrypt
apt install letsencrypt -y apt install letsencrypt -y
#ensure lower cases ###ensure lower cases
declare -l DYNDNSNAME declare -l DYNDNSNAME
declare -l YOURSERVERNAME declare -l YOURSERVERNAME
#read the current hostname ###read the current hostname
YOURSERVERNAME=$(hostname) YOURSERVERNAME=$(hostname)
#ask the user what would be the domain name to request the certificate for ###ask the user what would be the domain name to request the certificate for
read -p "Your domain: " DYNDNSNAME read -p "Your domain: " DYNDNSNAME
#request the certificate for the entered domain name ###request the certificate for the entered domain name
letsencrypt certonly -a webroot --webroot-path=/var/www/letsencrypt --rsa-key-size 4096 -d $DYNDNSNAME letsencrypt certonly -a webroot --webroot-path=/var/www/letsencrypt --rsa-key-size 4096 -d $DYNDNSNAME
#in case of any errors ###in case of any errors
if [ ! -d "/etc/letsencrypt/live" ]; then if [ ! -d "/etc/letsencrypt/live" ]; then
errorSSL errorSSL
#if no error appeared ###if no error appeared
else else
copy4SSL copy4SSL
#remove the entry for the self signed certificates ###remove the entry for the self signed certificates
sed -i '/ssl-cert-snakeoil/d' /etc/nginx/ssl.conf sed -i '/ssl-cert-snakeoil/d' /etc/nginx/ssl.conf
#apply the new server/domain name to the NGINX vhost for Nextcloud ###apply the new server/domain name to the NGINX vhost for Nextcloud
sed -i "s/server_name.*;/server_name $DYNDNSNAME;/" /etc/nginx/conf.d/nextcloud.conf sed -i "s/server_name.*;/server_name $DYNDNSNAME;/" /etc/nginx/conf.d/nextcloud.conf
#change the placeholder values to the exact letsencrypt ones ###change the placeholder values to the exact letsencrypt ones
sed -in 's/YOUR.DEDYN.IO/'$DYNDNSNAME'/' /etc/nginx/ssl.conf sed -in 's/YOUR.DEDYN.IO/'$DYNDNSNAME'/' /etc/nginx/ssl.conf
# remove the '#' to enable these certificates/keys ###remove the '#' to enable these certificates/keys
sed -i s/\#\ssl/\ssl/g /etc/nginx/ssl.conf sed -i s/\#\ssl/\ssl/g /etc/nginx/ssl.conf
#ensure that dhparam is commented as long it was not generated ###ensure that dhparam is commented as long it was not generated
sed -i s/ssl_dhparam/\#ssl_dhparam/g /etc/nginx/ssl.conf sed -i s/ssl_dhparam/\#ssl_dhparam/g /etc/nginx/ssl.conf
#adjust Nextclous config.php to the new domain name ###adjust Nextclous config.php to the new domain name
sudo -u www-data sed -in 's/'$YOURSERVERNAME'/'$DYNDNSNAME'/' /var/www/nextcloud/config/config.php sudo -u www-data sed -in 's/'$YOURSERVERNAME'/'$DYNDNSNAME'/' /var/www/nextcloud/config/config.php
#restart the cloud environment ###restart the cloud environment
restart_all_services restart_all_services
clear clear
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++++"