Skip to content

Commit 29b3b67

Browse files
authored
Merge pull request #69 from GaiaNet-AI/feat-uninstall-script
2 parents 7a1ceb4 + 6c3236c commit 29b3b67

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

uninstall.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# path to the default gaianet base directory. It could be changed by the --base option
6+
gaianet_base_dir="$HOME/gaianet"
7+
8+
# print in red color
9+
RED=$'\e[0;31m'
10+
# print in green color
11+
GREEN=$'\e[0;32m'
12+
# print in yellow color
13+
YELLOW=$'\e[0;33m'
14+
# No Color
15+
NC=$'\e[0m'
16+
17+
info() {
18+
printf "${GREEN}$1${NC}\n\n"
19+
}
20+
21+
error() {
22+
printf "${RED}$1${NC}\n\n"
23+
}
24+
25+
warning() {
26+
printf "${YELLOW}$1${NC}\n\n"
27+
}
28+
29+
function print_usage {
30+
printf "Usage:\n"
31+
printf " ./install.sh [Options]\n\n"
32+
printf "Options:\n"
33+
printf " --base <Path>: specify a path to the gaianet base directory\n"
34+
printf " --help: Print usage\n"
35+
}
36+
37+
while [[ $# -gt 0 ]]; do
38+
key="$1"
39+
case $key in
40+
--base)
41+
gaianet_base_dir="$2"
42+
shift
43+
shift
44+
;;
45+
--help)
46+
print_usage
47+
exit 0
48+
;;
49+
*)
50+
echo "Unknown argument: $key"
51+
print_usage
52+
exit 1
53+
;;
54+
esac
55+
done
56+
57+
58+
# 1. Stop WasmEdge, Qdrant and frpc
59+
if command -v gaianet > /dev/null 2>&1; then
60+
gaianet stop
61+
printf "\n"
62+
fi
63+
64+
65+
# 2. Remove the gaianet base directory
66+
if [ -d "$gaianet_base_dir" ]; then
67+
printf "[+] Removing the gaianet base directory ...\n"
68+
rm -rf $gaianet_base_dir
69+
printf "\n"
70+
fi
71+
72+
if [ -f "/usr/local/bin/gaianet" ]; then
73+
printf "[+] Removing gaianet binary from /usr/local/bin ...\n"
74+
sudo rm "/usr/local/bin/gaianet"
75+
printf "\n"
76+
fi
77+
78+
79+
# 3. Remove WasmEdge
80+
if command -v wasmedge > /dev/null 2>&1; then
81+
printf "[+] Uninstall WasmEdge ...\n"
82+
bash <(curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/uninstall.sh) -q
83+
printf "\n"
84+
fi
85+
86+
87+
# 4. Clean up the environment variables
88+
printf "[+] Remove the path from the shell rc file ...\n"
89+
90+
shell="${SHELL#${SHELL%/*}/}"
91+
shell_rc=".""$shell""rc"
92+
93+
info "shell: $shell"
94+
info "shell_rc: $HOME/$shell_rc"
95+
96+
if [[ -f "${HOME}/${shell_rc}" ]]; then
97+
line_num=$(grep -n "export PATH=\"$gaianet_base_dir/bin:\$PATH\"" "$HOME/${shell_rc}" | cut -d : -f 1)
98+
99+
[ "$line_num" != "" ] && sed -i.gaianet_backup -e "${line_num}"'d' "${HOME}/${shell_rc}"
100+
fi
101+
102+
if [[ -f "${HOME}/.zprofile" ]]; then
103+
line_num="$(grep -n "export PATH=\"$gaianet_base_dir/bin:\$PATH\"" "${HOME}/.zprofile" | cut -d : -f 1)"
104+
105+
[ "$line_num" != "" ] && sed -i.gaianet_backup -e "${line_num}"'d' "${HOME}/.zprofile"
106+
fi
107+
108+
if [[ -f "${HOME}/.bash_profile" ]]; then
109+
line_num="$(grep -n "export PATH=\"$gaianet_base_dir/bin:\$PATH\"" "${HOME}/.bash_profile" | cut -d : -f 1)"
110+
111+
[ "$line_num" != "" ] && sed -i.gaianet_backup -e "${line_num}"'d' "${HOME}/.bash_profile"
112+
fi
113+
114+
115+
info ">>> Next, run the command 'source $HOME/$shell_rc' to make the uninstallation effective in the current shell."
116+
117+

0 commit comments

Comments
 (0)