source: lliurex-analytics-server/trunk/fuentes/debian/postrm @ 6768

Last change on this file since 6768 was 5128, checked in by mabarracus, 2 years ago

Fix errors counting clients
Better postinstallation script

File size: 2.9 KB
Line 
1#!/bin/sh
2# postrm script
3#
4# see: dh_installdeb(1)
5
6set -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
21do_dialog(){
22    input=$(dialog      \
23    --title "$1"        \
24    --inputbox "$2"     0 0     \
25    3>&1 1>&2 2>&3 3>&-)
26    clear
27}
28ask_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
38case "$1" in
39    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
40    ;;
41    purge)
42        rootuser=""
43        rootpass=""
44        RET=$(mysql -s -N -e "show databases;" 2>/dev/null||true)
45        if [ -z "${RET}" ]; then
46            ask_root=yes
47            rootuser=$(cat /etc/mysql/debian.cnf |grep -A 4 '\[client\]'|perl -ne '/user[ \t]*=[ \t]*(.*)/i && print $1')
48            rootpass=$(cat /etc/mysql/debian.cnf |grep -A 4 '\[client\]'|perl -ne '/password[ \t]*=[ \t]*(.*)/i && print $1')
49            if [ -n "$rootuser" -a -n "$rootpass" ]; then
50                root_test=$(mysql -u $rootuser -p$rootpass -s -N -e "show databases" 2>/dev/null || true)
51                if [ -n "$root_test" ]; then
52                    ask_root="no"
53                    rootuser="-u$rootuser"
54                    rootpass="-p$rootpass"
55                fi
56            fi
57            if  [ "x$ask_root" = "xyes" ]; then
58                do_dialog 'Mysql root password?'
59                rootpass=${input}
60                RET=$(mysql -uroot -p$rootpass -s -N -e "show databases" 2>/dev/null||true)
61                if [ -z "${RET}" ]; then
62                    echo "Error removing database"
63                    exit 0
64                else
65                    rootuser="-uroot"
66                    rootpass="-p$rootpass"
67                fi
68            fi
69        fi
70        echo "Removing database.."
71        USER=$(mysql $rootuser $rootpass -s -N -e "select user from mysql.db where db like 'analytics';" 2>/dev/null||true)
72        if [ -z "${USER}" ]; then
73            echo "Error removing database"
74            exit 0
75        fi
76        mysql $rootuser $rootpass -s -N -e "drop database analytics;" 2>/dev/null  || true
77        mysql $rootuser $rootpass -s -N -e "drop user ${USER};" 2>/dev/null || true
78        mysql $rootuser $rootpass -s -N -e "flush privileges;" 2>/dev/null || true
79        echo "Database analytics & user ${USER} removed from mysql"
80        if [ -f "/etc/lliurex-analytics-server/config_db" ]; then
81            rm -f /etc/lliurex-analytics-server/config_db
82            rmdir /etc/lliurex-analytics-server
83        else
84            echo "Warning: config_db file not found! "
85        fi
86        exit 0
87    ;;
88
89    *)
90        echo "postrm called with unknown argument \`$1'" >&2
91        exit 1
92    ;;
93esac
94
95# dh_installdeb will replace this with shell code automatically
96# generated by other debhelper scripts.
97
98#DEBHELPER#
99
100exit 0
Note: See TracBrowser for help on using the repository browser.