11#! /usr/bin/env bash
2- DAPPNODE_DIR=" /usr/src/dappnode"
2+
3+ # This uninstaller is written for bash. It's safe to *run it from zsh* (it will execute via bash
4+ # thanks to the shebang), but users sometimes invoke it as `zsh ./script.sh` or `source ./script.sh`.
5+ # - If sourced, bail out (sourcing would pollute the current shell and can break it).
6+ # - If invoked by a non-bash shell, re-exec with bash before hitting bash-specific builtins.
7+ if (return 0 2> /dev/null); then
8+ echo " This script must be executed, not sourced. Run: bash $0 "
9+ return 1
10+ fi
11+
12+ if [ -z " ${BASH_VERSION:- } " ]; then
13+ exec /usr/bin/env bash " $0 " " $@ "
14+ fi
15+
16+ # #################
17+ # OS DETECTION #
18+ # #################
19+ OS_TYPE=" $( uname -s) "
20+ IS_MACOS=false
21+ IS_LINUX=false
22+ if [[ " $OS_TYPE " == " Darwin" ]]; then
23+ IS_MACOS=true
24+ elif [[ " $OS_TYPE " == " Linux" ]]; then
25+ IS_LINUX=true
26+ else
27+ echo " Unsupported operating system: $OS_TYPE "
28+ exit 1
29+ fi
30+
31+ # ############
32+ # VARIABLES #
33+ # ############
34+ # Dirs — macOS uses $HOME/dappnode, Linux uses /usr/src/dappnode (mirrors install script)
35+ if $IS_MACOS ; then
36+ DAPPNODE_DIR=" $HOME /dappnode"
37+ else
38+ DAPPNODE_DIR=" /usr/src/dappnode"
39+ fi
340DAPPNODE_CORE_DIR=" ${DAPPNODE_DIR} /DNCORE"
441PROFILE_FILE=" ${DAPPNODE_CORE_DIR} /.dappnode_profile"
542input=$1 # Allow to call script with argument (must be Y/N)
643
7- [ -f $PROFILE_FILE ] || (
8- echo " Error: DAppNode profile does not exist."
44+ # #############################
45+ # Cross-platform Helpers #
46+ # #############################
47+
48+ # Cross-platform in-place sed (macOS requires '' after -i)
49+ sed_inplace () {
50+ if $IS_MACOS ; then
51+ sed -i ' ' " $@ "
52+ else
53+ sed -i " $@ "
54+ fi
55+ }
56+
57+ [ -f " $PROFILE_FILE " ] || {
58+ echo " Error: DAppNode profile does not exist at ${PROFILE_FILE} ."
959 exit 1
10- )
60+ }
1161
1262uninstall () {
13- echo -e " \e[32mUninstalling DAppNode\e[0m "
63+ echo " Uninstalling DAppNode"
1464 # shellcheck disable=SC1090
1565 source " ${PROFILE_FILE} " & > /dev/null
1666
1767 DAPPNODE_CONTAINERS=" $( docker ps -a --format ' {{.Names}}' | grep DAppNode) "
18- echo -e " \e[32mRemoving DAppNode containers: \e[0m\n${DAPPNODE_CONTAINERS} "
68+ echo " Removing DAppNode containers: "
69+ echo " ${DAPPNODE_CONTAINERS} "
1970 for container in $DAPPNODE_CONTAINERS ; do
2071 # Stop DAppNode container
2172 docker stop " $container " & > /dev/null
@@ -24,40 +75,58 @@ uninstall() {
2475 done
2576
2677 DAPPNODE_IMAGES=" $( docker image ls -a | grep " dappnode" ) "
27- echo -e " \e[32mRemoving DAppNode images: \e[0m\n${DAPPNODE_IMAGES} "
78+ echo " Removing DAppNode images: "
79+ echo " ${DAPPNODE_IMAGES} "
2880 for image in $DAPPNODE_IMAGES ; do
2981 # Remove DAppNode images
3082 docker image rm " $image " & > /dev/null
3183 done
3284
3385 DAPPNODE_VOLUMES=" $( docker volume ls | grep " dappnode\|dncore" ) "
34- echo -e " \e[32mRemoving DAppNode volumes: \e[0m\n${DAPPNODE_VOLUMES} "
86+ echo " Removing DAppNode volumes: "
87+ echo " ${DAPPNODE_VOLUMES} "
3588 for volume in $DAPPNODE_VOLUMES ; do
3689 # Remove DAppNode volumes
3790 docker volume rm " $volume " & > /dev/null
3891 done
3992
4093 # Remove dncore_network
41- echo -e " \e[32mRemoving docker dncore_network\e[0m "
94+ echo " Removing docker dncore_network"
4295 docker network remove dncore_network || echo " dncore_network already removed"
4396
44- # Remove dir
45- echo -e " \e[32mRemoving DAppNode directory\e[0m "
46- rm -rf /usr/src/dappnode
97+ # Remove DAppNode directory
98+ echo " Removing DAppNode directory: ${DAPPNODE_DIR} "
99+ rm -rf " ${DAPPNODE_DIR} "
47100
48101 # Remove profile file references from shell config files
49- USER=$( grep 1000 /etc/passwd | cut -f 1 -d:)
50- [ -n " $USER " ] && USER_HOME=/home/$USER || USER_HOME=/root
51-
52- for config_file in .profile .bashrc; do
53- CONFIG_PATH=" $USER_HOME /$config_file "
54- if [ -f " $CONFIG_PATH " ]; then
55- sed -i ' /######## DAPPNODE PROFILE ########/d' " $CONFIG_PATH "
56- sed -i ' /.*dappnode_profile/d' " $CONFIG_PATH "
102+ local user_home
103+ local shell_configs
104+
105+ if $IS_MACOS ; then
106+ user_home=" $HOME "
107+ # macOS defaults to zsh — matches install script
108+ shell_configs=(" .zshrc" " .zprofile" )
109+ else
110+ local user_name
111+ user_name=$( grep 1000 /etc/passwd | cut -f 1 -d:)
112+ if [ -n " $user_name " ]; then
113+ user_home=" /home/$user_name "
114+ else
115+ user_home=" /root"
116+ fi
117+ shell_configs=(" .profile" " .bashrc" )
118+ fi
119+
120+ # Remove Dappnode profile references from shell config files
121+ for config_file in " ${shell_configs[@]} " ; do
122+ local config_path=" ${user_home} /${config_file} "
123+ if [ -f " $config_path " ]; then
124+ sed_inplace ' /######## DAPPNODE PROFILE ########/d' " $config_path "
125+ sed_inplace ' /.*dappnode_profile/d' " $config_path "
57126 fi
58127 done
59128
60- echo -e " \e[32mDAppNode uninstalled!\e[0m "
129+ echo " DAppNode uninstalled!"
61130}
62131
63132if [ $# -eq 0 ]; then
0 commit comments