From d64cfa4e8bd07c0d4ff41c6d8d04f16f0a8f5508 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Thu, 22 Nov 2018 16:28:24 +0100 Subject: [PATCH 1/5] Fix problems with web-add.sh add-alias All uses of the VHOST_PATH variable in the code append a slash to it, so it is easier to remove the trailing slash in it's instantiation. Also simplifies the sed(1) invocation. --- scripts/web-add.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 10444a3..2dc2ff5 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -26,7 +26,7 @@ SSH_GROUP="evolinux-ssh" # Set to nginx if you use nginx and not apache WEB_SERVER="apache" if [ "$WEB_SERVER" == "apache" ]; then - VHOST_PATH="/etc/apache2/sites-available/" + VHOST_PATH="/etc/apache2/sites-available" TPL_VHOST="$SCRIPTS_PATH/vhost" TPL_MAIL="$SCRIPTS_PATH/web-mail.tpl" @@ -767,7 +767,7 @@ op_aliasadd() { vhost="${1}.conf" alias=$2 - [ -f $VHOST_PATH/"$vhost" ] && sed -i -e "s/\\(ServerName .*\\)/\\1\\n\\tServerAlias $alias/" "$VHOST_PATH"/"$vhost" --follow-symlinks + [ -f $VHOST_PATH/"$vhost" ] && sed -i "/ServerName .*/a \\\tServerAlias $alias" "$VHOST_PATH"/"$vhost" --follow-symlinks apache2ctl configtest 2>/dev/null /etc/init.d/apache2 force-reload >/dev/null From b693075f392ebec12f8b928fdeff279f0e0e60a9 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Thu, 22 Nov 2018 20:15:06 +0100 Subject: [PATCH 2/5] Adds command to fix vhost linking problems in web-add.sh Some people forget to use the --follow-symlinks flag with sed(1), thus not carrying changes over to /etc/apache2/sites-available. This new command makes sure all vhosts in /etc/apache2/sites-enabled are symlinks. It assumes that we always want to overwrite the file in /etc/apache2/sites-available with the file in /etc/apache2/sites-enabled. --- scripts/web-add.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 2dc2ff5..eae492d 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -109,6 +109,9 @@ del LOGIN [DBNAME] list-vhost LOGIN List Apache vhost for user LOGIN + +fix-vhosts + Fixes non-symlinked vhosts add-alias VHOST ALIAS @@ -709,6 +712,9 @@ arg_processing() { ;; list-vhost) op_listvhost "$@" + ;; + fix-vhosts) + op_fixvhosts "$@" ;; add-alias) op_aliasadd "$@" @@ -988,5 +994,20 @@ op_add() { echo } +# Some people forget to use the --follow-symlinks flag with sed(1), +# thus not carrying changes over to /etc/sites-available. +op_fixvhosts() { + ln_vhosts_dir="$(echo "$VHOST_PATH" | sed 's/available/enabled')" + non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)" + + for ln_path in $non_ln_vhosts + do + vhost_name=$(basename "$ln_path") + + mv "$ln_path" "$VHOST_PATH/$vhost_name" + ln -s "$VHOST_PATH/$vhost_name" "$ln_path" + done +} + # Point d'entrée arg_processing "$@" From 53335ee4ef84a84216c05783e44296771c6f1aaf Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Thu, 29 Nov 2018 18:42:20 +0100 Subject: [PATCH 3/5] Apply first and third benpro review of web-add fix command Simplify sed(1) command by getting rid of echo(1) Use a2ensite(1) instead of ln(1) to link vhosts. --- scripts/web-add.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index eae492d..e0022dc 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -997,7 +997,7 @@ op_add() { # Some people forget to use the --follow-symlinks flag with sed(1), # thus not carrying changes over to /etc/sites-available. op_fixvhosts() { - ln_vhosts_dir="$(echo "$VHOST_PATH" | sed 's/available/enabled')" + ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")" non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)" for ln_path in $non_ln_vhosts @@ -1005,7 +1005,7 @@ op_fixvhosts() { vhost_name=$(basename "$ln_path") mv "$ln_path" "$VHOST_PATH/$vhost_name" - ln -s "$VHOST_PATH/$vhost_name" "$ln_path" + a2ensite "$vhostname" done } From c135807010f78c232b45e2ecc18b5754aa88a5df Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Tue, 4 Dec 2018 11:25:45 -0500 Subject: [PATCH 4/5] Changed API for web-add.sh fix-vhosts check-vhosts now only applies changes when it is passed the -f flag, otherwise it simply lists the suggested fixes. --- scripts/web-add.sh | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index e0022dc..866341a 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -110,8 +110,8 @@ list-vhost LOGIN List Apache vhost for user LOGIN -fix-vhosts - Fixes non-symlinked vhosts +check-vhosts -f + List suggested changes to vhosts, apply fixes with -f add-alias VHOST ALIAS @@ -713,8 +713,8 @@ arg_processing() { list-vhost) op_listvhost "$@" ;; - fix-vhosts) - op_fixvhosts "$@" + check-vhosts) + op_checkvhosts "$@" ;; add-alias) op_aliasadd "$@" @@ -996,17 +996,38 @@ op_add() { # Some people forget to use the --follow-symlinks flag with sed(1), # thus not carrying changes over to /etc/sites-available. -op_fixvhosts() { +op_checkvhosts() { ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")" non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)" - - for ln_path in $non_ln_vhosts + + while getopt f opt; do + case "$opt" in + f) + apply=1 + ;; + *) + usage + exit 1 + ;; + esac + done + + for ln_path in $non_ln_vhosts do - vhost_name=$(basename "$ln_path") + vhost_name=$(basename "$ln_path") + fix_conf="mv $ln_path $VHOST_PATH/$vhost_name" + fix_ln="a2ensite $vhost_name" - mv "$ln_path" "$VHOST_PATH/$vhost_name" - a2ensite "$vhostname" - done + if [[ -z "$apply" ]]; then + echo "Suggested fixes for $vhost_name:" + echo "diff $ln_path $VHOST_PATH/$vhost_name" + echo "$fix_conf" + echo "$fix_ln" + else + $fix_conf + $fix_ln + fi + done } # Point d'entrée From 21f5f011da345916f3d97f86f1f9949776b9aff7 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Thu, 13 Dec 2018 13:21:13 -0500 Subject: [PATCH 5/5] Fixed mistake with getopts(1) in web-add.sh --- scripts/web-add.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/web-add.sh b/scripts/web-add.sh index 866341a..6f15551 100755 --- a/scripts/web-add.sh +++ b/scripts/web-add.sh @@ -1000,12 +1000,12 @@ op_checkvhosts() { ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")" non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)" - while getopt f opt; do + while getopts f opt; do case "$opt" in f) apply=1 ;; - *) + ?) usage exit 1 ;;