-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathdappnode_uninstall.sh
More file actions
executable file
·149 lines (129 loc) · 4.11 KB
/
Copy pathdappnode_uninstall.sh
File metadata and controls
executable file
·149 lines (129 loc) · 4.11 KB
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
#!/usr/bin/env bash
# This uninstaller is written for bash. It's safe to *run it from zsh* (it will execute via bash
# thanks to the shebang), but users sometimes invoke it as `zsh ./script.sh` or `source ./script.sh`.
# - If sourced, bail out (sourcing would pollute the current shell and can break it).
# - If invoked by a non-bash shell, re-exec with bash before hitting bash-specific builtins.
if (return 0 2>/dev/null); then
echo "This script must be executed, not sourced. Run: bash $0"
return 1
fi
if [ -z "${BASH_VERSION:-}" ]; then
exec /usr/bin/env bash "$0" "$@"
fi
##################
# OS DETECTION #
##################
OS_TYPE="$(uname -s)"
IS_MACOS=false
IS_LINUX=false
if [[ "$OS_TYPE" == "Darwin" ]]; then
IS_MACOS=true
elif [[ "$OS_TYPE" == "Linux" ]]; then
IS_LINUX=true
else
echo "Unsupported operating system: $OS_TYPE"
exit 1
fi
#############
# VARIABLES #
#############
# Dirs — macOS uses $HOME/dappnode, Linux uses /usr/src/dappnode (mirrors install script)
if $IS_MACOS; then
DAPPNODE_DIR="$HOME/dappnode"
else
DAPPNODE_DIR="/usr/src/dappnode"
fi
DAPPNODE_CORE_DIR="${DAPPNODE_DIR}/DNCORE"
PROFILE_FILE="${DAPPNODE_CORE_DIR}/.dappnode_profile"
input=$1 # Allow to call script with argument (must be Y/N)
##############################
# Cross-platform Helpers #
##############################
# Cross-platform in-place sed (macOS requires '' after -i)
sed_inplace() {
if $IS_MACOS; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
[ -f "$PROFILE_FILE" ] || {
echo "Error: DAppNode profile does not exist at ${PROFILE_FILE}."
exit 1
}
uninstall() {
echo "Uninstalling DAppNode"
# shellcheck disable=SC1090
source "${PROFILE_FILE}" &>/dev/null
DAPPNODE_CONTAINERS="$(docker ps -a --format '{{.Names}}' | grep DAppNode)"
echo "Removing DAppNode containers: "
echo "${DAPPNODE_CONTAINERS}"
for container in $DAPPNODE_CONTAINERS; do
# Stop DAppNode container
docker stop "$container" &>/dev/null
# Remove DAppNode container
docker rm "$container" &>/dev/null
done
DAPPNODE_IMAGES="$(docker image ls -a | grep "dappnode")"
echo "Removing DAppNode images: "
echo "${DAPPNODE_IMAGES}"
for image in $DAPPNODE_IMAGES; do
# Remove DAppNode images
docker image rm "$image" &>/dev/null
done
DAPPNODE_VOLUMES="$(docker volume ls | grep "dappnode\|dncore")"
echo "Removing DAppNode volumes: "
echo "${DAPPNODE_VOLUMES}"
for volume in $DAPPNODE_VOLUMES; do
# Remove DAppNode volumes
docker volume rm "$volume" &>/dev/null
done
# Remove dncore_network
echo "Removing docker dncore_network"
docker network remove dncore_network || echo "dncore_network already removed"
# Remove DAppNode directory
echo "Removing DAppNode directory: ${DAPPNODE_DIR}"
rm -rf "${DAPPNODE_DIR}"
# Remove profile file references from shell config files
local user_home
local shell_configs
if $IS_MACOS; then
user_home="$HOME"
# macOS defaults to zsh — matches install script
shell_configs=(".zshrc" ".zprofile")
else
local user_name
user_name=$(grep 1000 /etc/passwd | cut -f 1 -d:)
if [ -n "$user_name" ]; then
user_home="/home/$user_name"
else
user_home="/root"
fi
shell_configs=(".profile" ".bashrc")
fi
# Remove Dappnode profile references from shell config files
for config_file in "${shell_configs[@]}"; do
local config_path="${user_home}/${config_file}"
if [ -f "$config_path" ]; then
sed_inplace '/######## DAPPNODE PROFILE ########/d' "$config_path"
sed_inplace '/.*dappnode_profile/d' "$config_path"
fi
done
echo "DAppNode uninstalled!"
}
if [ $# -eq 0 ]; then
read -r -p "WARNING: This script will uninstall and delete all DAppNode
containers and volumes. Are You Sure? [Y/n] " input <&2
fi
case $input in
[yY][eE][sS] | [yY])
uninstall
;;
[nN][oO] | [nN])
echo "Ok."
;;
*)
echo "Invalid input. Exiting..."
exit 1
;;
esac