11#! /bin/sh
22# GPU Go (ggo) Uninstallation Script
3- # Usage: curl -sfL https://cdn.tensor-fusion.ai/archive/gpugo/uninstall.sh | sh
3+ #
4+ # When called from `ggo uninstall`, this script only handles service and binary
5+ # removal. Agent unregistration and config directory cleanup are done by the
6+ # Go code before/after this script runs.
7+ #
8+ # When called standalone (curl | sh), it still works but won't unregister the
9+ # agent from the server — users should run `ggo uninstall` instead.
410#
511# Environment variables:
612# - GGO_INSTALL_DIR: Installation directory (default: /usr/local/bin)
7- #
8- # This script will:
9- # - Stop and remove the systemd service (Linux)
10- # - Remove the ggo binary
11- # - Clean up config directories
1213
1314set -e
1415
@@ -57,22 +58,21 @@ remove_systemd_service() {
5758 if ! command -v systemctl > /dev/null 2>&1 ; then
5859 return 0
5960 fi
60-
61+
6162 if [ ! -d /run/systemd/system ]; then
6263 return 0
6364 fi
64-
65+
6566 SERVICE_FILE=" /etc/systemd/system/${SYSTEMD_SERVICE_NAME} .service"
66-
67+
6768 if [ ! -f " ${SERVICE_FILE} " ]; then
6869 info " Systemd service not found, skipping..."
6970 return 0
7071 fi
71-
72+
7273 info " Stopping systemd service..."
7374 SUDO=$( get_sudo)
7475
75- # Stop and disable service, remove file, reload daemon (using cached sudo credentials)
7676 ${SUDO} systemctl stop " ${SYSTEMD_SERVICE_NAME} " 2> /dev/null || true
7777
7878 info " Disabling systemd service..."
@@ -83,24 +83,22 @@ remove_systemd_service() {
8383
8484 info " Reloading systemd daemon..."
8585 ${SUDO} systemctl daemon-reload
86-
86+
8787 info " Systemd service removed successfully!"
8888}
8989
9090# --- Stop launchd service (macOS) ---
9191remove_launchd_service () {
9292 PLIST_FILE=" $HOME /Library/LaunchAgents/ai.tensor-fusion.ggo-agent.plist"
9393 PLIST_FILE_SYSTEM=" /Library/LaunchDaemons/ai.tensor-fusion.ggo-agent.plist"
94-
95- # Check user launch agent
94+
9695 if [ -f " ${PLIST_FILE} " ]; then
9796 info " Stopping launchd user agent..."
9897 launchctl unload " ${PLIST_FILE} " 2> /dev/null || true
9998 rm -f " ${PLIST_FILE} "
10099 info " User launch agent removed!"
101100 fi
102-
103- # Check system launch daemon
101+
104102 if [ -f " ${PLIST_FILE_SYSTEM} " ]; then
105103 info " Stopping launchd system daemon..."
106104 SUDO=$( get_sudo)
@@ -113,11 +111,10 @@ remove_launchd_service() {
113111# --- Remove binary ---
114112remove_binary () {
115113 BINARY_PATH=" ${INSTALL_DIR} /${BINARY_NAME} "
116-
114+
117115 if [ ! -f " ${BINARY_PATH} " ]; then
118116 info " Binary not found at ${BINARY_PATH} , checking common locations..."
119-
120- # Check common locations
117+
121118 for dir in /usr/local/bin /usr/bin /opt/bin " $HOME /.local/bin" " $HOME /bin" ; do
122119 if [ -f " ${dir} /${BINARY_NAME} " ]; then
123120 BINARY_PATH=" ${dir} /${BINARY_NAME} "
@@ -126,17 +123,16 @@ remove_binary() {
126123 fi
127124 done
128125 fi
129-
126+
130127 if [ ! -f " ${BINARY_PATH} " ]; then
131128 warn " ggo binary not found"
132129 return 0
133130 fi
134-
131+
135132 info " Removing binary at ${BINARY_PATH} ..."
136133
137134 SUDO=$( get_sudo)
138135
139- # Check if we need sudo
140136 if [ -w " $( dirname " ${BINARY_PATH} " ) " ]; then
141137 if rm -f " ${BINARY_PATH} " 2> /dev/null; then
142138 info " Binary removed!"
@@ -155,175 +151,14 @@ remove_binary() {
155151 fi
156152}
157153
158- # --- Remove config directories ---
159- remove_config () {
160- info " Removing configuration directories..."
161-
162- # User config
163- CONFIG_DIRS=" $HOME /.config/ggo $HOME /.ggo $HOME /.gpugo"
164-
165- for dir in ${CONFIG_DIRS} ; do
166- if [ -d " ${dir} " ]; then
167- info " Removing ${dir} ..."
168- rm -rf " ${dir} "
169- fi
170- done
171-
172- # System config (Linux)
173- SUDO=$( get_sudo)
174- SYSTEM_DIRS=" /var/lib/ggo /etc/ggo"
175- local system_cleanup_failed=false
176-
177- for dir in ${SYSTEM_DIRS} ; do
178- if [ -d " ${dir} " ]; then
179- info " Removing ${dir} ..."
180- if ${SUDO} rm -rf " ${dir} " 2> /dev/null; then
181- info " Successfully removed ${dir} "
182- else
183- warn " Failed to remove ${dir} (permission denied or sudo not available)"
184- system_cleanup_failed=true
185- fi
186- fi
187- done
188-
189- # Root config (if running as root or with sudo)
190- local root_cleanup_failed=false
191- if [ " $( id -u) " -eq 0 ] || [ -n " $( get_sudo) " ]; then
192- if [ -d " /root/.config/ggo" ]; then
193- if ${SUDO} rm -rf " /root/.config/ggo" 2> /dev/null; then
194- info " Removed /root/.config/ggo"
195- else
196- warn " Failed to remove /root/.config/ggo (permission denied)"
197- root_cleanup_failed=true
198- fi
199- fi
200- if [ -d " /root/.ggo" ]; then
201- if ${SUDO} rm -rf " /root/.ggo" 2> /dev/null; then
202- info " Removed /root/.ggo"
203- else
204- warn " Failed to remove /root/.ggo (permission denied)"
205- root_cleanup_failed=true
206- fi
207- fi
208- if [ -d " /root/.gpugo" ]; then
209- if ${SUDO} rm -rf " /root/.gpugo" 2> /dev/null; then
210- info " Removed /root/.gpugo"
211- else
212- warn " Failed to remove /root/.gpugo (permission denied)"
213- root_cleanup_failed=true
214- fi
215- fi
216- else
217- # Check if root directories exist but we can't remove them
218- if [ -d " /root/.config/ggo" ] || [ -d " /root/.ggo" ] || [ -d " /root/.gpugo" ]; then
219- warn " Root configuration directories exist but sudo is not available"
220- root_cleanup_failed=true
221- fi
222- fi
223-
224- info " Configuration directories removed!"
225-
226- # Warn about manual cleanup if root cleanup failed
227- if [ " ${root_cleanup_failed} " = " true" ] || [ " ${system_cleanup_failed} " = " true" ]; then
228- echo " "
229- warn " ==============================================="
230- warn " MANUAL CLEANUP REQUIRED"
231- warn " ==============================================="
232- warn " Some configuration directories could not be removed automatically."
233- warn " Please run the following commands with appropriate permissions:"
234- warn " "
235- if [ " ${system_cleanup_failed} " = " true" ]; then
236- for dir in ${SYSTEM_DIRS} ; do
237- if [ -d " ${dir} " ]; then
238- warn " sudo rm -rf ${dir} "
239- fi
240- done
241- fi
242- if [ -d " /root/.config/ggo" ]; then
243- warn " sudo rm -rf /root/.config/ggo"
244- fi
245- if [ -d " /root/.ggo" ]; then
246- warn " sudo rm -rf /root/.ggo"
247- fi
248- if [ -d " /root/.gpugo" ]; then
249- warn " sudo rm -rf /root/.gpugo"
250- fi
251- warn " ==============================================="
252- echo " "
253- fi
254- }
255-
256- # --- Unregister from server ---
257- unregister_from_server () {
258- # Search for ggo binary in multiple locations
259- local binary_path=" "
260- local search_paths=" ${GGO_INSTALL_DIR:-/ usr/ local/ bin} /${BINARY_NAME} /usr/local/bin/${BINARY_NAME} /usr/bin/${BINARY_NAME} /opt/bin/${BINARY_NAME} ${HOME} /.local/bin/${BINARY_NAME} ${HOME} /bin/${BINARY_NAME} "
261-
262- for path in ${search_paths} ; do
263- if [ -f " ${path} " ] && [ -x " ${path} " ]; then
264- binary_path=" ${path} "
265- break
266- fi
267- done
268-
269- if [ -z " ${binary_path} " ]; then
270- warn " ggo binary not found in common locations, skipping server unregistration"
271- warn " Searched: ${search_paths} "
272- return 0
273- fi
274-
275- info " Unregistering agent from server (using binary at ${binary_path} )..."
276-
277- # Check if agent config exists in root directory (agent mode)
278- # If so, we need to run unregister with sudo
279- local needs_sudo=false
280- SUDO=$( get_sudo)
281-
282- # Try to check for root config files (need sudo to access root's home)
283- if [ -n " ${SUDO} " ]; then
284- if ${SUDO} test -f " /root/.gpugo/config/config.json" || \
285- ${SUDO} test -f " /root/.gpugo/config/agent.yaml" || \
286- ${SUDO} test -f " /root/.config/ggo/agent.yaml" ; then
287- needs_sudo=true
288- info " Agent config found in root directory, using sudo for unregistration"
289- fi
290- fi
291-
292- # Run unregister command (don't suppress output so user can see what happened)
293- # When using sudo, explicitly specify root's config dir since the command
294- # defaults to the calling user's home directory, not root's
295- local unregister_result=0
296- if [ " ${needs_sudo} " = " true" ]; then
297- SUDO=$( get_sudo)
298- if [ -n " ${SUDO} " ]; then
299- ${SUDO} " ${binary_path} " agent unregister --config-dir /root/.gpugo/config --force || unregister_result=$?
300- else
301- warn " Sudo not available, attempting unregister without sudo (may fail)"
302- " ${binary_path} " agent unregister --force || unregister_result=$?
303- fi
304- else
305- " ${binary_path} " agent unregister --force || unregister_result=$?
306- fi
307-
308- # Check result - exit code 0 means command succeeded (either unregistered or was not registered)
309- if [ ${unregister_result} -eq 0 ]; then
310- # Success - either unregistered or wasn't registered, both are fine
311- :
312- else
313- warn " Server unregistration failed (exit code: ${unregister_result} )"
314- warn " Local config will still be removed"
315- warn " You may need to manually remove the agent from the server dashboard"
316- fi
317- }
318-
319154# --- Main uninstallation ---
320155main () {
321156 OS=$( detect_os)
322-
157+
323158 if [ " ${OS} " = " windows" ]; then
324159 fatal " Windows uninstallation is not supported by this script. Please use uninstall.ps1 or uninstall.bat instead."
325160 fi
326-
161+
327162 echo " "
328163 echo " =========================================="
329164 echo " GPU Go (ggo) Uninstaller"
@@ -338,10 +173,7 @@ main() {
338173 ${SUDO} -v 2> /dev/null || true
339174 fi
340175
341- # Unregister from server (before removing binary and config)
342- unregister_from_server
343-
344- # Remove services based on OS (graceful stop)
176+ # Stop and remove service
345177 if [ " ${OS} " = " linux" ]; then
346178 remove_systemd_service
347179 elif [ " ${OS} " = " darwin" ]; then
@@ -350,10 +182,7 @@ main() {
350182
351183 # Remove binary
352184 remove_binary
353-
354- # Remove config
355- remove_config
356-
185+
357186 echo " "
358187 echo " =========================================="
359188 echo " Uninstallation Complete!"
0 commit comments