File: postrm

package info (click to toggle)
sympa 5.2.3-1.2%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 21,384 kB
  • ctags: 3,566
  • sloc: perl: 27,368; sh: 3,990; makefile: 1,366; ansic: 226; php: 105; lisp: 32
file content (234 lines) | stat: -rw-r--r-- 5,529 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/sh

set -e

. /usr/share/debconf/confmodule

case "$1" in
    "remove")
	# Don't fail here, the package might not be configured yet
	db_get sympa/use_wwsympa || true
	use_wwsympa="$RET"
	db_get sympa/use_soap || true
	use_soap="$RET"

    # Check whether the syslog configuration file is present
    # in case another system log daemon is used instead of syslog
	if [ -x /usr/sbin/syslog-facility ]; then
	    if [ -e /etc/syslog.conf ]; then
		if [ -f /etc/sympa/facility ]; then
		    syslog-facility remove "`cat /etc/sympa/facility`"
		
		    if [ -x /etc/init.d/sysklogd ]; then
				invoke-rc.d sysklogd reload
		    fi
		    rm -f /etc/sympa/facility
		fi
	    fi
	fi

	if [ "$use_wwsympa" = "true" -o "$use_soap" = "true" ]; then
	    ## Remove Web server configuration
	    db_get wwsympa/webserver_type
	    webserver="$RET"
	    
	    case $webserver in
			"Apache")
		    webserver="apache"
		    ;;
			"Apache-SSL")
		    webserver="apache-ssl"
		    ;;
			"Apache 2")
			webserver="apache2"
			;;
			*)
		    webserver="none"
		    ;;
	    esac

		if [ "$use_soap" = "true" ]; then
			# Remove symbolic link to webserver configuration snippet
			link=`readlink /etc/$webserver/conf.d/sympa-soap || true`
			if [ "$link" = "/etc/sympa/apache-soap" ]; then
				rm -f /etc/$webserver/conf.d/sympa-soap
			fi
		fi

	    if [ $webserver != "none" ]; then
		    # Restarting web server if it was requested at configuration time.
		    db_get wwsympa/webserver_restart
		    restart="$RET"
		    
		    if [ "$restart" = "true" ]; then
				if [ -x /etc/init.d/$webserver ]; then
					/etc/init.d/$webserver restart
				fi

		        # End up with debconf
			db_stop
		    fi
		fi
	fi
	;;
    
    "purge")
	db_get sympa/use_wwsympa
	use_wwsympa="$RET"

	if [ "$use_wwsympa" = "true" ]; then
		db_input high wwsympa/remove_spool || true
    	db_go
	    db_get wwsympa/remove_spool
	    remove_archives="$RET"
    
	    if [ "$remove_archives" = "true" ]; then
		echo ""
		echo "Removing archives and spool subdirectories as requested ..."
		rm -rf /var/lib/sympa/wwsarchive 2>/dev/null || true
		rm -rf /var/spool/sympa/wws*  2>/dev/null || true
	    fi
	fi

        # Delete the log files if purging
        # Remove aliases too.
	rm -f /var/log/sympa.log*

	if [ -f /etc/aliases ]; then
	    sed -e '/#-- SYMPA begin/,/#-- SYMPA end/d' \
		/etc/aliases >/etc/aliases.new
	    mv -f /etc/aliases.new /etc/aliases
	    newaliases || true
	fi

	rm -f /etc/sympa/cookie   2>/dev/null || true
	rm -f /etc/sympa/cookies.history

        # Remove configuration files
	rm -f /etc/sympa/data_structure.version
	rm -f /etc/sympa/sympa.conf
	rm -f /etc/sympa/wwsympa.conf

        # Try to remove if empty
	rmdir /etc/sympa          2>/dev/null || true

 	db_input high sympa/remove_spool || true
    db_go
	db_get sympa/remove_spool
	remove_spool="$RET"

	if [ "$remove_spool" = "true" ]; then
	    echo ""
	    echo "Removing lists data and spool directory as requested ..."
	    rm -rf /var/lib/sympa 2>/dev/null || true
	    rm -rf /var/spool/sympa 2>/dev/null || true
	fi

        # Remove the database if asked for
	db_get sympa/use_db
	use_db="$RET"

	if [ "$use_db" = "true" ]; then 
	    
	    # Check whether it was configured
	    db_get sympa/db_configured
	    db_configured="$RET"

	    db_input high sympa/db_removeonpurge || true
    	db_go
	    db_get sympa/db_removeonpurge
	    db_removeonpurge="$RET"
	    
	    if [ "$db_configured" = "true" -a "$db_removeonpurge" = "true" ]
	    then
	        # Get the database info
		db_get sympa/db_type
		db_type="$RET"
		
		db_get sympa/db_hostname
		db_host="$RET"
	    
		db_get sympa/db_name
		db_name="$RET"
		
		db_fset sympa/db_adminpasswd seen false
		db_input critical sympa/db_adminpasswd || true
		db_go
		
		db_get sympa/db_adminpasswd
		adminpass="$RET"
		db_reset sympa/db_adminpasswd
		
		set +e
		
		case $db_type in
		    "PostgreSQL")
			echo -n "Trying to remove your PostgreSQL database ..."
			perl -e "
			    use DBI;

			    my \$dsn = \"DBI:Pg:dbname=template1\";

			    if ($db_host ne 'localhost') {
			        \$dsn .= \";host=$db_host\";
			    }

			    # Connect to PostgreSQL
			    my \$dbh = DBI->connect(\$dsn, \"postgres\", \"$adminpass\",
				    		    {\"RaiseError\" => 1});

			    # Remove database
			    eval {\$dbh->do(\"DROP DATABASE $db_name\")};
			
			    # Remove user sympa
			    \$dbh->do(\"DELETE FROM pg_shadow WHERE usename='sympa'\");

			    \$dbh->disconnect();" >/dev/null 2>&1
		        ;;

		    "MySQL")
			echo -n "Trying to remove your MySQL database ..."
			perl -e "
			    use DBI;

			    my \$dsn = \"DBI:mysql:database=mysql\";

			    if ($db_host ne 'localhost') {
			        \$dsn .= \";host=$db_host\";
			    }
			
			    # Connect to mysql
			    my \$dbh = DBI->connect(\$dsn, \"root\", \"$adminpass\",
						    {\"RaiseError\" => 1});

			    # Remove the database
			    eval {\$dbh->do(\"DROP DATABASE $db_name\")};

			    # Remove user sympa
			    \$dbh->do(\"DELETE FROM user WHERE user='sympa'\");
			    \$dbh->do(\"DELETE FROM db WHERE user='sympa'\");
			    \$dbh->do(\"FLUSH PRIVILEGES\");
			
			    \$dbh->disconnect();" >/dev/null 2>&1
			;;
		esac

		if [ "$?" != "0" ]; then
		    /bin/echo -e "Failed\n\n"
		    echo "I was not able to connect to the database server."
		    echo "You will have to remove the sympa database yourself."
		else
		    echo " OK"
		    db_set "sympa/db_configured" "false"
		fi
		
		set -e
	    fi
	fi
	;;
esac


# Other jobs
#DEBHELPER#