-
Notifications
You must be signed in to change notification settings - Fork 4
/
geoip-shell-uninstall.sh
129 lines (98 loc) · 2.85 KB
/
geoip-shell-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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
# shellcheck disable=SC2154,SC2086,SC2034,SC1090
# geoip-shell-uninstall
# Copyright: antonk (antonk.d3v@gmail.com)
# github.com/friendly-bits
# uninstalls or resets geoip-shell
#### Initial setup
p_name="geoip-shell"
script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)
manmode=1
nolog=1
in_uninstall=1
geoinit="${p_name}-geoinit.sh"
for geoinit_path in "$script_dir/$geoinit" "/usr/bin/$geoinit"; do
[ -f "$geoinit_path" ] && break
done
[ ! "$geoinit_path" ] && die "Cannot uninstall $p_name because ${p_name}-geoinit.sh is missing."
. "$geoinit_path" &&
: "${_fw_backend:=$_fw_backend_def}" &&
. "$_lib-uninstall.sh" &&
{
[ "$_fw_backend" ] && { . "$_lib-$_fw_backend.sh" || exit 1; } ||
echolog -err "Firewall backend is unknown. Cannot remove firewall rules." \
"Please restart the machine after uninstalling."
:
} || exit 1
san_args "$@"
newifs "$delim"
set -- $_args; oldifs
debugentermsg
#### USAGE
usage() {
cat <<EOF
Usage: $me [-V] [-h]
1) Removes geoip firewall rules
2) Removes geoip cron jobs
3) Deletes scripts' data folder (/var/lib/geoip-shell or /etc/geoip-shell/data on OpenWrt)
4) Deletes the scripts from /usr/sbin
5) Deletes the config folder /etc/geoip-shell
Options:
-r : Leave the config file and the backup files in place
-V : Version
-h : This help
EOF
}
rm_scripts() {
printed=
for script_name in fetch apply manage cronsetup run backup mk-fw-include fw-include detect-lan uninstall geoinit; do
s_path="${install_dir}/${p_name}-$script_name.sh"
[ -f "$s_path" ] && {
[ ! "$printed" ] && { printf '%s\n' "Deleting $p_name main scripts from $install_dir..."; printed=1; }
rm -f "$s_path"
}
done
rm_geodir "$lib_dir" "library scripts"
:
}
#### PARSE ARGUMENTS
while getopts ":rVh" opt; do
case $opt in
r) keepdata="-r" ;;
V) echo "$curr_ver"; exit 0 ;;
h) usage; exit 0 ;;
*) ;;
esac
done
shift $((OPTIND-1))
is_root_ok || exit 1
lib_dir="/usr/lib/$p_name"
_lib="$lib_dir/$p_name-lib"
### VARIABLES
old_install_dir="$(command -v "$p_name")"
old_install_dir="${old_install_dir%/*}"
install_dir="${old_install_dir:-"$install_dir"}"
[ ! "$install_dir" ] && die "Can not determine installation directory. Try setting \$install_dir manually"
[ "$script_dir" != "$install_dir" ] && [ -f "$install_dir/${p_name}-uninstall.sh" ] && [ ! "$norecur" ] && {
# prevents infinite loop
export norecur=1
call_script "$install_dir/${p_name}-uninstall.sh" "$keepdata" && exit 0
}
: "${conf_dir:=/etc/$p_name}"
[ -d "$conf_dir" ] && : "${conf_file:="$conf_dir/$p_name.conf"}"
[ -s "$conf_file" ] && nodie=1 getconfig datadir
: "${datadir:="/var/lib/geoip-shell"}"
#### MAIN
rm_setupdone
rm_iplists_rules
rm_cron_jobs
# For OpenWrt
[ "$_OWRT_install" ] && {
rm_owrt_init
rm_owrt_fw_include
restart_owrt_fw
}
rm_symlink
rm_scripts
[ ! "$keepdata" ] && { rm_config; rm_data; }
printf '%s\n\n' "Uninstall complete."