New check command for web-add.sh #5
|
@ -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"
|
||||
|
||||
|
@ -109,6 +109,9 @@ del LOGIN [DBNAME]
|
|||
list-vhost LOGIN
|
||||
|
||||
List Apache vhost for user LOGIN
|
||||
|
||||
check-vhosts -f
|
||||
List suggested changes to vhosts, apply fixes with -f
|
||||
|
||||
add-alias VHOST ALIAS
|
||||
|
||||
|
@ -709,6 +712,9 @@ arg_processing() {
|
|||
;;
|
||||
list-vhost)
|
||||
op_listvhost "$@"
|
||||
;;
|
||||
check-vhosts)
|
||||
op_checkvhosts "$@"
|
||||
;;
|
||||
add-alias)
|
||||
op_aliasadd "$@"
|
||||
|
@ -767,7 +773,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
|
||||
|
@ -988,5 +994,41 @@ 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_checkvhosts() {
|
||||
ln_vhosts_dir="$(sed 's/available/enabled/' <<< "$VHOST_PATH")"
|
||||
benpro
commented
Useless echo? Missing last sed trail? Should be:
Useless echo? Missing last sed trail?
Should be:
```bash
sed 's/available/enabled/' <<< "$VHOST_PATH"
```
Ghost
commented
Mostly me not completely used to bash again, I'll fix it. Mostly me not completely used to bash again, I'll fix it.
|
||||
non_ln_vhosts="$(find "$ln_vhosts_dir"/* ! -type l)"
|
||||
|
||||
while getopts f opt; do
|
||||
case "$opt" in
|
||||
f)
|
||||
apply=1
|
||||
;;
|
||||
benpro
commented
Beware that operation can be dangerous. If people have modified the version in sites-available and sites-enabled, you should first merge the difference in the sites-available version, then do the symbolic link. Beware that operation can be dangerous. If people have modified the version in sites-available **and** sites-enabled, you should first merge the difference in the sites-available version, then do the symbolic link.
Ghost
commented
I'm thinking it could probably take a --dry-run flag I'm thinking it could probably take a --dry-run flag
Ghost
commented
So what would the behavior be when using it from the web interface? So what would the behavior be when using it from the web interface?
benpro
commented
Huh. No need for that feature in the web interface. Huh. No need for that feature in the web interface.
This is for helping sysadmins only.
benpro
commented
Yes you should add a Yes you should add a `--dry-run`, or even should be the default.
Ghost
commented
What's your preference: What's your preference: `--force` or `--apply`?
benpro
commented
`--force` is nice. (If you force, you must understand the consequences ;))
Ghost
commented
Yeah but Yeah but `web-add.sh fix --apply` makes more semantic sense in my mind, `web-add.sh fix --force` seems to apply more to an operation that was aborted because of inconsistencies, but gives you the option to force break stuff? Like `web-add.sh add-alias [alias] --force` would make sense.
benpro
commented
Well... Ok for Well... Ok for `--apply`.
Ghost
commented
See the latest commit for changes. I switched fix-vhosts to check-vhosts and added the -f flag to apply fixes. See the latest commit for changes. I switched fix-vhosts to check-vhosts and added the -f flag to apply fixes.
|
||||
?)
|
||||
benpro
commented
You could also use You could also use `a2ensite` in place of doing a manual link.
Ghost
commented
Good idea Good idea
|
||||
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
|
||||
arg_processing "$@"
|
||||
|
|
"/ServerName .*/a \\\tServerAlias $alias
missing the trailing slash?