Initial draft

This commit is contained in:
Lutchy Horace 2021-02-17 12:47:48 -05:00
parent f71d76bc39
commit 433c7c3f94
2 changed files with 37 additions and 8 deletions

View File

@ -68,6 +68,11 @@ function send_notification
echo -e "$2" | mail $opt -s "$1" ${EMAIL} echo -e "$2" | mail $opt -s "$1" ${EMAIL}
} }
function become
{
sudo su -
}
function check_values function check_values
{ {

View File

@ -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 /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 )" _cwd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_bootstrap=${_cwd}/bootstrap.sh _bootstrap=${_cwd}/bootstrap.sh
@ -112,9 +117,8 @@ if test -z "$_root" -a -z "$_backend"; then
err "You must specify either --root or --backend!" err "You must specify either --root or --backend!"
fi fi
echo "Creating Nginx configuration..." # gain priviledges
_vhost_conf_file=/etc/nginx/conf.d/${_domain}.conf become
echo -n "Checking if /srv/http-content-combined/ exists?" echo -n "Checking if /srv/http-content-combined/ exists?"
if ! test -d /srv/http-content-combined; then if ! test -d /srv/http-content-combined; then
@ -124,6 +128,17 @@ else
echo " Yes!" echo " Yes!"
fi 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 cat << EOF > $_vhost_conf_file
#### Description #### Description
## Type: HTTP ## Type: HTTP
@ -142,6 +157,18 @@ server {
return 302 https://${_domain}\$request_uri; 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 { server {
listen ${_listenip}443 http2 ssl; listen ${_listenip}443 http2 ssl;
@ -160,8 +187,5 @@ ${_locationblock}
} }
EOF EOF
echo "Setting permissions on conf file..." echo "Reloading Nginx..."
#setfacl -m user:sysadmin:rw $_vhost_conf_file reload_nginx
echo "Retrieving Let's Encrypt Certificate..."
get_cert