-
Notifications
You must be signed in to change notification settings - Fork 8
/
uninstall
executable file
·86 lines (74 loc) · 2.52 KB
/
uninstall
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
#!/bin/bash
################################################################
# Colors #
################################################################
# Reset
Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
#Yellow='\033[0;33m' # Yellow
#Purple='\033[0;35m' # Purple
White='\033[0;37m' # White
# Background
On_Black='\033[40m' # Black
OkBullet="${Green}${On_Black}:: ${White}${On_Black}"
#WarnBullet="${Yellow}${On_Black}:: ${White}${On_Black}"
ErrBullet="${Red}${On_Black}:: ${White}${On_Black}"
Ok="${Green}${On_Black} ok.${Off}"
Fail="${Red}${On_Black} failed!${Off}"
#Nok="${Yellow}${On_Black} nok.${Off}"
################################################################
# Vars #
################################################################
XMRSH_DIR="/opt/xmr.sh"
XMRSH_LOG_FILE="/tmp/xmr.sh-$(date +%Y%m%d-%H%M%S).log"
################################################################
# Functions #
################################################################
check_root() {
echo -ne "${OkBullet}Checking root... ${Off}"
if [[ $EUID -ne 0 ]]; then
echo -e "${Fail}"
echo -e "${ErrBullet}You need to run this script as root (UID=0).${Off}"
exit 1
fi
echo -e "${Ok}"
}
check_return() {
if [ "$1" -ne 0 ]; then
echo -e "${Fail}"
echo -e "${ErrBullet}Installation failed. Check the logs in ${XMRSH_LOG_FILE}${Off}"
exit "$1"
fi
}
uninstall() {
pushd $XMRSH_DIR >>"${XMRSH_LOG_FILE}" 2>&1 || check_return $?
echo -e "${OkBullet}Uninstalling xmr.sh..."
if [ -f docker-compose.yml ]; then
docker-compose down >>"${XMRSH_LOG_FILE}" 2>&1
fi
check_return $?
while true; do
read -r -e -p " Do you want to keep the data directory with the blockchain and other data files? [y/n]: " yn
case $yn in
[Yy]*)
find . -type f -not -name 'data' -print0 | xargs -0 -I {} rm {}
check_return $?
popd >>"${XMRSH_LOG_FILE}" 2>&1 || check_return $?
break
;;
[Nn]*)
popd >>"${XMRSH_LOG_FILE}" 2>&1 || check_return $?
rm -rf "${XMRSH_DIR}"
check_return $?
break
;;
*) echo " Please answer yes or no." ;;
esac
done
echo -e "${OkBullet}Uninstall complete."
}
check_root
uninstall
exit 0