New check command for web-add.sh #5

Merged
Ghost merged 5 commits from ticket-37722 into master 2018-12-13 23:29:07 +01:00

View file

@ -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
Review

"/ServerName .*/a \\\tServerAlias $alias missing the trailing slash?

`"/ServerName .*/a \\\tServerAlias $alias` missing the trailing slash?
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")"

Useless echo? Missing last sed trail?

Should be:

sed 's/available/enabled/' <<< "$VHOST_PATH"
Useless echo? Missing last sed trail? Should be: ```bash sed 's/available/enabled/' <<< "$VHOST_PATH" ```
Outdated
Review

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
;;

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.
Outdated
Review

I'm thinking it could probably take a --dry-run flag

I'm thinking it could probably take a --dry-run flag
Outdated
Review

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?

Huh. No need for that feature in the web interface.
This is for helping sysadmins only.

Huh. No need for that feature in the web interface. This is for helping sysadmins only.

Yes you should add a --dry-run, or even should be the default.

Yes you should add a `--dry-run`, or even should be the default.
Outdated
Review

What's your preference: --force or --apply?

What's your preference: `--force` or `--apply`?

--force is nice. (If you force, you must understand the consequences ;))

`--force` is nice. (If you force, you must understand the consequences ;))
Outdated
Review

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.

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.

Well... Ok for --apply.

Well... Ok for `--apply`.
Review

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.
?)

You could also use a2ensite in place of doing a manual link.

You could also use `a2ensite` in place of doing a manual link.
Outdated
Review

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 "$@"