izmjene u postinstu
[apache2-cn.git] / debian / postinst
index ebebc6b..cd51a84 100755 (executable)
@@ -2,28 +2,13 @@
 
 set -e
 
+[ "$1" = "configure" ] || exit 0
 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
 
-# Source debconf library.
+# Load Debconf
 . /usr/share/debconf/confmodule
 
-case "$1" in
-    configure)
-        # continue below
-        ;;
-
-    abort-upgrade|abort-remove|abort-deconfigure)
-        exit 0
-        ;;
-
-    *)
-        echo "postinst called with unknown argument \`$1'" >&2
-        exit 0
-        ;;
-esac
-
-
-# Include CARNet functions.
+# Load CARNet Tools
 . /usr/share/carnet-tools/functions.sh
 
 PKG="apache2-cn"
@@ -78,7 +63,7 @@ tag_conf () {
 ## Begin - Generated by CARNet package apache2-cn
 #
 #  REMOVE this whole block if you DON'T WANT apache2-cn
-#  to edit your configuration file.
+#  to edit or undo your changes to this configuration file.
 #
 ## End - Generated by CARNet package apache2-cn
 EOF
@@ -288,7 +273,7 @@ backup_conf () {
         cp_echo "CN: Doing backup for all files in $dir"
         for file in ${dir}/*; do
             if [ -f "$file" ]; then
-                if [ -z "$(echo $file | egrep '^/.*~')" ]; then
+                if [ -z "$(echo "$file" | egrep '^/.*(~|(\.(old|staro|bkp|bak|swp|tmp|dpkg-.+|cn-.+)))$')" ]; then
                     backup_dir="$BACKUPDIR/$(basename $(dirname "$file"))"
                     cp_backup_conffile -d "$backup_dir" -p "$file"
                 fi
@@ -330,6 +315,7 @@ move_conf () {
     if [ -d "${dir}" ] && [ -n "$(ls -A ${dir}/)" ]; then
         mkdir -p "$newdir"
         for file in ${dir}/*; do
+            [ -z "$(echo "$file" | egrep '^/.*(~|(\.(old|staro|bkp|bak|swp|tmp|dpkg-.+|cn-.+)))$')" ] || continue
             newfile="${newdir}/$(basename "$file" .conf).conf"
             if [ ! -e "$newfile" ]; then
                 cp_echo "CN: Preserving changes to $newfile (renamed from $file)."
@@ -369,6 +355,8 @@ rename_conf () {
     if [ -d "${edir}" ] && [ -n "$(ls -A ${edir}/)" ]; then
         mkdir -p "$adir"
         for efile in ${edir}/*; do
+            [ -z "$(echo "$efile" | egrep '^/.*(~|(\.(old|staro|bkp|bak|swp|tmp|dpkg-.+|cn-.+)))$')" ] || continue
+
             [ ! -e "${edir}/$(basename "$efile" .conf).conf" ] || continue
 
             afile="$(readlink -q -m "$efile")"
@@ -392,6 +380,25 @@ rename_conf () {
     fi
 }
 
+# listconffiles()
+#
+#   Recursively walks /etc/apache2/apache2.conf for Include and
+#   IncludeOptional directives.
+#   Prints all configfiles so defined.
+#
+listconffiles () {
+    local i incs
+    local base_dir="`dirname $1`"
+
+    incs=`awk 'tolower($1) ~ /include(optional)?/ { sub("/$","/*",$2); print $2; }' $1`
+    incs=`echo "$incs" | sed -r "s#^([^/])#${base_dir}/\1#"`
+    if [ -n "$incs" ]; then
+        for i in $incs; do
+            if [ -e "$i" ]; then echo "`readlink -m -q $i`"; listconffiles "$i"; fi
+        done
+    fi
+}
+
 
 # Set trap for deleting all temp files.
 #
@@ -414,7 +421,7 @@ backup_conf $CONFDIR/sites-available
 cp_echo "CN: Backup is located in directory: $BACKUPDIR/"
 
 
-# Enable Apache2 web server modules (mpm_prefork, cgi, rewrite, userdir, suexec, php5, ssl).
+# Enable Apache2 web server modules (mpm_prefork, cgi, rewrite, userdir, suexec, php7.0, ssl).
 #
 if [ -e "$CONF" ]; then
     cp_echo "CN: Enabling the prefork Apache2 MPM."
@@ -424,11 +431,12 @@ if [ -e "$CONF" ]; then
     fi
 
     cp_echo "CN: Enabling required Apache2 web server modules."
+    a2enmod -m -q access_compat
     a2enmod -m -q cgi
     a2enmod -m -q rewrite
     a2enmod -m -q userdir
     a2enmod -m -q suexec
-    a2enmod -m -q php5
+    a2enmod -m -q php7.0
     a2enmod -m -q ssl
 fi
 
@@ -476,6 +484,43 @@ if [ -e "$CONF" ]; then
     rm -f "$CONFTMP"
 fi
 
+# Remove deprecated directives. Add default Mutex if not defined.
+#
+if [ -e "$CONF" ]; then
+
+    ( listconffiles "$CONF"; echo "$CONF" ) | while read -r a2cfile; do
+
+        a2cfiletmp=`mktemp $a2cfile.tmp.XXXXXX`
+        temp_files="${temp_files} ${a2cfiletmp}"
+        cp "$a2cfile" "$a2cfiletmp"
+
+        if egrep -iq "^[[:space:]]*NameVirtualHost[[:space:]]+" "$a2cfiletmp"; then
+            cp_echo "CN: Removing deprecated NameVirtualHost from $a2cfile"
+            sed -r -i '/^[[:space:]]*NameVirtualHost[[:space:]]+/Id' \
+                "$a2cfiletmp"
+        fi
+
+        if egrep -iq "^[[:space:]]*SSLMutex[[:space:]]+" "$a2cfiletmp"; then
+            cp_echo "CN: Removing deprecated SSLMutex from $a2cfile"
+            sed -r -i '/^[[:space:]]*SSLMutex[[:space:]]+/Id' \
+                "$a2cfiletmp"
+        fi
+
+        if [ "$a2cfile" = "$CONF" ]; then
+            if ! egrep -iq "^[[:space:]]*Mutex[[:space:]]+" "$a2cfiletmp"; then
+                cp_echo "CN: Adding default Mutex to $a2cfile"
+                echo 'Mutex file:${APACHE_LOCK_DIR} default' >> "$a2cfiletmp"
+            fi
+        fi
+
+        if ! cmp -s "$a2cfiletmp" "$a2cfile"; then
+            cp_mv "$a2cfiletmp" "$a2cfile"
+            need_restart=1
+        fi
+        rm -f "$a2cfiletmp"
+    done
+fi
+
 
 # Install CARNet specific configuration file.
 #