-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuninstall.sh
executable file
·106 lines (97 loc) · 2.95 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
NGINX_CONF="crowdsec_openresty.conf"
NGINX_CONF_DIR="/usr/local/openresty/nginx/conf/conf.d/"
LIB_PATH="/usr/local/openresty/lualib/plugins/crowdsec/"
PKG="apt"
PACKAGE_LIST="dpkg -l"
SILENT="false"
#Accept cmdline arguments to overwrite options.
while [[ $# -gt 0 ]]
do
case $1 in
-y|--yes)
SILENT="true"
;;
esac
shift
done
check_pkg_manager(){
if [ -f /etc/redhat-release ]; then
PKG="yum remove"
PACKAGE_LIST="yum list installed"
elif [ -f /etc/system-release ]; then
if grep -q "Amazon Linux release 2 (Karoo)" < /etc/system-release ; then
PKG="yum remove"
PACKAGE_LIST="yum list installed"
fi
elif [ -f /etc/debian_version ]; then
PKG="apt remove --purge"
PACKAGE_LIST="dpkg -l"
else
echo "Distribution is not supported, exiting."
exit
fi
}
remove_lua_dependency() {
DEPENDENCY=(
"pintsized/lua-resty-http"
)
for dep in ${DEPENDENCY[@]};
do
opm list | grep ${dep} > /dev/null
if [[ $? == 0 ]]; then
if [[ ${SILENT} == "true" ]]; then
opm remove ${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
opm remove ${dep} > /dev/null && echo "${dep} successfully removed"
fi
fi
fi
done
}
remove_openresty_dependency() {
DEPENDENCY=(
"openresty-opm"
)
for dep in ${DEPENDENCY[@]};
do
$PACKAGE_LIST | grep ${dep} > /dev/null
if [[ $? == 0 ]]; then
if [[ ${SILENT} == "true" ]]; then
$PKG -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
$PKG -y -qq ${dep} > /dev/null && echo "${dep} successfully removed"
fi
fi
fi
done
}
uninstall() {
rm -rf ${LIB_PATH}
rm ${NGINX_CONF_DIR}/${NGINX_CONF}
}
if ! [ $(id -u) = 0 ]; then
log_err "Please run the uninstall script as root or with sudo"
exit 1
fi
check_pkg_manager
remove_lua_dependency
remove_openresty_dependency
uninstall
echo "crowdsec-openresty-bouncer uninstalled successfully"
echo ""
echo "Don't forget to remove 'include /usr/local/openresty/nginx/conf/conf.d/crowdsec_openresty.conf;' in your nginx configuration file to disable the bouncer and make openresty start again."
echo ""
echo "Run 'sudo systemctl restart openresty.service' to stop openresty-bouncer"