Initial commit
[apache2-cn.git] / debian / postrm
1 #!/bin/sh
2
3 set -e
4
5 # Debconf
6 . /usr/share/debconf/confmodule
7
8 # Include CARNet functions.
9 . /usr/share/carnet-tools/functions.sh
10
11
12 HOST=$(hostname -f)
13 DOMAIN=$(hostname -d)
14 sitefiles="000-$HOST www.$DOMAIN 001-ssl"
15 sitesdir=/etc/apache2/sites-available
16
17
18 case "$1" in
19         purge)
20                 # Get CARNet config files in /etc/apache2/sites-available directory.
21                 if [ -d "${sitesdir}" ] && [ -n "$(ls ${sitesdir}/)" ]; then
22
23                     sitefiles=""
24                     for file in ${sitesdir}/*; do
25                         if [ -f "$file" ]; then
26                             if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" $file; then
27                                 site=`echo "$file" | sed 's/^\/.*\///'`
28                                 sitefiles="$sitefiles $site"
29                             fi
30                         fi
31                     done
32                 fi
33                 
34                 # Remove our vhosts.
35                 for site in $sitefiles; do
36                 
37                     if [ -e "$sitesdir/$site" ]; then
38
39                         cp_echo "CN: Removing $site site configuration file."
40                         rm -f $sitesdir/$site
41                     fi
42                 done
43                 
44                 # Remove default DocumentRoot if there's only a one line index.html there
45                 docroots="/var/www/$HOST.$DOMAIN /var/www/www.$DOMAIN"
46                 
47                 if [ -d "/var/www" ]; then
48                 
49                     for docroot in $docroots; do
50
51                         if [ -d $docroot ]; then
52                             if [ "x$(echo ${docroot}/*)" = "x${docroot}/index.html" ]; then
53                                 if [ "$(wc -l ${docroot}/index.html | awk '{print $1}')" -eq 1 ]; then
54                 
55                                     cp_echo "CN: Removing document root directory ${docroot}."
56                                     rm -f $docroot/index.html
57                                     rmdir $docroot || true
58                                 fi
59                             fi
60                         fi
61                     done
62                 fi
63                 
64                 # Remove CARNet specific configuration.
65                 if [ -d "$CONFDIR/conf.d" ] && [ -n "$(ls ${CONFDIR}/conf.d/)" ]; then
66                     cp_echo "CN: Disabling CARNet specific configuration."
67                     for file in /etc/apache2/conf.d/*; do
68                         if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" $file; then
69                             rm -f $file
70                         fi
71                     done
72                 fi
73
74                 # Debconf purge
75                 db_purge
76                 
77                 # Mail root
78                 cp_mail "apache2-cn"
79                 ;;
80         *)
81                 ;;
82 esac
83
84
85 db_stop
86
87 exit 0