From 433c7c3f94fb98bb276c132c2d710df758ec1557 Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Wed, 17 Feb 2021 12:47:48 -0500 Subject: [PATCH] Initial draft --- bootstrap.sh | 5 +++++ createVhosts.sh | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index bb027e7..b98d651 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -68,6 +68,11 @@ function send_notification echo -e "$2" | mail $opt -s "$1" ${EMAIL} } +function become +{ + sudo su - +} + function check_values { diff --git a/createVhosts.sh b/createVhosts.sh index 8a98cf3..b9f502f 100755 --- a/createVhosts.sh +++ b/createVhosts.sh @@ -30,6 +30,11 @@ function get_cert /root/.acme.sh/acme.sh --issue --domain $_domain --webroot /srv/http-content-combined/ --cert-file /etc/nginx/ssl/${_domain}.crt --key-file /etc/nginx/ssl/${_domain}.key --fullchain-file /etc/nginx/ssl/${_domain}-fullchain.crt } +function reload_nginx +{ + systemctl reload nginx +} + _cwd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" _bootstrap=${_cwd}/bootstrap.sh @@ -112,9 +117,8 @@ if test -z "$_root" -a -z "$_backend"; then err "You must specify either --root or --backend!" fi -echo "Creating Nginx configuration..." -_vhost_conf_file=/etc/nginx/conf.d/${_domain}.conf - +# gain priviledges +become echo -n "Checking if /srv/http-content-combined/ exists?" if ! test -d /srv/http-content-combined; then @@ -124,6 +128,17 @@ else echo " Yes!" fi +echo "Creating Nginx configuration..." +_vhost_conf_file=/etc/nginx/conf.d/${_domain}.conf + +echo -n "Checking if $_vhost_conf_file exists? " +if test -f $_vhost_conf_file; then + echo "Removing!" + rm $_vhost_conf_file +else + echo "No!" +fi + cat << EOF > $_vhost_conf_file #### Description ## Type: HTTP @@ -142,6 +157,18 @@ server { return 302 https://${_domain}\$request_uri; } } +EOF + +echo "Setting permissions on conf file..." +setfacl -m user:sysadmin:rw $_vhost_conf_file + +echo "Reloading Nginx..." +reload_nginx + +echo "Retrieving Let's Encrypt Certificate..." +get_cert + +cat << EOF >> $_vhost_conf_file server { listen ${_listenip}443 http2 ssl; @@ -160,8 +187,5 @@ ${_locationblock} } EOF -echo "Setting permissions on conf file..." -#setfacl -m user:sysadmin:rw $_vhost_conf_file - -echo "Retrieving Let's Encrypt Certificate..." -get_cert +echo "Reloading Nginx..." +reload_nginx