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.
This commit is contained in:
Patrick Marchand 2018-12-04 11:25:45 -05:00
parent 53335ee4ef
commit c135807010

View file

@ -110,8 +110,8 @@ list-vhost LOGIN
List Apache vhost for user LOGIN List Apache vhost for user LOGIN
fix-vhosts check-vhosts -f
Fixes non-symlinked vhosts List suggested changes to vhosts, apply fixes with -f
add-alias VHOST ALIAS add-alias VHOST ALIAS
@ -713,8 +713,8 @@ arg_processing() {
list-vhost) list-vhost)
op_listvhost "$@" op_listvhost "$@"
;; ;;
fix-vhosts) check-vhosts)
op_fixvhosts "$@" op_checkvhosts "$@"
;; ;;
add-alias) add-alias)
op_aliasadd "$@" op_aliasadd "$@"
@ -996,17 +996,38 @@ op_add() {
# Some people forget to use the --follow-symlinks flag with sed(1), # Some people forget to use the --follow-symlinks flag with sed(1),
# thus not carrying changes over to /etc/sites-available. # thus not carrying changes over to /etc/sites-available.
op_fixvhosts() { op_checkvhosts() {
ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")" ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")"
non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)" 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 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" if [[ -z "$apply" ]]; then
a2ensite "$vhostname" echo "Suggested fixes for $vhost_name:"
done 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 # Point d'entrée