X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=0588a0ffd6af2a2eb96505de9ddb30fde1fce7a0;hb=b0aaaaefbf10a1e20c50cb243fd4b21b283930e0;hp=086cc7570c45928d6366efc9d4015fdab6811202;hpb=d03328f5a691130af6d00a90401854ec1dbca134;p=apache2-cn.git diff --git a/debian/postinst b/debian/postinst index 086cc75..0588a0f 100755 --- a/debian/postinst +++ b/debian/postinst @@ -29,15 +29,13 @@ esac PKG="apache2-cn" VERSION="2.2-1" CONFDIR="/etc/apache2" -CONFDIROLD="/etc/apache" CONF="$CONFDIR/apache2.conf" -CONFOLD="$CONFDIROLD/httpd.conf" A2MODEDIR="$CONFDIR/mods-enabled" PORTCONF="$CONFDIR/ports.conf" A2CNDIR=/usr/share/apache2-cn TMPLDIR=$A2CNDIR/templates CERTDIR=/etc/ssl/certs -A2PHPINI="/etc/php4/apache2/php.ini" +A2PHPINI="/etc/php5/apache2/php.ini" HOST=$(hostname) FQDN=$(hostname --fqdn) @@ -328,11 +326,14 @@ fi # Make sure Apache is NOT running. # -if [ -x /usr/sbin/invoke-rc.d ]; then - [ -x /usr/sbin/apache ] && invoke-rc.d apache stop || true - pkill -9 -f /usr/sbin/apache || true -else - [ -x /etc/init.d/apache ] && /etc/init.d/apache stop || true +if [ -x /etc/init.d/apache ]; then + if [ -x /usr/sbin/invoke-rc.d ]; then + invoke-rc.d apache stop || true + else + /etc/init.d/apache stop || true + fi + + pkill -9 -f '/usr/sbin/apache$' || true fi @@ -367,7 +368,7 @@ if [ $backup_done -eq 1 ]; then fi -# Enable Apache2 web server modules (cgi, rewrite, userdir, suexec, php4, ssl). +# Enable Apache2 web server modules (cgi, rewrite, userdir, suexec, php5, ssl). # if [ -e "$CONF" ]; then @@ -395,10 +396,20 @@ if [ -e "$CONF" ]; then need_restart=1 fi + if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then + if [ -e "/usr/lib/apache2/modules/libphp5.so" ]; then + cp_echo "CN: Enabling PHP5 module for Apache2 web server." + a2enmod php5 >/dev/null || true + need_restart=1 + fi + fi + if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then + if [ -e "/usr/lib/apache2/modules/libphp4.so" ]; then cp_echo "CN: Enabling PHP4 module for Apache2 web server." a2enmod php4 >/dev/null || true need_restart=1 + fi fi if [ ! -e "$A2MODEDIR/ssl.load" ] || [ ! -e "$A2MODEDIR/ssl.conf" ]; then @@ -477,9 +488,12 @@ fi # Add VirtualHosts. +# - on fresh install # -db_get apache2-cn/wwwhost || true -if [ "$RET" = "true" ]; then +if [ -z "$2" ]; then + + db_get apache2-cn/wwwhost || true + if [ "$RET" = "true" ]; then # Add WWW VirtualHost. if [ -f "$CONFDIR/sites-available/$FQDN" ]; then @@ -490,17 +504,17 @@ if [ "$RET" = "true" ]; then fi chk_conf_tag "$CONFDIR/sites-available/$FQDN" - if [ ! -f "$CONFDIR/sites-available/$FQDN" ] || [ $RET -eq 0 -a -f "$CONFOLD" ]; then + if [ ! -f "$CONFDIR/sites-available/$FQDN" ] || [ $RET -eq 0 ]; then install_vhost -nvh -d -r www.$DOMAIN default $FQDN 000-$FQDN need_restart=1 fi chk_conf_tag "$CONFDIR/sites-available/www.$DOMAIN" - if [ ! -f "$CONFDIR/sites-available/www.$DOMAIN" ] || [ $RET -eq 0 -a -f "$CONFOLD" ]; then + if [ ! -f "$CONFDIR/sites-available/www.$DOMAIN" ] || [ $RET -eq 0 ]; then install_vhost default www.$DOMAIN www.$DOMAIN need_restart=1 fi -else + else # No WWW VirtualHost. if [ -f "$CONFDIR/sites-available/$FQDN" ]; then @@ -508,10 +522,11 @@ else fi chk_conf_tag "$CONFDIR/sites-available/$FQDN" - if [ ! -f "$CONFDIR/sites-available/$FQDN" ] || [ $RET -eq 0 -a -f "$CONFOLD" ]; then + if [ ! -f "$CONFDIR/sites-available/$FQDN" ] || [ $RET -eq 0 ]; then install_vhost -nvh -d -r $FQDN default $FQDN 000-$FQDN need_restart=1 fi + fi fi @@ -525,7 +540,7 @@ if [ $apache2_sslcert -eq 0 ]; then # No active SSL VirtualHosts found - add new one. chk_conf_tag "$CONFDIR/sites-available/ssl" - if [ ! -f "$CONFDIR/sites-available/ssl" ] || [ $RET -eq 0 -a -f "$CONFOLD" ]; then + if [ ! -f "$CONFDIR/sites-available/ssl" ] || [ $RET -eq 0 ]; then install_vhost -r $FQDN -n $HOST ssl ssl 001-ssl need_restart=1 fi @@ -540,7 +555,7 @@ if [ $apache2_sslcert -eq 0 ]; then if [ $RET -eq 0 ] && [ -n "$apache2_sslcf" ]; then SSLTMP=$(mktemp ${CONFDIR}/ssltmp.XXXXXX) - temp_files="${temp_files} ${SSLTMP}" + temp_files="${temp_files} ${SSLTMP} ${SSLTMP}.cn-old" cp ${CONFDIR}/sites-available/ssl $SSLTMP # SSLCertificateFile @@ -555,9 +570,9 @@ if [ $apache2_sslcert -eq 0 ]; then # SSLCertificateChainFile if [ -n "$apache2_sslccf" ]; then - cp_check_and_sed "^# SSLCertificateChainFile \/etc\/ssl\/certs/sureserverEDU\.pem" \ - "s#\# SSLCertificateChainFile /etc/ssl/certs/sureserverEDU.pem#SSLCertificateChainFile $apache2_sslccf #g" \ - $SSLTMP || true + cp_check_and_sed "^# SSLCertificateChainFile \/etc\/ssl\/certs/sureserverEDU\.pem" \ + "s#\# SSLCertificateChainFile /etc/ssl/certs/sureserverEDU.pem#SSLCertificateChainFile $apache2_sslccf #g" \ + $SSLTMP || true fi cp_mv $SSLTMP ${CONFDIR}/sites-available/ssl @@ -565,13 +580,24 @@ if [ $apache2_sslcert -eq 0 ]; then need_restart=1 # Just to be sure. - if [ -e "$SSLTMP" ]; then - rm -f $SSLTMP - fi + [ -e "${SSLTMP}" ] && rm -f ${SSLTMP} + [ -e "${SSLTMP}.cn-old" ] && rm -f ${SSLTMP}.cn-old fi fi +# Check file access permissions for SSL certificates. +# +cp_echo "CN: Checking file access permissions for Apache2 SSL certificates." +sslkey=/etc/ssl/private +sslcerts="${sslkey}/ca.key ${sslkey}/apache2-ca.key ${sslkey}/apache2.key" +for certf in $sslcerts; do + if [ -f "$certf" ]; then + chmod 600 $certf + fi +done + + # Check for CustomLog, ErrorLog and TransferLog in Apache2 configuration. # cp_echo "CN: Checking Apache2 CustomLog, ErrorLog and TransferLog directives." @@ -589,6 +615,25 @@ for file in $CONF $log_mask; do done +# Check and remove obsolete "Include /etc/apache2/sites-enabled/[^.#]*" from +# /etc/apache2/apache2.conf. +# +if egrep -iq "^[[:space:]]*Include[[:space:]]+\/etc\/apache2\/sites-enabled\/\[\^\.\#\]\*$" "$CONF"; then + + cp_echo "CN: Fixing obsolete Include line in $CONF." + CONFTMP=`mktemp $CONF.tmp.XXXXXX` + sed -r "/^[[:space:]]*Include[[:space:]]+\/etc\/apache2\/sites-enabled\/\[\^\.\#\]\*$/Id" \ + "$CONF" > "$CONFTMP" + + if ! egrep -iq "^[[:space:]]*Include[[:space:]]+\/etc\/apache2\/sites-enabled\/$" "$CONFTMP"; then + echo "Include /etc/apache2/sites-enabled/" >> "$CONFTMP" + fi + + cp_mv "$CONFTMP" "$CONF" + need_restart=1 +fi + + # Start Apache2 web server on boot? # This will enable Apache2 in /etc/default/apache2 file. # @@ -680,6 +725,7 @@ cp_mail "$PKG" # (re)generate monit.d files if monit-cn is installed. # if [ -x "/usr/sbin/update-monit.d" ]; then + cp_echo "CN: Updating monit configuration..." update-monit.d || true fi