#!/bin/sh # postrm script # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `remove' # * `purge' # * `upgrade' # * `failed-upgrade' # * `abort-install' # * `abort-install' # * `abort-upgrade' # * `disappear' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package do_dialog(){ input=$(dialog \ --title "$1" \ --inputbox "$2" 0 0 \ 3>&1 1>&2 2>&3 3>&-) clear } ask_question(){ dialog --yesno "$1" 0 0 if [ $? -eq 0 ]; then input=yes else input=no fi clear } case "$1" in remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) ;; purge) if [ -d "/etc/lliurex-analytics-server" ]; then for dump in $(ls /etc/lliurex-analytics-server/dump*); do mkdir -p /etc/old-dumps-lliurex-analytics-server d=$(basename $dump) echo "moving $d into /etc/old-dumps-lliurex-analytics-server" mv /etc/lliurex-analytics-server/$d /etc/old-dumps-lliurex-analytics-server/ || true done fi rootuser="" rootpass="" RET=$(mysql -s -N -e "show databases;" 2>/dev/null||true) if [ -z "${RET}" ]; then ask_root=yes rootuser=$(cat /etc/mysql/debian.cnf |grep -A 4 '\[client\]'|perl -ne '/user[ \t]*=[ \t]*(.*)/i && print $1') rootpass=$(cat /etc/mysql/debian.cnf |grep -A 4 '\[client\]'|perl -ne '/password[ \t]*=[ \t]*(.*)/i && print $1') if [ -n "$rootuser" -a -n "$rootpass" ]; then root_test=$(mysql -u $rootuser -p$rootpass -s -N -e "show databases" 2>/dev/null || true) if [ -n "$root_test" ]; then ask_root="no" rootuser="-u$rootuser" rootpass="-p$rootpass" fi fi if [ "x$ask_root" = "xyes" ]; then do_dialog 'Mysql root password?' rootpass=${input} RET=$(mysql -uroot -p$rootpass -s -N -e "show databases" 2>/dev/null||true) if [ -z "${RET}" ]; then echo "Error removing database" exit 0 else rootuser="-uroot" rootpass="-p$rootpass" fi fi fi echo "Removing database.." USER=$(mysql $rootuser $rootpass -s -N -e "select user from mysql.db where db like 'analytics';" 2>/dev/null||true) if [ -z "${USER}" ]; then echo "Error removing database" exit 0 fi mysql $rootuser $rootpass -s -N -e "drop database analytics;" 2>/dev/null || true mysql $rootuser $rootpass -s -N -e "drop user ${USER};" 2>/dev/null || true mysql $rootuser $rootpass -s -N -e "flush privileges;" 2>/dev/null || true echo "Database analytics & user ${USER} removed from mysql" if [ -f "/etc/lliurex-analytics-server/config_db" ]; then rm -f /etc/lliurex-analytics-server/config_db rmdir /etc/lliurex-analytics-server else echo "Warning: config_db file not found! " fi exit 0 ;; *) echo "postrm called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0