11#! /usr/bin/env bash
2- DAPPNODE_DIR=" /usr/src/dappnode"
2+
3+ # Guard against sourcing
4+ if (return 0 2> /dev/null); then
5+ echo " This script must be executed, not sourced. Run: bash $0 "
6+ return 1
7+ fi
8+
9+ # Re-exec under bash if invoked by another shell (e.g. zsh)
10+ if [ -z " ${BASH_VERSION:- } " ]; then
11+ exec /usr/bin/env bash " $0 " " $@ "
12+ fi
13+
14+ # #################
15+ # OS DETECTION #
16+ # #################
17+ OS_TYPE=" $( uname -s) "
18+ IS_MACOS=false
19+ IS_LINUX=false
20+ if [[ " $OS_TYPE " == " Darwin" ]]; then
21+ IS_MACOS=true
22+ elif [[ " $OS_TYPE " == " Linux" ]]; then
23+ IS_LINUX=true
24+ else
25+ echo " Unsupported operating system: $OS_TYPE "
26+ exit 1
27+ fi
28+
29+ # ############
30+ # VARIABLES #
31+ # ############
32+ # Dirs — macOS uses $HOME/dappnode, Linux uses /usr/src/dappnode (mirrors install script)
33+ if $IS_MACOS ; then
34+ DAPPNODE_DIR=" $HOME /dappnode"
35+ else
36+ DAPPNODE_DIR=" /usr/src/dappnode"
37+ fi
338DAPPNODE_CORE_DIR=" ${DAPPNODE_DIR} /DNCORE"
439PROFILE_FILE=" ${DAPPNODE_CORE_DIR} /.dappnode_profile"
540input=$1 # Allow to call script with argument (must be Y/N)
641
7- [ -f $PROFILE_FILE ] || (
8- echo " Error: DAppNode profile does not exist."
42+ # #############################
43+ # Cross-platform Helpers #
44+ # #############################
45+
46+ # Color output helper (no ANSI on macOS to avoid \e issues)
47+ color_echo () {
48+ local color=" $1 " ; shift
49+ if $IS_LINUX ; then
50+ case " $color " in
51+ green) code=" \e[32m" ;;
52+ yellow) code=" \e[33m" ;;
53+ * ) code=" " ;;
54+ esac
55+ echo -e " ${code} $* \e[0m"
56+ else
57+ echo " $* "
58+ fi
59+ }
60+
61+ # Cross-platform in-place sed (macOS requires '' after -i)
62+ sed_inplace () {
63+ if $IS_MACOS ; then
64+ sed -i ' ' " $@ "
65+ else
66+ sed -i " $@ "
67+ fi
68+ }
69+
70+ [ -f " $PROFILE_FILE " ] || {
71+ echo " Error: DAppNode profile does not exist at ${PROFILE_FILE} ."
972 exit 1
10- )
73+ }
1174
1275uninstall () {
13- echo -e " \e[32mUninstalling DAppNode\e[0m "
76+ color_echo green " Uninstalling DAppNode"
1477 # shellcheck disable=SC1090
1578 source " ${PROFILE_FILE} " & > /dev/null
1679
1780 DAPPNODE_CONTAINERS=" $( docker ps -a --format ' {{.Names}}' | grep DAppNode) "
18- echo -e " \e[32mRemoving DAppNode containers: \e[0m\n${DAPPNODE_CONTAINERS} "
81+ color_echo green " Removing DAppNode containers: "
82+ echo " ${DAPPNODE_CONTAINERS} "
1983 for container in $DAPPNODE_CONTAINERS ; do
2084 # Stop DAppNode container
2185 docker stop " $container " & > /dev/null
@@ -24,40 +88,58 @@ uninstall() {
2488 done
2589
2690 DAPPNODE_IMAGES=" $( docker image ls -a | grep " dappnode" ) "
27- echo -e " \e[32mRemoving DAppNode images: \e[0m\n${DAPPNODE_IMAGES} "
91+ color_echo green " Removing DAppNode images: "
92+ echo " ${DAPPNODE_IMAGES} "
2893 for image in $DAPPNODE_IMAGES ; do
2994 # Remove DAppNode images
3095 docker image rm " $image " & > /dev/null
3196 done
3297
3398 DAPPNODE_VOLUMES=" $( docker volume ls | grep " dappnode\|dncore" ) "
34- echo -e " \e[32mRemoving DAppNode volumes: \e[0m\n${DAPPNODE_VOLUMES} "
99+ color_echo green " Removing DAppNode volumes: "
100+ echo " ${DAPPNODE_VOLUMES} "
35101 for volume in $DAPPNODE_VOLUMES ; do
36102 # Remove DAppNode volumes
37103 docker volume rm " $volume " & > /dev/null
38104 done
39105
40106 # Remove dncore_network
41- echo -e " \e[32mRemoving docker dncore_network\e[0m "
107+ color_echo green " Removing docker dncore_network"
42108 docker network remove dncore_network || echo " dncore_network already removed"
43109
44- # Remove dir
45- echo -e " \e[32mRemoving DAppNode directory\e[0m "
46- rm -rf /usr/src/dappnode
110+ # Remove DAppNode directory
111+ color_echo green " Removing DAppNode directory: ${DAPPNODE_DIR} "
112+ rm -rf " ${DAPPNODE_DIR} "
47113
48114 # 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 "
115+ local user_home
116+ local shell_configs
117+
118+ if $IS_MACOS ; then
119+ user_home=" $HOME "
120+ # macOS defaults to zsh — matches install script
121+ shell_configs=(" .zshrc" " .zprofile" )
122+ else
123+ local user_name
124+ user_name=$( grep 1000 /etc/passwd | cut -f 1 -d:)
125+ if [ -n " $user_name " ]; then
126+ user_home=" /home/$user_name "
127+ else
128+ user_home=" /root"
129+ fi
130+ shell_configs=(" .profile" " .bashrc" )
131+ fi
132+
133+ # Remove Dappnode profile references from shell config files
134+ for config_file in " ${shell_configs[@]} " ; do
135+ local config_path=" ${user_home} /${config_file} "
136+ if [ -f " $config_path " ]; then
137+ sed_inplace ' /######## DAPPNODE PROFILE ########/d' " $config_path "
138+ sed_inplace ' /.*dappnode_profile/d' " $config_path "
57139 fi
58140 done
59141
60- echo -e " \e[32mDAppNode uninstalled!\e[0m "
142+ color_echo green " DAppNode uninstalled!"
61143}
62144
63145if [ $# -eq 0 ]; then
0 commit comments