Fix file access permissions and group ownership for Apache2 SSL
[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 CONFDIR="/etc/apache2"
12 sitesdir=${CONFDIR}/sites-available
13 HOST=$(hostname -f)
14 DOMAIN=$(hostname -d)
15 sitefiles=
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                     for file in ${sitesdir}/*; do
24                         if [ -f "$file" ]; then
25                             if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" $file; then
26                                 site=`echo "$file" | sed 's/^\/.*\///'`
27                                 sitefiles="$sitefiles $site"
28                             fi
29                         fi
30                     done
31                 fi
32                 
33                 # Remove our vhosts.
34                 if [ -n "$sitefiles" ]; then
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                 fi
44                 
45                 # Remove default DocumentRoot if there's only a one line index.html there
46                 docroots="/var/www/$HOST /var/www/www.$DOMAIN"
47                 
48                 if [ -d "/var/www" ]; then
49                 
50                     for docroot in $docroots; do
51
52                         if [ -d $docroot ]; then
53                             if [ "x$(echo ${docroot}/*)" = "x${docroot}/index.html" ]; then
54                                 if [ "$(wc -l ${docroot}/index.html | awk '{print $1}')" -eq 1 ]; then
55                 
56                                     cp_echo "CN: Removing document root directory ${docroot}."
57                                     rm -f $docroot/index.html
58                                     rmdir $docroot || true
59                                 fi
60                             fi
61                         fi
62                     done
63                 fi
64                 
65                 # Remove CARNet specific configuration.
66                 if [ -d "${CONFDIR}/conf.d" ] && [ -n "$(ls ${CONFDIR}/conf.d/)" ]; then
67                     cp_echo "CN: Disabling CARNet specific configuration."
68                     for file in ${CONFDIR}/conf.d/*; do
69                         if [ -f "$file" ]; then
70                             if egrep -q "^## Begin - Generated by CARNet package apache2-cn$" $file; then
71                                 rm -f $file
72                             fi
73                         fi
74                     done
75                 fi
76
77                 # Debconf purge
78                 db_purge
79                 
80                 # Mail root
81                 cp_mail "apache2-cn"
82                 ;;
83         *)
84                 ;;
85 esac
86
87
88 db_stop
89
90 exit 0