Prva inacica paketa za Debian jessie distribuciju.
[apache2-cn.git] / debian / postrm
index 5171fe3..325beea 100755 (executable)
@@ -5,16 +5,6 @@ set -e
 # Debconf
 . /usr/share/debconf/confmodule
 
-# Include CARNet functions.
-. /usr/share/carnet-tools/functions.sh
-
-CONFDIR="/etc/apache2"
-sitesdir=${CONFDIR}/sites-available
-HOST=$(hostname -f)
-DOMAIN=$(hostname -d)
-sitefiles=
-
-
 case "$1" in
     purge)
         # continue below
@@ -24,27 +14,45 @@ case "$1" in
         ;;
 esac
 
-# Get CARNet config files in /etc/apache2/sites-available directory.
-if [ -d "${sitesdir}" ] && [ -n "$(ls ${sitesdir}/)" ]; then
-    for file in ${sitesdir}/*; do
-        if [ -f "$file" ]; then
-            if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" $file; then
-                site=`echo "$file" | sed 's/^\/.*\///'`
-                sitefiles="$sitefiles $site"
+CONFDIR="/etc/apache2"
+HOST=$(hostname -f)
+DOMAIN=$(hostname -d)
+
+# purge_conf()
+#
+#   Purge Apache2 configuration files located in specified directory.
+#
+purge_conf () {
+    local ctype dir file
+
+    ctype="$1"
+    dir="$2"
+
+    case "$ctype" in
+        site|conf)
+            # continue below
+            ;;
+        *)
+            return 1
+            ;;
+    esac
+
+    if [ -d "${dir}" ] && [ -n "$(ls -A ${dir}/)" ]; then
+        for file in ${dir}/*.conf; do
+            if [ -f "$file" ]; then
+                if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" "$file"; then
+                    a2dis$ctype -p -f -q "`basename "$file" .conf`" || exit $?
+                    rm -f "$file"
+                fi
             fi
-        fi
-    done
-fi
+        done
+    fi
+}
 
-# Remove our vhosts.
-if [ -n "$sitefiles" ]; then
-    for site in $sitefiles; do
-        if [ -e "$sitesdir/$site" ]; then
-            cp_echo "CN: Removing $site site configuration file."
-            rm -f $sitesdir/$site
-        fi
-    done
-fi
+# Configuration generated by this CARNet package.
+echo "CN: Purging $PKG configuration for Apache2."
+purge_conf site ${CONFDIR}/sites-available
+purge_conf conf ${CONFDIR}/conf-available
 
 # Remove default DocumentRoot if there's only a one line index.html there
 docroots="/var/www/$HOST /var/www/www.$DOMAIN"
@@ -54,7 +62,7 @@ if [ -d "/var/www" ]; then
         if [ -d $docroot ]; then
             if [ "x$(echo ${docroot}/*)" = "x${docroot}/index.html" ]; then
                 if [ "$(wc -l ${docroot}/index.html | awk '{print $1}')" -eq 1 ]; then
-                    cp_echo "CN: Removing document root directory ${docroot}."
+                    echo "CN: Removing document root directory ${docroot}."
                     rm -f $docroot/index.html
                     rmdir $docroot || true
                 fi
@@ -63,24 +71,6 @@ if [ -d "/var/www" ]; then
     done
 fi
 
-# Remove CARNet specific configuration.
-if [ -d "${CONFDIR}/conf.d" ] && [ -n "$(ls ${CONFDIR}/conf.d/)" ]; then
-    cp_echo "CN: Disabling CARNet specific configuration."
-    for file in ${CONFDIR}/conf.d/*; do
-        if [ -f "$file" ]; then
-            if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" $file; then
-                rm -f $file
-            fi
-        fi
-    done
-fi
-
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
 #DEBHELPER#
 
-# Mail root
-cp_mail "apache2-cn"
-
 exit 0