parent
d241024593
commit
45b8e87546
|
@ -38,14 +38,14 @@ function get_cert
|
||||||
if [ "$DEBUG" = "1" ]; then
|
if [ "$DEBUG" = "1" ]; then
|
||||||
_debug_arg="--debug"
|
_debug_arg="--debug"
|
||||||
fi
|
fi
|
||||||
/root/.acme.sh/acme.sh --issue --domain $_domain --webroot /srv/http-content-combined/ --cert-file /etc/ssl/${_domain}.crt --key-file /etc/ssl/${_domain}.key --fullchain-file /etc/ssl/${_domain}-fullchain.crt $_debug_arg
|
/root/.acme.sh/acme.sh --issue --domain "$_domain" --webroot /srv/http-content-combined/ --cert-file /etc/ssl/"${_domain}".crt --key-file /etc/ssl/"${_domain}".key --fullchain-file /etc/ssl/"${_domain}"-fullchain.crt $_debug_arg
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
function reload_nginx
|
function reload_nginx
|
||||||
{
|
{
|
||||||
echo -n "Reloading ${_servicename}..."
|
echo -n "Reloading ${_servicename}..."
|
||||||
if systemctl reload ${_servicename} > /dev/null 2>&1; then
|
if systemctl reload "${_servicename}" > /dev/null 2>&1; then
|
||||||
echo "Success"
|
echo "Success"
|
||||||
else
|
else
|
||||||
echo "Failed"
|
echo "Failed"
|
||||||
|
@ -60,10 +60,10 @@ function reload_nginx
|
||||||
function clean_up
|
function clean_up
|
||||||
{
|
{
|
||||||
debug "Removing Nginx configuration and logs..."
|
debug "Removing Nginx configuration and logs..."
|
||||||
rm $_vhost_conf_file
|
rm "$_vhost_conf_file"
|
||||||
rm /var/log/nginx/$_domain.* > /dev/null 2>&1
|
rm /var/log/nginx/"$_domain".* > /dev/null 2>&1
|
||||||
reload_nginx
|
reload_nginx
|
||||||
err $1
|
err "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
function verify_vhost
|
function verify_vhost
|
||||||
|
@ -80,7 +80,7 @@ function verify_vhost
|
||||||
|
|
||||||
mkdir -p $verify_path
|
mkdir -p $verify_path
|
||||||
touch $verify_full_path
|
touch $verify_full_path
|
||||||
http_code=$(curl -I -H "Host: $_domain" http://$target/.well-known/$verify_file_name 2> /dev/null | grep 'HTTP/1.1' | cut -d " " -f 2)
|
http_code=$(curl -I -H "Host: $_domain" http://"$target"/.well-known/"$verify_file_name" 2> /dev/null | grep 'HTTP/1.1' | cut -d " " -f 2)
|
||||||
|
|
||||||
if [[ $http_code = '200' ]]; then
|
if [[ $http_code = '200' ]]; then
|
||||||
return 0
|
return 0
|
||||||
|
@ -96,8 +96,8 @@ _bb_myname=$(basename "$0")
|
||||||
_bb_mypath=$(realpath $BASH_SOURCE)
|
_bb_mypath=$(realpath $BASH_SOURCE)
|
||||||
|
|
||||||
# Init script
|
# Init script
|
||||||
if test -f $_bootstrap; then
|
if test -f "$_bootstrap"; then
|
||||||
source $_bootstrap 2> /dev/null
|
source "$_bootstrap" 2> /dev/null
|
||||||
else
|
else
|
||||||
echo "Unable to parse BOOTSTRAP: $_bootstrap"
|
echo "Unable to parse BOOTSTRAP: $_bootstrap"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -111,7 +111,7 @@ fi
|
||||||
# gain priviledges
|
# gain priviledges
|
||||||
become "$@"
|
become "$@"
|
||||||
|
|
||||||
OPTS=$(getopt -o h,d -l domain:,root:,backend:,listenip:,desc:,donotredirect,servicename:,debug -n 'createVhosts' -- "$@")
|
OPTS=$(getopt -o h,d -l domain:,root:,backend:,listenip:,desc:,donotredirect,servicename:,confpath:,debug -n 'createVhosts' -- "$@")
|
||||||
if [ "$?" -gt '0' ]; then
|
if [ "$?" -gt '0' ]; then
|
||||||
echo 'Failed to set command line arguments'
|
echo 'Failed to set command line arguments'
|
||||||
exit 1;
|
exit 1;
|
||||||
|
@ -149,6 +149,9 @@ while true; do
|
||||||
--servicename )
|
--servicename )
|
||||||
_servicename=$2
|
_servicename=$2
|
||||||
shift ;;
|
shift ;;
|
||||||
|
--confpath )
|
||||||
|
_confpath=$2
|
||||||
|
shift ;;
|
||||||
-d | --debug )
|
-d | --debug )
|
||||||
_debug=true
|
_debug=true
|
||||||
shift ;;
|
shift ;;
|
||||||
|
@ -173,9 +176,9 @@ fi
|
||||||
|
|
||||||
if test -n "$_root"; then
|
if test -n "$_root"; then
|
||||||
echo -n "Checking if $_root exists?"
|
echo -n "Checking if $_root exists?"
|
||||||
if ! test -d $_root; then
|
if ! test -d "$_root"; then
|
||||||
echo " Creating..."
|
echo " Creating..."
|
||||||
mkdir -p $_root
|
mkdir -p "$_root"
|
||||||
else
|
else
|
||||||
echo " Yes!"
|
echo " Yes!"
|
||||||
fi
|
fi
|
||||||
|
@ -187,7 +190,7 @@ _locationblock_http=""
|
||||||
_locationblock_https=""
|
_locationblock_https=""
|
||||||
if test -n "$_backend"; then
|
if test -n "$_backend"; then
|
||||||
echo "Verifying backend(s)..."
|
echo "Verifying backend(s)..."
|
||||||
if ! validate_host $_backend; then
|
if ! validate_host "$_backend"; then
|
||||||
_check_host=failed
|
_check_host=failed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -229,7 +232,7 @@ EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -n "$_listenip"; then
|
if test -n "$_listenip"; then
|
||||||
if ! validate_ip $_listenip; then
|
if ! validate_ip "$_listenip"; then
|
||||||
err "Invalid IP: $_listenip"
|
err "Invalid IP: $_listenip"
|
||||||
fi
|
fi
|
||||||
_listenip="$_listenip:"
|
_listenip="$_listenip:"
|
||||||
|
@ -249,6 +252,15 @@ else
|
||||||
echo " No!"
|
echo " No!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -n "Checking if conf path '$_confpath' exists? "
|
||||||
|
if test -d "$_confpath"; then
|
||||||
|
echo "Yes!"
|
||||||
|
clean_up
|
||||||
|
else
|
||||||
|
echo "No!"
|
||||||
|
clean_up
|
||||||
|
fi
|
||||||
|
|
||||||
##
|
##
|
||||||
## End processing command line arguments
|
## End processing command line arguments
|
||||||
###########################################
|
###########################################
|
||||||
|
@ -265,18 +277,18 @@ else
|
||||||
echo " Yes!"
|
echo " Yes!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_vhost_conf_file=/etc/nginx/conf.d/${_domain}.conf
|
_vhost_conf_file=$_confpath/conf.d/${_domain}.conf
|
||||||
|
|
||||||
echo -n "Checking if $_vhost_conf_file exists? "
|
echo -n "Checking if $_vhost_conf_file exists? "
|
||||||
if test -f $_vhost_conf_file; then
|
if test -f "$_vhost_conf_file"; then
|
||||||
echo "Removing!"
|
echo "Removing!"
|
||||||
rm $_vhost_conf_file
|
rm "$_vhost_conf_file"
|
||||||
else
|
else
|
||||||
echo "No!"
|
echo "No!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Creating Nginx configuration..."
|
echo "Creating Nginx configuration..."
|
||||||
cat << EOF > $_vhost_conf_file
|
cat << EOF > "$_vhost_conf_file"
|
||||||
#### Description
|
#### Description
|
||||||
## Type: HTTP
|
## Type: HTTP
|
||||||
## VHost: $_domain
|
## VHost: $_domain
|
||||||
|
@ -300,7 +312,7 @@ $_locationblock_http
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo "Setting permissions on conf file..."
|
echo "Setting permissions on conf file..."
|
||||||
setfacl -m user:sysadmin:rw $_vhost_conf_file
|
setfacl -m user:sysadmin:rw "$_vhost_conf_file"
|
||||||
|
|
||||||
if ! reload_nginx; then
|
if ! reload_nginx; then
|
||||||
clean_up "Failed to reload Nginx"
|
clean_up "Failed to reload Nginx"
|
||||||
|
@ -316,7 +328,7 @@ if ! get_cert; then
|
||||||
clean_up "Failed to retrieve certificate!"
|
clean_up "Failed to retrieve certificate!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat << EOF >> $_vhost_conf_file
|
cat << EOF >> "$_vhost_conf_file"
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen ${_listenip}443 http2 ssl;
|
listen ${_listenip}443 http2 ssl;
|
||||||
|
|
Loading…
Reference in New Issue