apache/httpd-update_httpdconf.sh

50 lines
1.4 KiB
Bash

#!/bin/bash
# update_httpdconf.sh - updates httpd.conf modules list
# Copyright (c) 2006-2016 by Silvan Calarco <silvan.calarco@qilinux.it>
INPUT_CONF=/etc/httpd/httpd.conf.rpmnew
OUTPUT_CONF=/etc/httpd/httpd.conf
MODULES_PREFIX=/usr
if [ -d /usr/lib64/apache ]; then
MODULES_APPEND=lib64/apache
else
MODULES_APPEND=lib/apache
fi
MODULES_PATH=$MODULES_PREFIX/$MODULES_APPEND
cont=0
# no rpmnew file ? silently nothing to do
[ -e $INPUT_CONF ] || exit 0
for a in `grep ^LoadModule $INPUT_CONF | gawk '{ print $3 }'`; do
MODULE[$cont]=`echo $a | sed "s|.*/mod_\(.*\)\.so|\1|"`
let cont+=1
done
# remove missing modules
for a in `grep ^LoadModule $OUTPUT_CONF | gawk '{ print $3 }'`; do
[ -e $MODULES_PREFIX/$a ] || {
echo "Removing missing module $a"
A=`echo $a | sed 's|\/|\\\\\/|g'`
sed -i "/^LoadModule .* $A/d" $OUTPUT_CONF
}
done
ANCHOR_LINE=`grep "^LoadModule .*" $OUTPUT_CONF | tail -n 1 | sed 's|\/|\\\\\/|g'`
#echo $ANCHOR_LINE
#exit 1
# adding new modules
for a in ${MODULE[*]}; do
[ ${a:0:4} == "mpm_" ] && continue
grep "^LoadModule .* $MODULES_APPEND/mod_$a.so" $OUTPUT_CONF >/dev/null || {
echo "Configuring module $a"
sed -i "/${ANCHOR_LINE}/a \
LoadModule ${a}_module $MODULES_APPEND\/mod_$a.so" $OUTPUT_CONF
ANCHOR_LINE=`echo "LoadModule ${a}_module $MODULES_APPEND/mod_$a.so" | sed 's|\/|\\\\\/|g'`
}
done
sed -i "s|/etc/httpd/ssl.conf|/etc/httpd/extra/httpd-ssl.conf|" $OUTPUT_CONF