Refactor createVhosts.sh script

* Fixed line breaks
* Remove duplicate block
* Added error message to the cleanup process, conf dir
is missing.
This commit is contained in:
Lutchy Horace 2022-05-11 18:47:39 -04:00
parent be51283e33
commit 178fa8e5dd
1 changed files with 9 additions and 17 deletions

View File

@ -126,6 +126,7 @@ _backend=""
_listenip="" _listenip=""
_debug=false _debug=false
_servicename=nginx _servicename=nginx
_confpath=/etc/nginx
while true; do while true; do
case "$1" in case "$1" in
--domain ) --domain )
@ -185,31 +186,20 @@ if test -n "$_root"; then
_rootpath="root $_root;" _rootpath="root $_root;"
fi fi
_check_host=success _check_host=failed
_locationblock_http="" _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=success
fi
# Include backend for HTTP traffic if donotredirect is enabled
#
if [ "$_donotredirect" = "true" ]; then
##Begin HEREDOC
_locationblock_http=$(cat <<- EOF
proxy_pass $_backend;
include proxy_params;
EOF
)
##End HEREDOC
fi fi
if [ "$_check_host" = "success" ]; then if [ "$_check_host" = "success" ]; then
# Include backend for HTTP traffic if donotredirect is enabled # Include backend for HTTP traffic if donotredirect is enabled
# #
if [ "$_donotredirect" = "true" ]; then if [ "$_donotredirect" = "true" ]; then
##Begin HEREDOC ##Begin HEREDOC
_locationblock_http=$(cat <<- EOF _locationblock_http=$(cat <<- EOF
proxy_pass $_backend; proxy_pass $_backend;
@ -217,6 +207,7 @@ _locationblock_http=$(cat <<- EOF
EOF EOF
) )
##End HEREDOC ##End HEREDOC
fi fi
##Begin HEREDOC ##Begin HEREDOC
@ -225,7 +216,8 @@ _locationblock_https=$(cat <<- EOF
include proxy_params; include proxy_params;
EOF EOF
) )
##End HEREDOC ##End HEREDOC
else else
err "Invalid hostname: $_backend. Not resolvable!" err "Invalid hostname: $_backend. Not resolvable!"
fi fi
@ -257,7 +249,7 @@ if test -d "$_confpath"; then
echo "Yes!" echo "Yes!"
else else
echo "No!" echo "No!"
clean_up clean_up "Conf path doesn't exists!"
fi fi
## ##