forked from IceWhaleTech/get
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
322 lines (274 loc) · 8.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
#
# CasaOS Uninstaller Script
#
# GitHub: https://github.com/IceWhaleTech/CasaOS
# Issues: https://github.com/IceWhaleTech/CasaOS/issues
# Requires: bash, mv, rm, tr, grep, sed
#
# This script installs CasaOS to your system.
# In automated environments, you may want to run as root.
# If using curl, we recommend using the -fsSL flags.
#
# This only work on Linux systems. Please
# open an issue if you notice any bugs.
#
set -e
clear
# shellcheck disable=SC2016
echo '
_____ ____ _____
/ ____| / __ \ / ____|
| | __ _ ___ __ _| | | | (___
| | / _` / __|/ _` | | | |\___ \
| |___| (_| \__ \ (_| | |__| |____) |
\_____\__,_|___/\__,_|\____/|_____/
--- Made by IceWhale with YOU ---
'
###############################################################################
# Golbals #
###############################################################################
# Not every platform has or needs sudo (https://termux.com/linux.html)
((EUID)) && sudo_cmd="sudo"
readonly CASA_SERVICES=(
"casaos-gateway.service"
"casaos-user-service.service"
"casaos.service"
"casaos-local-storage.service"
)
readonly CASA_PATH=/casaOS
readonly CASA_EXEC=casaos
readonly CASA_BIN=/usr/local/bin/casaos
readonly CASA_SERVICE_USR=/usr/lib/systemd/system/casaos.service
readonly CASA_SERVICE_LIB=/lib/systemd/system/casaos.service
readonly CASA_SERVICE_ETC=/etc/systemd/system/casaos.service
readonly CASA_ADDON1=/etc/udev/rules.d/11-usb-mount.rules
readonly CASA_ADDON2=/etc/systemd/system/[email protected]
readonly CASA_UNINSTALL_PATH=/usr/bin/casaos-uninstall
# New Casa Files
readonly MANIFEST=/var/lib/casaos/manifest
readonly CASA_CONF_PATH_OLD=/etc/casaos.conf
readonly CASA_CONF_PATH=/etc/casaos
readonly CASA_RUN_PATH=/var/run/casaos
readonly CASA_USER_FILES=/var/lib/casaos
readonly CASA_LOGS_PATH=/var/log/casaos
readonly CASA_HELPER_PATH=/usr/share/casaos
readonly COLOUR_RESET='\e[0m'
readonly aCOLOUR=(
'\e[38;5;154m' # green | Lines, bullets and separators
'\e[1m' # Bold white | Main descriptions
'\e[90m' # Grey | Credits
'\e[91m' # Red | Update notifications Alert
'\e[33m' # Yellow | Emphasis
)
UNINSTALL_ALL_CONTAINER=false
REMOVE_IMAGES="none"
REMOVE_APP_DATA=false
###############################################################################
# Helpers #
###############################################################################
#######################################
# Custom printing function
# Globals:
# None
# Arguments:
# $1 0:OK 1:FAILED 2:INFO 3:NOTICE
# message
# Returns:
# None
#######################################
Show() {
# OK
if (($1 == 0)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# FAILED
elif (($1 == 1)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# INFO
elif (($1 == 2)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# NOTICE
elif (($1 == 3)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
fi
}
Warn() {
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
}
trap 'onCtrlC' INT
onCtrlC() {
echo -e "${COLOUR_RESET}"
exit 1
}
Detecting_CasaOS() {
if [[ ! -x "$(command -v ${CASA_EXEC})" ]]; then
Show 2 "CasaOS is not detected, exit the script."
exit 1
else
Show 0 "This script will delete the containers you no longer use, and the CasaOS configuration files."
fi
}
Unistall_Container() {
if [[ ${UNINSTALL_ALL_CONTAINER} == true && "$(${sudo_cmd} docker ps -aq)" != "" ]]; then
Show 2 "Start deleting containers."
${sudo_cmd} docker stop "$(${sudo_cmd} docker ps -aq)" || Show 1 "Failed to stop containers."
${sudo_cmd} docker rm "$(${sudo_cmd} docker ps -aq)" || Show 1 "Failed to delete all containers."
fi
}
Remove_Images() {
if [[ ${REMOVE_IMAGES} == "all" && "$(${sudo_cmd} docker images -q)" != "" ]]; then
Show 2 "Start deleting all images."
${sudo_cmd} docker rmi "$(${sudo_cmd} docker images -q)" || Show 1 "Failed to delete all images."
elif [[ ${REMOVE_IMAGES} == "unuse" && "$(${sudo_cmd} docker images -q)" != "" ]]; then
Show 2 "Start deleting unuse images."
${sudo_cmd} docker image prune -af || Show 1 "Failed to delete unuse images."
fi
}
Uninstall_Casaos() {
for SERVICE in "${CASA_SERVICES[@]}"; do
Show 2 "Stopping ${SERVICE}..."
systemctl stop "${SERVICE}" || Show 3 "Service ${SERVICE} does not exist."
systemctl disable "${SERVICE}" || Show 3 "Service ${SERVICE} does not exist."
done
# Remove Service file
if [[ -f ${CASA_SERVICE_USR} ]]; then
${sudo_cmd} rm -rf ${CASA_SERVICE_USR}
fi
if [[ -f ${CASA_SERVICE_LIB} ]]; then
${sudo_cmd} rm -rf ${CASA_SERVICE_LIB}
fi
if [[ -f ${CASA_SERVICE_ETC} ]]; then
${sudo_cmd} rm -rf ${CASA_SERVICE_ETC}
fi
# Old Casa Files
if [[ -d ${CASA_PATH} ]]; then
${sudo_cmd} rm -rf ${CASA_PATH} || Show 1 "Failed to delete CasaOS files."
fi
if [[ -f ${CASA_ADDON1} ]]; then
${sudo_cmd} rm -rf ${CASA_ADDON1}
fi
if [[ -f ${CASA_ADDON2} ]]; then
${sudo_cmd} rm -rf ${CASA_ADDON2}
fi
if [[ -f ${CASA_BIN} ]]; then
${sudo_cmd} rm -rf ${CASA_BIN} || Show 1 "Failed to delete CasaOS exec file."
fi
# New Casa Files
if [[ -f ${CASA_CONF_PATH_OLD} ]]; then
${sudo_cmd} rm -rf ${CASA_CONF_PATH_OLD}
fi
if [[ -f ${MANIFEST} ]]; then
${sudo_cmd} cat ${MANIFEST} | while read -r line; do
if [[ -f ${line} ]]; then
${sudo_cmd} rm -rf "${line}"
fi
done
fi
if [[ -d ${CASA_USER_FILES} ]]; then
${sudo_cmd} rm -rf ${CASA_USER_FILES}/[0-9]*
${sudo_cmd} rm -rf ${CASA_USER_FILES}/db
${sudo_cmd} rm -rf ${CASA_USER_FILES}/*.db
fi
${sudo_cmd} rm -rf ${CASA_USER_FILES}/www
${sudo_cmd} rm -rf ${CASA_USER_FILES}/migration
if [[ -d ${CASA_HELPER_PATH} ]]; then
${sudo_cmd} rm -rf ${CASA_HELPER_PATH}
fi
if [[ -d ${CASA_LOGS_PATH} ]]; then
${sudo_cmd} rm -rf ${CASA_LOGS_PATH}
fi
if [[ ${REMOVE_APP_DATA} = true ]]; then
$sudo_cmd rm -fr /DATA/AppData || Show 1 "Failed to delete AppData."
fi
if [[ -d ${CASA_CONF_PATH} ]]; then
${sudo_cmd} rm -rf ${CASA_CONF_PATH}
fi
if [[ -d ${CASA_RUN_PATH} ]]; then
${sudo_cmd} rm -rf ${CASA_RUN_PATH}
fi
if [[ -f ${CASA_UNINSTALL_PATH} ]]; then
${sudo_cmd} rm -rf ${CASA_UNINSTALL_PATH}
fi
}
# Check user
if [ "$(id -u)" -ne 0 ];then
Show 1 "Please execute with a root user, or use ${aCOLOUR[4]}sudo casaos-uninstall${COLOUR_RESET}."
exit 1
fi
#Inputs
Detecting_CasaOS
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete all containers? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
UNINSTALL_ALL_CONTAINER=true
break
;;
[nN][oO] | [nN])
UNINSTALL_ALL_CONTAINER=false
break
;;
*)
Warn " Invalid input..."
;;
esac
done
if [[ ${UNINSTALL_ALL_CONTAINER} == true ]]; then
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete all images? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_IMAGES="all"
break
;;
[nN][oO] | [nN])
REMOVE_IMAGES="none"
break
;;
*)
Warn " Invalid input..."
;;
esac
done
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete all AppData of CasaOS? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_APP_DATA=true
break
;;
[nN][oO] | [nN])
REMOVE_APP_DATA=false
break
;;
*)
Warn " Invalid input..."
;;
esac
done
else
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want to delete all images that are not used by the container? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_IMAGES="unuse"
break
;;
[nN][oO] | [nN])
REMOVE_IMAGES="none"
break
;;
*)
Warn " Invalid input..."
;;
esac
done
fi
Unistall_Container
Remove_Images
Uninstall_Casaos