forked from NVIDIA/NemoClaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·464 lines (394 loc) · 11.8 KB
/
uninstall.sh
File metadata and controls
executable file
·464 lines (394 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
#!/usr/bin/env bash
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# NemoClaw uninstaller.
# Removes the host-side resources created by the installer/setup flow:
# - NemoClaw helper services
# - All OpenShell sandboxes plus the NemoClaw gateway/providers
# - NemoClaw/OpenShell/OpenClaw Docker images built or pulled for the sandbox flow
# - ~/.nemoclaw plus ~/.config/{openshell,nemoclaw} state
# - Global nemoclaw npm install/link
# - OpenShell binary if it was installed to the standard installer path
#
# Preserves shared system tooling such as Docker, Node.js, npm, and Ollama by default.
set -euo pipefail
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${GREEN}[uninstall]${NC} $1"; }
warn() { echo -e "${YELLOW}[uninstall]${NC} $1"; }
fail() { echo -e "${RED}[uninstall]${NC} $1"; exit 1; }
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
NEMOCLAW_STATE_DIR="${HOME}/.nemoclaw"
OPENSHELL_CONFIG_DIR="${HOME}/.config/openshell"
NEMOCLAW_CONFIG_DIR="${HOME}/.config/nemoclaw"
DEFAULT_GATEWAY="nemoclaw"
PROVIDERS=("nvidia-nim" "vllm-local" "ollama-local" "nvidia-ncp" "nim-local")
OPEN_SHELL_INSTALL_PATHS=("/usr/local/bin/openshell" "${XDG_BIN_HOME:-$HOME/.local/bin}/openshell")
OLLAMA_MODELS=("nemotron-3-super:120b" "nemotron-3-nano:30b")
TMP_ROOT="${TMPDIR:-/tmp}"
NEMOCLAW_SHIM_DIR="${HOME}/.local/bin"
ASSUME_YES=false
KEEP_OPEN_SHELL=false
DELETE_MODELS=false
usage() {
cat <<'EOF'
Usage: ./uninstall.sh [--yes] [--keep-openshell] [--delete-models]
Options:
--yes Skip the confirmation prompt
--keep-openshell Leave the openshell binary installed
--delete-models Remove NemoClaw-pulled Ollama models
-h, --help Show this help
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--yes)
ASSUME_YES=true
shift
;;
--keep-openshell)
KEEP_OPEN_SHELL=true
shift
;;
--delete-models)
DELETE_MODELS=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
fail "Unknown argument: $1"
;;
esac
done
confirm() {
if [ "$ASSUME_YES" = true ]; then
return 0
fi
echo ""
warn "This will remove all OpenShell sandboxes, NemoClaw-managed gateway/providers,"
warn "related Docker images, and local state under ~/.nemoclaw, ~/.config/openshell,"
warn "and ~/.config/nemoclaw."
warn "It will not uninstall Docker, Ollama, npm, Node.js, or other shared tooling."
if [ "$DELETE_MODELS" = false ]; then
warn "Ollama models are preserved by default. Re-run with --delete-models to remove them."
fi
printf "Continue? [y/N] "
local reply=""
if [ -t 2 ] && read -r reply 0</dev/tty 2>/dev/null; then
:
else
read -r reply || true
fi
case "$reply" in
y|Y|yes|YES) ;;
*) info "Aborted."; exit 0 ;;
esac
}
run_optional() {
local description="$1"
shift
if "$@" > /dev/null 2>&1; then
info "$description"
else
warn "$description skipped"
fi
}
remove_path() {
local path="$1"
if [ -e "$path" ] || [ -L "$path" ]; then
rm -rf "$path"
info "Removed $path"
fi
}
remove_glob_paths() {
local pattern="$1"
local path
for path in $pattern; do
[ -e "$path" ] || [ -L "$path" ] || continue
rm -rf "$path"
info "Removed $path"
done
}
remove_file_with_optional_sudo() {
local path="$1"
if [ ! -e "$path" ] && [ ! -L "$path" ]; then
return 0
fi
if [ -w "$path" ] || [ -w "$(dirname "$path")" ]; then
rm -f "$path"
elif [ "${NEMOCLAW_NON_INTERACTIVE:-}" = "1" ] || [ ! -t 0 ]; then
warn "Skipping privileged removal of $path in non-interactive mode."
return 0
else
sudo rm -f "$path"
fi
info "Removed $path"
}
stop_helper_services() {
if [ -x "$SCRIPT_DIR/scripts/start-services.sh" ]; then
run_optional "Stopped NemoClaw helper services" "$SCRIPT_DIR/scripts/start-services.sh" --stop
fi
remove_glob_paths "${TMP_ROOT}/nemoclaw-services-*"
}
stop_openshell_forward_processes() {
if ! command -v pgrep > /dev/null 2>&1; then
warn "pgrep not found; skipping local OpenShell forward process cleanup."
return 0
fi
local -a pids=()
local pid
while IFS= read -r pid; do
[ -n "$pid" ] || continue
pids+=("$pid")
done < <(pgrep -f 'openshell.*forward.*18789' 2>/dev/null || true)
if [ "${#pids[@]}" -eq 0 ]; then
info "No local OpenShell forward processes found"
return 0
fi
for pid in "${pids[@]}"; do
if kill "$pid" > /dev/null 2>&1 || kill -9 "$pid" > /dev/null 2>&1; then
info "Stopped OpenShell forward process $pid"
else
warn "Failed to stop OpenShell forward process $pid"
fi
done
}
remove_openshell_resources() {
if ! command -v openshell > /dev/null 2>&1; then
warn "openshell not found; skipping gateway/provider/sandbox cleanup."
return 0
fi
run_optional "Deleted all OpenShell sandboxes" openshell sandbox delete --all
for provider in "${PROVIDERS[@]}"; do
run_optional "Deleted provider '${provider}'" openshell provider delete "$provider"
done
run_optional "Destroyed gateway '${DEFAULT_GATEWAY}'" openshell gateway destroy -g "$DEFAULT_GATEWAY"
}
remove_nemoclaw_cli() {
if command -v npm > /dev/null 2>&1; then
npm unlink -g nemoclaw > /dev/null 2>&1 || true
if npm uninstall -g nemoclaw > /dev/null 2>&1; then
info "Removed global nemoclaw npm package"
else
warn "Global nemoclaw npm package not found or already removed"
fi
else
warn "npm not found; skipping nemoclaw npm uninstall."
fi
if [ -L "${NEMOCLAW_SHIM_DIR}/nemoclaw" ] || [ -f "${NEMOCLAW_SHIM_DIR}/nemoclaw" ]; then
remove_path "${NEMOCLAW_SHIM_DIR}/nemoclaw"
fi
}
remove_nemoclaw_state() {
remove_path "$NEMOCLAW_STATE_DIR"
remove_path "$OPENSHELL_CONFIG_DIR"
remove_path "$NEMOCLAW_CONFIG_DIR"
}
remove_related_docker_containers() {
if ! command -v docker > /dev/null 2>&1; then
warn "docker not found; skipping Docker container cleanup."
return 0
fi
if ! docker info > /dev/null 2>&1; then
warn "docker is not running; skipping Docker container cleanup."
return 0
fi
local -a container_ids=()
local line
while IFS= read -r line; do
[ -n "$line" ] || continue
container_ids+=("$line")
done < <(
docker ps -a --format '{{.ID}} {{.Image}} {{.Names}}' 2>/dev/null \
| awk '
BEGIN { IGNORECASE=1 }
{
ref=$0
if (ref ~ /openshell-cluster/ || ref ~ /openshell/ || ref ~ /openclaw/ || ref ~ /nemoclaw/) {
print $1
}
}
' \
| awk '!seen[$0]++'
)
if [ "${#container_ids[@]}" -eq 0 ]; then
info "No NemoClaw/OpenShell Docker containers found"
return 0
fi
local removed_any=false
local container_id
for container_id in "${container_ids[@]}"; do
if docker rm -f "$container_id" > /dev/null 2>&1; then
info "Removed Docker container $container_id"
removed_any=true
else
warn "Failed to remove Docker container $container_id"
fi
done
if [ "$removed_any" = false ]; then
warn "No related Docker containers were removed"
fi
}
remove_related_docker_images() {
if ! command -v docker > /dev/null 2>&1; then
warn "docker not found; skipping Docker image cleanup."
return 0
fi
if ! docker info > /dev/null 2>&1; then
warn "docker is not running; skipping Docker image cleanup."
return 0
fi
local -a image_ids=()
local line
while IFS= read -r line; do
[ -n "$line" ] || continue
image_ids+=("$line")
done < <(
docker images --format '{{.ID}} {{.Repository}}:{{.Tag}}' 2>/dev/null \
| awk '
BEGIN { IGNORECASE=1 }
{
ref=$0
if (ref ~ /openshell/ || ref ~ /openclaw/ || ref ~ /nemoclaw/) {
print $1
}
}
' \
| awk '!seen[$0]++'
)
if [ "${#image_ids[@]}" -eq 0 ]; then
info "No NemoClaw/OpenShell Docker images found"
return 0
fi
local removed_any=false
local image_id
for image_id in "${image_ids[@]}"; do
if docker rmi -f "$image_id" > /dev/null 2>&1; then
info "Removed Docker image $image_id"
removed_any=true
else
warn "Failed to remove Docker image $image_id"
fi
done
if [ "$removed_any" = false ]; then
warn "No related Docker images were removed"
fi
}
gateway_volume_candidates() {
local gateway_name="${1:-$DEFAULT_GATEWAY}"
printf 'openshell-cluster-%s\n' "$gateway_name"
}
remove_related_docker_volumes() {
if ! command -v docker > /dev/null 2>&1; then
warn "docker not found; skipping Docker volume cleanup."
return 0
fi
if ! docker info > /dev/null 2>&1; then
warn "docker is not running; skipping Docker volume cleanup."
return 0
fi
local -a volume_names=()
local volume_name
while IFS= read -r volume_name; do
[ -n "$volume_name" ] || continue
volume_names+=("$volume_name")
done < <(gateway_volume_candidates "$DEFAULT_GATEWAY")
if [ "${#volume_names[@]}" -eq 0 ]; then
info "No NemoClaw/OpenShell Docker volumes found"
return 0
fi
local removed_any=false
for volume_name in "${volume_names[@]}"; do
if docker volume inspect "$volume_name" > /dev/null 2>&1; then
if docker volume rm -f "$volume_name" > /dev/null 2>&1; then
info "Removed Docker volume $volume_name"
removed_any=true
else
warn "Failed to remove Docker volume $volume_name"
fi
fi
done
if [ "$removed_any" = false ]; then
info "No NemoClaw/OpenShell Docker volumes found"
fi
}
remove_optional_ollama_models() {
if [ "$DELETE_MODELS" != true ]; then
info "Keeping Ollama models as requested."
return 0
fi
if ! command -v ollama > /dev/null 2>&1; then
warn "ollama not found; skipping model cleanup."
return 0
fi
local model
for model in "${OLLAMA_MODELS[@]}"; do
if ollama rm "$model" > /dev/null 2>&1; then
info "Removed Ollama model '$model'"
else
warn "Ollama model '$model' not found or already removed"
fi
done
}
remove_runtime_temp_artifacts() {
remove_glob_paths "${TMP_ROOT}/nemoclaw-create-*.log"
remove_glob_paths "${TMP_ROOT}/nemoclaw-tg-ssh-*.conf"
}
remove_openshell_binary() {
if [ "$KEEP_OPEN_SHELL" = true ]; then
info "Keeping openshell binary as requested."
return 0
fi
local removed=false
local current_path=""
if command -v openshell > /dev/null 2>&1; then
current_path="$(command -v openshell)"
fi
for path in "${OPEN_SHELL_INSTALL_PATHS[@]}"; do
if [ -e "$path" ] || [ -L "$path" ]; then
remove_file_with_optional_sudo "$path"
removed=true
fi
done
if [ "$removed" = false ] && [ -n "$current_path" ]; then
warn "openshell is installed at $current_path; leaving it in place."
elif [ "$removed" = false ]; then
warn "openshell binary not found in installer-managed locations."
fi
}
main() {
confirm
info "Stopping NemoClaw helper services..."
stop_helper_services
info "Stopping local OpenShell forward processes..."
stop_openshell_forward_processes
info "Removing OpenShell resources created for NemoClaw..."
remove_openshell_resources
info "Removing global nemoclaw install..."
remove_nemoclaw_cli
info "Removing related Docker containers..."
remove_related_docker_containers
info "Removing related Docker images..."
remove_related_docker_images
info "Removing related Docker volumes..."
remove_related_docker_volumes
info "Removing optional Ollama models..."
remove_optional_ollama_models
info "Removing runtime temp artifacts..."
remove_runtime_temp_artifacts
info "Removing openshell binary..."
remove_openshell_binary
info "Removing NemoClaw state..."
remove_nemoclaw_state
echo ""
info "Uninstall complete."
}
if [ "${BASH_SOURCE[0]-}" = "$0" ] || { [ -z "${BASH_SOURCE[0]-}" ] && { [ "$0" = "bash" ] || [ "$0" = "-bash" ]; }; }; then
main "$@"
fi