replace chained conditionals by regular if/else + configtest before reload
This commit is contained in:
parent
128db07700
commit
7faf647185
|
@ -837,26 +837,45 @@ op_aliasdel() {
|
||||||
if [ $# -eq 2 ]; then
|
if [ $# -eq 2 ]; then
|
||||||
vhost="${1}.conf"
|
vhost="${1}.conf"
|
||||||
alias=$2
|
alias=$2
|
||||||
|
vhost_file="${VHOST_PATH}/${vhost}"
|
||||||
|
|
||||||
[ -f $VHOST_PATH/"$vhost" ] && sed -i -e "/ServerAlias $alias/d" $VHOST_PATH/"$vhost" --follow-symlinks
|
if [ -f "${vhost_file}" ]; then
|
||||||
|
sed -i -e "/ServerAlias $alias/d" "${vhost_file}" --follow-symlinks
|
||||||
|
else
|
||||||
|
echo "VHost file \`${vhost_file}' not found'" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
apache2ctl configtest 2>/dev/null
|
configtest_out=$(apache2ctl configtest)
|
||||||
/etc/init.d/apache2 force-reload >/dev/null
|
configtest_rc=$?
|
||||||
|
|
||||||
else usage
|
if [ "$configtest_rc" = "0" ]; then
|
||||||
|
/etc/init.d/apache2 force-reload >/dev/null
|
||||||
|
else
|
||||||
|
echo $configtest_out >&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
usage
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
op_listservername() {
|
op_listservername() {
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
configfile="$VHOST_PATH/${1}.conf";
|
vhost_file="$VHOST_PATH/${1}.conf";
|
||||||
|
|
||||||
for servername in $(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq); do
|
if [ -f "${vhost_file}" ]; then
|
||||||
echo "$servername";
|
servernames=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$vhost_file" | uniq)
|
||||||
done
|
|
||||||
|
|
||||||
else usage
|
for servername in $servernames; do
|
||||||
fi
|
echo "$servername";
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "VHost file \`${vhost_file}' not found'" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
op_servernameupdate() {
|
op_servernameupdate() {
|
||||||
|
@ -864,76 +883,101 @@ op_servernameupdate() {
|
||||||
vhost="${1}.conf"
|
vhost="${1}.conf"
|
||||||
servername=$2
|
servername=$2
|
||||||
old_servername=$3
|
old_servername=$3
|
||||||
|
vhost_file="${VHOST_PATH}/${vhost}"
|
||||||
|
|
||||||
# Remplacement de toutes les directives ServerName, on assume qu'il s'agit du même pour chaque vhost du fichier
|
# Remplacement de toutes les directives ServerName, on assume qu'il s'agit du même pour chaque vhost du fichier
|
||||||
[ -f $VHOST_PATH/"$vhost" ] && sed -i "/^ *ServerName/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks \
|
if [ -f "${vhost_file}" ]; then
|
||||||
&& sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" $VHOST_PATH/"$vhost" --follow-symlinks
|
sed -i "/^ *ServerName/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks
|
||||||
|
sed -i "/^ *RewriteCond/ s/$old_servername/$servername/g" "${vhost_file}" --follow-symlinks
|
||||||
|
fi
|
||||||
|
|
||||||
apache2ctl configtest 2>/dev/null
|
configtest_out=$(apache2ctl configtest)
|
||||||
/etc/init.d/apache2 force-reload >/dev/null
|
configtest_rc=$?
|
||||||
|
|
||||||
else usage
|
if [ "$configtest_rc" = "0" ]; then
|
||||||
|
/etc/init.d/apache2 force-reload >/dev/null
|
||||||
|
else
|
||||||
|
echo $configtest_out >&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
usage
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
op_checkoccurencename() {
|
op_checkoccurencename() {
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
name=${1}
|
name=${1}
|
||||||
configlist="$VHOST_PATH/*";
|
configlist="$VHOST_PATH/*";
|
||||||
servernames=''
|
servernames=''
|
||||||
aliases=''
|
aliases=''
|
||||||
|
|
||||||
for configfile in $configlist; do
|
for configfile in $configlist; do
|
||||||
if [ -r "$configfile" ]; then
|
if [ -r "$configfile" ]; then
|
||||||
aliases="$aliases $(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1)"
|
alias=$(perl -ne 'print "$1 " if /^[[:space:]]*ServerAlias (.*)/' "$configfile" | head -n 1)
|
||||||
servernames="$servernames $(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq)"
|
aliases="$aliases $alias"
|
||||||
fi
|
|
||||||
done
|
servername=$(awk '/^[[:space:]]*ServerName (.*)/ { print $2 }' "$configfile" | uniq)
|
||||||
|
servernames="$servernames $servername"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo "$servernames" "$aliases" | grep -w "$name"
|
echo "$servernames" "$aliases" | grep -w "$name"
|
||||||
|
else
|
||||||
else usage
|
usage
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
op_listuseritk() {
|
op_listuseritk() {
|
||||||
if [ $# -eq 2 ]; then
|
if [ $# -eq 2 ]; then
|
||||||
domain=${1}
|
domain=${1}
|
||||||
configfile="$VHOST_PATH"/"${2}".conf
|
configfile="$VHOST_PATH/${2}.conf"
|
||||||
|
|
||||||
sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $2}' | uniq
|
sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $2}' | uniq
|
||||||
else usage
|
else
|
||||||
fi
|
usage
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
op_enableuseritk() {
|
op_enableuseritk() {
|
||||||
if [ $# -eq 2 ]; then
|
if [ $# -eq 2 ]; then
|
||||||
domain=${1}
|
domain=${1}
|
||||||
configfile="$VHOST_PATH"/"${2}".conf
|
configfile="$VHOST_PATH/${2}.conf"
|
||||||
group=$(sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $3}' | uniq)
|
group=$(sed -n "/$domain/,/<\/VirtualHost>/p" "$configfile" | awk '/AssignUserID/ {print $3}' | uniq)
|
||||||
|
|
||||||
sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $group/ AssignUserID www-$group/" $configfile --follow-symlinks
|
sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID $group/ AssignUserID www-$group/" "$configfile" --follow-symlinks
|
||||||
|
|
||||||
apache2ctl configtest 2>/dev/null
|
configtest_out=$(apache2ctl configtest)
|
||||||
/etc/init.d/apache2 force-reload >/dev/null
|
configtest_rc=$?
|
||||||
|
|
||||||
else usage
|
if [ "$configtest_rc" = "0" ]; then
|
||||||
fi
|
/etc/init.d/apache2 force-reload >/dev/null
|
||||||
|
else
|
||||||
|
echo $configtest_out >&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
op_disableuseritk() {
|
op_disableuseritk() {
|
||||||
if [ $# -eq 2 ]; then
|
if [ $# -eq 2 ]; then
|
||||||
domain=${1}
|
domain=${1}
|
||||||
configfile="$VHOST_PATH"/"${2}".conf
|
configfile="$VHOST_PATH"/"${2}".conf
|
||||||
group=$(sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $3}' | uniq)
|
group=$(sed -n "/$domain/,/<\/VirtualHost>/p" $configfile | awk '/AssignUserID/ {print $3}' | uniq)
|
||||||
|
|
||||||
sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID www-$group/ AssignUserID ${group}/" $configfile --follow-symlinks
|
sed -i "/$domain/,/<\/VirtualHost>/ s/^ *AssignUserID www-$group/ AssignUserID ${group}/" "$configfile" --follow-symlinks
|
||||||
|
|
||||||
apache2ctl configtest 2>/dev/null
|
configtest_out=$(apache2ctl configtest)
|
||||||
/etc/init.d/apache2 force-reload >/dev/null
|
configtest_rc=$?
|
||||||
|
|
||||||
else usage
|
if [ "$configtest_rc" = "0" ]; then
|
||||||
fi
|
/etc/init.d/apache2 force-reload >/dev/null
|
||||||
|
else
|
||||||
|
echo $configtest_out >&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
op_add() {
|
op_add() {
|
||||||
|
|
Loading…
Reference in a new issue