Skip to content

Commit a77f9c8

Browse files
andystimeclaude
andcommitted
fix: unregister agent with sudo when config is in /root/.gpugo
Critical fix for agent unregistration during uninstall. Problem: When gpugo is installed with GPU_GO_TOKEN (agent mode), the install script runs `sudo ggo agent register` which saves config to /root/.gpugo/config/agent.yaml. During uninstall, the unregister command was running as normal user and couldn't read root's config, causing silent failure. Changes: 1. Detect if agent config exists in root directories - Check /root/.gpugo/config/agent.yaml - Check /root/.config/ggo/agent.yaml 2. Run unregister with sudo if agent mode detected - Properly construct command with sudo - Handle sudo not available gracefully 3. Improved error handling - Capture exit code correctly - Show clear warnings if unregistration fails - Inform user they may need manual cleanup on server 4. Better command execution - Avoid word splitting issues with proper quoting - Disable set -e for unregister command using || pattern - Show exit code in warning message This ensures agents are properly unregistered from the server before removing local config files. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f338cbc commit a77f9c8

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

scripts/uninstall.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,35 @@ unregister_from_server() {
260260
fi
261261

262262
info "Unregistering agent from server (using binary at ${binary_path})..."
263-
if "${binary_path}" agent unregister --force 2>/dev/null; then
263+
264+
# Check if agent config exists in root directory (agent mode)
265+
# If so, we need to run unregister with sudo
266+
local needs_sudo=false
267+
if [ -f "/root/.gpugo/config/agent.yaml" ] || [ -f "/root/.config/ggo/agent.yaml" ]; then
268+
needs_sudo=true
269+
info "Agent config found in root directory, using sudo for unregistration"
270+
fi
271+
272+
# Run unregister command
273+
local unregister_result=0
274+
if [ "${needs_sudo}" = "true" ]; then
275+
SUDO=$(get_sudo)
276+
if [ -n "${SUDO}" ]; then
277+
${SUDO} "${binary_path}" agent unregister --force 2>/dev/null || unregister_result=$?
278+
else
279+
warn "Sudo not available, attempting unregister without sudo (may fail)"
280+
"${binary_path}" agent unregister --force 2>/dev/null || unregister_result=$?
281+
fi
282+
else
283+
"${binary_path}" agent unregister --force 2>/dev/null || unregister_result=$?
284+
fi
285+
286+
if [ ${unregister_result} -eq 0 ]; then
264287
info "Agent unregistered from server"
265288
else
266-
warn "Server unregistration failed, local config will still be removed"
289+
warn "Server unregistration failed (exit code: ${unregister_result})"
290+
warn "Local config will still be removed"
291+
warn "You may need to manually remove the agent from the server dashboard"
267292
fi
268293
}
269294

0 commit comments

Comments
 (0)