1 | #!/bin/sh |
---|
2 | # postrm script |
---|
3 | # |
---|
4 | # see: dh_installdeb(1) |
---|
5 | |
---|
6 | #set -e |
---|
7 | |
---|
8 | # summary of how this script can be called: |
---|
9 | # * <postrm> `remove' |
---|
10 | # * <postrm> `purge' |
---|
11 | # * <old-postrm> `upgrade' <new-version> |
---|
12 | # * <new-postrm> `failed-upgrade' <old-version> |
---|
13 | # * <new-postrm> `abort-install' |
---|
14 | # * <new-postrm> `abort-install' <old-version> |
---|
15 | # * <new-postrm> `abort-upgrade' <old-version> |
---|
16 | # * <disappearer's-postrm> `disappear' <overwriter> |
---|
17 | # <overwriter-version> |
---|
18 | # for details, see http://www.debian.org/doc/debian-policy/ or |
---|
19 | # the debian-policy package |
---|
20 | |
---|
21 | do_dialog(){ |
---|
22 | input=$(dialog \ |
---|
23 | --title "$1" \ |
---|
24 | --inputbox "$2" 0 0 \ |
---|
25 | 3>&1 1>&2 2>&3 3>&-) |
---|
26 | clear |
---|
27 | } |
---|
28 | ask_question(){ |
---|
29 | dialog --yesno "$1" 0 0 |
---|
30 | if [ $? -eq 0 ]; then |
---|
31 | input=yes |
---|
32 | else |
---|
33 | input=no |
---|
34 | fi |
---|
35 | clear |
---|
36 | } |
---|
37 | |
---|
38 | case "$1" in |
---|
39 | remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) |
---|
40 | ;; |
---|
41 | purge) |
---|
42 | mysql_cmd="mysql -s -u root" |
---|
43 | RET=$(echo "show databases;" |${mysql_cmd} 2>/dev/null) |
---|
44 | if [ -z "${RET}" ]; then |
---|
45 | ask_question 'Mysql root password?' |
---|
46 | rootpass=${input} |
---|
47 | mysql_cmd="mysql -s -uroot -p${input}" |
---|
48 | RET=$(echo "show databases;" |${mysql_cmd} 2>/dev/null) |
---|
49 | if [ -z "${RET}" ]; then |
---|
50 | echo "Error removing database" |
---|
51 | exit 0 |
---|
52 | fi |
---|
53 | fi |
---|
54 | echo "Removing database.." |
---|
55 | USER=$(echo "select user from mysql.db where db like 'analytics';"| ${mysql_cmd} 2>/dev/null) |
---|
56 | if [ -z "${USER}" ]; then |
---|
57 | echo "Error removing database" |
---|
58 | exit 0 |
---|
59 | fi |
---|
60 | echo "drop database analytics;" | ${mysql_cmd} 2>/dev/null |
---|
61 | echo "drop user ${USER};"| ${mysql_cmd} 2>/dev/null |
---|
62 | echo "flush privileges;"| ${mysql_cmd} 2>/dev/null |
---|
63 | echo "Database analytics & user ${USER} removed from mysql" |
---|
64 | exit 0 |
---|
65 | ;; |
---|
66 | |
---|
67 | *) |
---|
68 | echo "postrm called with unknown argument \`$1'" >&2 |
---|
69 | exit 1 |
---|
70 | ;; |
---|
71 | esac |
---|
72 | |
---|
73 | # dh_installdeb will replace this with shell code automatically |
---|
74 | # generated by other debhelper scripts. |
---|
75 | |
---|
76 | #DEBHELPER# |
---|
77 | |
---|
78 | exit 0 |
---|