From b693075f392ebec12f8b928fdeff279f0e0e60a9 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Thu, 22 Nov 2018 20:15:06 +0100 Subject: [PATCH] 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 "$@"