-
Notifications
You must be signed in to change notification settings - Fork 10
/
uninstall.sh
executable file
·83 lines (73 loc) · 1.98 KB
/
uninstall.sh
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
#!/bin/bash
REQUIRE_SCRIPT="./lua-mod/uninstall.sh"
NGINX_CONF="crowdsec_nginx.conf"
NGINX_CONF_DIR="/etc/nginx/conf.d/"
ACCESS_FILE="access.lua"
LIB_PATH="/usr/local/lua/crowdsec/"
DATA_PATH="/var/lib/crowdsec/lua/"
SILENT="false"
usage() {
echo "Usage:"
echo " ./uninstall.sh -h Display this help message."
echo " ./uninstall.sh Uninstall the bouncer in interactive mode"
echo " ./uninstall.sh -y Uninstall the bouncer and accept everything"
exit 0
}
#Accept cmdline arguments to overwrite options.
while [[ $# -gt 0 ]]
do
case $1 in
-y|--yes)
SILENT="true"
shift
;;
-h|--help)
usage
;;
esac
shift
done
requirement() {
if [ -f "$REQUIRE_SCRIPT" ]; then
bash $REQUIRE_SCRIPT
fi
}
remove_nginx_dependency() {
DEPENDENCY=(
"libnginx-mod-http-lua"
"luarocks"
"lua5.1"
"gettext-base"
)
for dep in ${DEPENDENCY[@]};
do
dpkg -l | grep ${dep} > /dev/null
if [[ $? == 0 ]]; then
if [[ ${SILENT} == "true" ]]; then
sudo apt-get install -y -qq ${dep} > /dev/null && echo "${dep} successfully removed"
else
echo "${dep} found, do you want to remove it (Y/n)? "
read answer
if [[ ${answer} == "" ]]; then
answer="y"
fi
if [ "$answer" != "${answer#[Yy]}" ] ;then
apt-get remove --purge -y -qq ${dep} > /dev/null && echo "${dep} successfully removed"
fi
fi
fi
done
}
uninstall() {
rm ${NGINX_CONF_DIR}/${NGINX_CONF}
rm -rf ${DATA_PATH}
rm -rf ${LIB_PATH}
}
if ! [ $(id -u) = 0 ]; then
log_err "Please run the uninstall script as root or with sudo"
exit 1
fi
requirement
remove_nginx_dependency
uninstall
echo "crowdsec-nginx-bouncer uninstalled successfully"