forked from bluecherrydvr/bluecherry-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluecherry.postrm
95 lines (73 loc) · 2.24 KB
/
bluecherry.postrm
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
#!/bin/bash -e
set -x # trace
if [ -f /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
fi
function load_db_creds() {
# ATTENTION! Duplication of load_db_creds.sh
eval $(sed '/\(dbname\|user\|password\|host\)/!d;s/ *= */=/'";s/\"/'/g" /etc/bluecherry.conf)
}
function purge_files() {
echo "Removing recording files"
echo "SELECT filepath FROM Media" | mysql -h"${host:-localhost}" -D"$dbname" -u"$user" -p"$password" | tail -n +2 | \
while IFS= read -r MEDIAFILE
do
JPGFILE="`echo $MEDIAFILE | sed 's/[.]mkv$/.jpg/'`"
rm -f $MEDIAFILE $JPGFILE
# Try to remove empty basedirs recursively.
# This is probably slow, but
# - this is one time thing
# - the input is unsorted (possible to improve)
# - removing each Media file is not the same as removing Storage dirs contents recursively
BASEDIR="`dirname $MEDIAFILE`"
while rmdir "$BASEDIR"
do
BASEDIR="`dirname $BASEDIR`"
done
done
}
function drop_db() {
echo "Dropping database $dbname"
echo "DROP DATABASE $dbname" | mysql -h"${host:-localhost}" -D"$dbname" -u"$user" -p"$password"
# echo "DROP USER '$user'@'localhost'" | mysql -h"${host:-localhost}" -D"$dbname" -u"$user" -p"$password"
}
case "$1" in
remove)
a2dissite bluecherry.conf || true
# Reload some things
invoke-rc.d apache2 restart || true
invoke-rc.d rsyslog restart || true
;;
purge)
CONFIGFILE=/etc/bluecherry.conf
for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist; do
rm -f $CONFIGFILE$ext || true
done
load_db_creds
purge_files
drop_db
echo "Removing config file $CONFIGFILE"
rm -f $CONFIGFILE
if which ucf > /dev/null; then
ucf --purge $CONFIGFILE
fi
if which ucfr > /dev/null; then
ucfr --purge bluecherry $CONFIGFILE
fi
userdel bluecherry || true
groupdel bluecherry || true
db_purge || true
;;
esac
#DEBHELPER#
db_stop
# Remove cron file
cronfile=/etc/cron.d/bluecherry
if test -f $cronfile; then
rm $cronfile
fi
function warn_user_db() {
var_command='Warning!\n\nYou must run this command to finish the removal process or else you will not be able to reinstall Bluechery again\n***\necho DROP USER '$user'@'localhost' | mysql -h'${host:-localhost}' -u root -p\n***\n\n'
printf "\x1b[31m$var_command\x1b[0m\n";
}
warn_user_db