New check-vhosts command for web-add.sh
Checks whether the enabled vhosts are all symbolic links, also offers the -f flag to fix any problems automatically.
This commit is contained in:
commit
ea359880cc
|
@ -26,7 +26,7 @@ SSH_GROUP="evolinux-ssh"
|
||||||
# Set to nginx if you use nginx and not apache
|
# Set to nginx if you use nginx and not apache
|
||||||
WEB_SERVER="apache"
|
WEB_SERVER="apache"
|
||||||
if [ "$WEB_SERVER" == "apache" ]; then
|
if [ "$WEB_SERVER" == "apache" ]; then
|
||||||
VHOST_PATH="/etc/apache2/sites-available/"
|
VHOST_PATH="/etc/apache2/sites-available"
|
||||||
TPL_VHOST="$SCRIPTS_PATH/vhost"
|
TPL_VHOST="$SCRIPTS_PATH/vhost"
|
||||||
TPL_MAIL="$SCRIPTS_PATH/web-mail.tpl"
|
TPL_MAIL="$SCRIPTS_PATH/web-mail.tpl"
|
||||||
|
|
||||||
|
@ -110,6 +110,9 @@ list-vhost LOGIN
|
||||||
|
|
||||||
List Apache vhost for user LOGIN
|
List Apache vhost for user LOGIN
|
||||||
|
|
||||||
|
check-vhosts -f
|
||||||
|
List suggested changes to vhosts, apply fixes with -f
|
||||||
|
|
||||||
add-alias VHOST ALIAS
|
add-alias VHOST ALIAS
|
||||||
|
|
||||||
Add a ServerAlias to an Apache vhost
|
Add a ServerAlias to an Apache vhost
|
||||||
|
@ -709,6 +712,9 @@ arg_processing() {
|
||||||
list-vhost)
|
list-vhost)
|
||||||
op_listvhost "$@"
|
op_listvhost "$@"
|
||||||
;;
|
;;
|
||||||
|
check-vhosts)
|
||||||
|
op_checkvhosts "$@"
|
||||||
|
;;
|
||||||
add-alias)
|
add-alias)
|
||||||
op_aliasadd "$@"
|
op_aliasadd "$@"
|
||||||
;;
|
;;
|
||||||
|
@ -766,7 +772,7 @@ op_aliasadd() {
|
||||||
vhost="${1}.conf"
|
vhost="${1}.conf"
|
||||||
alias=$2
|
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
|
apache2ctl configtest 2>/dev/null
|
||||||
/etc/init.d/apache2 force-reload >/dev/null
|
/etc/init.d/apache2 force-reload >/dev/null
|
||||||
|
@ -987,5 +993,41 @@ op_add() {
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Some people forget to use the --follow-symlinks flag with sed(1),
|
||||||
|
# thus not carrying changes over to /etc/sites-available.
|
||||||
|
op_checkvhosts() {
|
||||||
|
ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")"
|
||||||
|
non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)"
|
||||||
|
|
||||||
|
while getopts 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")
|
||||||
|
fix_conf="mv $ln_path $VHOST_PATH/$vhost_name"
|
||||||
|
fix_ln="a2ensite $vhost_name"
|
||||||
|
|
||||||
|
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
|
# Point d'entrée
|
||||||
arg_processing "$@"
|
arg_processing "$@"
|
||||||
|
|
Loading…
Reference in a new issue