From 178fa8e5dd428836efa604f394e91d4c9aff2080 Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Wed, 11 May 2022 18:47:39 -0400 Subject: [PATCH] Refactor createVhosts.sh script * Fixed line breaks * Remove duplicate block * Added error message to the cleanup process, conf dir is missing. --- createVhosts.sh | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/createVhosts.sh b/createVhosts.sh index 74735cc..cedadbe 100755 --- a/createVhosts.sh +++ b/createVhosts.sh @@ -126,6 +126,7 @@ _backend="" _listenip="" _debug=false _servicename=nginx +_confpath=/etc/nginx while true; do case "$1" in --domain ) @@ -185,31 +186,20 @@ if test -n "$_root"; then _rootpath="root $_root;" fi -_check_host=success +_check_host=failed _locationblock_http="" _locationblock_https="" if test -n "$_backend"; then echo "Verifying backend(s)..." - if ! validate_host "$_backend"; then - _check_host=failed - 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 + if validate_host "$_backend"; then + _check_host=success fi if [ "$_check_host" = "success" ]; then # Include backend for HTTP traffic if donotredirect is enabled # if [ "$_donotredirect" = "true" ]; then + ##Begin HEREDOC _locationblock_http=$(cat <<- EOF proxy_pass $_backend; @@ -217,6 +207,7 @@ _locationblock_http=$(cat <<- EOF EOF ) ##End HEREDOC + fi ##Begin HEREDOC @@ -225,7 +216,8 @@ _locationblock_https=$(cat <<- EOF include proxy_params; EOF ) -##End HEREDOC +##End HEREDOC + else err "Invalid hostname: $_backend. Not resolvable!" fi @@ -257,7 +249,7 @@ if test -d "$_confpath"; then echo "Yes!" else echo "No!" - clean_up + clean_up "Conf path doesn't exists!" fi ##