forked from zeroclaw-labs/zeroclaw
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
Β·954 lines (826 loc) Β· 35.5 KB
/
install.sh
File metadata and controls
executable file
Β·954 lines (826 loc) Β· 35.5 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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
#!/bin/sh
set -eu
# ββ ZeroClaw installer βββββββββββββββββββββββββββββββββββββββββββ
# Builds and installs ZeroClaw from source.
# All feature lists and version info read from Cargo.toml β nothing hardcoded.
# POSIX sh β no bash required. Works on Alpine, Debian, macOS, everywhere.
REPO_URL="https://github.com/zeroclaw-labs/zeroclaw.git"
# ββ Output helpers (terminal-aware) ββββββββββββββββββββββββββββββ
if [ -t 1 ]; then
BOLD='\033[1m' GREEN='\033[32m' YELLOW='\033[33m' RED='\033[31m' RESET='\033[0m'
else
BOLD='' GREEN='' YELLOW='' RED='' RESET=''
fi
info() { printf " ${GREEN}β${RESET} %s\n" "$*"; }
warn() { printf " ${YELLOW}β ${RESET} %s\n" "$*" >&2; }
die() { printf " ${RED}β${RESET} %s\n" "$*" >&2; exit 1; }
bold() { printf "${BOLD}%s${RESET}" "$*"; }
# ββ Parse Cargo.toml (source of truth) ββββββββββββββββββββββββββββ
parse_cargo_toml() {
local toml="$1"
[ -f "$toml" ] || die "Cargo.toml not found at $toml"
VERSION=$(awk '/^\[workspace\.package\]/{p=1;next} /^\[/{p=0} p && /^version *=/{split($0,a,"\"");print a[2]}' "$toml")
MSRV=$(awk '/^\[workspace\.package\]/{p=1;next} /^\[/{p=0} p && /^rust-version *=/{split($0,a,"\"");print a[2]}' "$toml")
EDITION=$(awk '/^\[workspace\.package\]/{p=1;next} /^\[/{p=0} p && /^edition *=/{split($0,a,"\"");print a[2]}' "$toml")
DEFAULT_FEATURES=$(awk '/^default *= *\[/,/\]/{s=$0; while(match(s,/"[^"]+"/)){print substr(s,RSTART+1,RLENGTH-2); s=substr(s,RSTART+RLENGTH)}}' "$toml" | paste -sd, -)
ALL_FEATURES=$(awk '/^\[features\]/{p=1;next} /^\[/{p=0} p && /^[a-z][a-z0-9_-]* *=/{sub(/ *=.*/,"");print}' "$toml")
}
# ββ Feature validation ββββββββββββββββββββββββββββββββββββββββββββ
validate_feature() {
case "$1" in
fantoccini) warn "'fantoccini' is deprecated β use 'browser-native'" ; return 0 ;;
landlock) warn "'landlock' is deprecated β use 'sandbox-landlock'" ; return 0 ;;
metrics) warn "'metrics' is deprecated β use 'observability-prometheus'" ; return 0 ;;
esac
echo "$ALL_FEATURES" | grep -qx "$1" && return 0
die "Unknown feature '$1'. Run: $0 --list-features"
}
# ββ List features βββββββββββββββββββββββββββββββββββββββββββββββββ
list_features() {
parse_cargo_toml "$1"
echo
printf "%s β available build features\n" "$(bold "ZeroClaw v${VERSION}")"
echo
printf " %s\n" "$(bold "Default") (included unless --minimal):"
printf " %s\n" "$DEFAULT_FEATURES"
echo
channels="" observability="" platform="" other=""
for feat in $ALL_FEATURES; do
case "$feat" in
default|ci-all|fantoccini|landlock|metrics) continue ;;
channel-*) channels="${channels:+$channels, }$feat" ;;
observability-*) observability="${observability:+$observability, }$feat" ;;
hardware|peripheral-*|sandbox-*|browser-*|probe|rag-pdf|webauthn)
platform="${platform:+$platform, }$feat" ;;
*) other="${other:+$other, }$feat" ;;
esac
done
[ -n "$channels" ] && printf " %s\n %s\n\n" "$(bold "Channels:")" "$channels"
[ -n "$observability" ] && printf " %s\n %s\n\n" "$(bold "Observability:")" "$observability"
[ -n "$platform" ] && printf " %s\n %s\n\n" "$(bold "Platform:")" "$platform"
[ -n "$other" ] && printf " %s\n %s\n\n" "$(bold "Other:")" "$other"
printf " %s\n" "$(bold "Build profiles:")"
printf " %s # full (default features)\n" "$0"
printf " %s --minimal # kernel only (~6.6MB)\n" "$0"
printf " %s --minimal --features agent-runtime,channel-discord\n" "$0"
echo
}
# ββ Version comparison ββββββββββββββββββββββββββββββββββββββββββββ
version_gte() {
# Returns 0 if $1 >= $2 (dot-separated version strings)
local IFS=.
set -- $1 $2
local a1="${1:-0}" a2="${2:-0}" a3="${3:-0}"
shift 3 2>/dev/null || shift $#
local b1="${1:-0}" b2="${2:-0}" b3="${3:-0}"
[ "$a1" -gt "$b1" ] 2>/dev/null && return 0
[ "$a1" -lt "$b1" ] 2>/dev/null && return 1
[ "$a2" -gt "$b2" ] 2>/dev/null && return 0
[ "$a2" -lt "$b2" ] 2>/dev/null && return 1
[ "$a3" -gt "$b3" ] 2>/dev/null && return 0
[ "$a3" -lt "$b3" ] 2>/dev/null && return 1
return 0
}
# ββ Detect user's shell ββββββββββββββββββββββββββββββββββββββββββ
detect_shell_profile() {
local shell_name
shell_name=$(basename "${SHELL:-/bin/bash}")
case "$shell_name" in
zsh) echo "$HOME/.zshrc" ;;
fish) echo "$HOME/.config/fish/config.fish" ;;
*) echo "$HOME/.bashrc" ;;
esac
}
shell_export_syntax() {
local shell_name
shell_name=$(basename "${SHELL:-/bin/bash}")
case "$shell_name" in
fish) printf 'set -gx PATH "%s/bin" $PATH' "$CARGO_HOME" ;;
*) printf 'export PATH="%s/bin:$PATH"' "$CARGO_HOME" ;;
esac
}
# ββ Platform / target triple detection βββββββββββββββββββββββββββ
detect_target_triple() {
local os arch
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Darwin) echo "aarch64-apple-darwin" ;; # presume M-series
Linux)
case "$arch" in
x86_64) echo "x86_64-unknown-linux-gnu" ;;
aarch64|arm64) echo "aarch64-unknown-linux-gnu" ;;
armv7l) echo "armv7-unknown-linux-gnueabihf" ;;
armv6l|arm*) echo "arm-unknown-linux-gnueabihf" ;;
*) echo "" ;;
esac ;;
*) echo "" ;;
esac
}
# ββ Pre-built binary install ββββββββββββββββββββββββββββββββββββββ
install_prebuilt() {
local triple version asset_name asset_url sha256_url tmp_dir web_data_dir
triple=$(detect_target_triple)
if [ -z "$triple" ]; then
warn "No pre-built binary for this platform β falling back to source build"
return 1
fi
# Resolve latest release version via GitHub API
version=$(curl -fsSL "https://api.github.com/repos/zeroclaw-labs/zeroclaw/releases/latest" \
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\(.*\)".*/\1/')
if [ -z "$version" ]; then
warn "Could not resolve latest release β falling back to source build"
return 1
fi
asset_name="zeroclaw-${triple}.tar.gz"
asset_url="https://github.com/zeroclaw-labs/zeroclaw/releases/download/${version}/${asset_name}"
sha256_url="https://github.com/zeroclaw-labs/zeroclaw/releases/download/${version}/SHA256SUMS"
echo
printf "%s\n" "$(bold "Installing ZeroClaw ${version} (pre-built)")"
info "Platform: $triple"
info "Source: $asset_url"
echo
# Resolve platform-correct web data directory to match gateway auto-detect
case "$(uname -s)" in
Darwin)
web_data_dir="${HOME}/Library/Application Support/zeroclaw/web/dist"
;;
MINGW*|CYGWIN*|MSYS*)
web_data_dir="${LOCALAPPDATA}/zeroclaw/web/dist"
;;
*)
web_data_dir="${XDG_DATA_HOME:-${PREFIX}/.local/share}/zeroclaw/web/dist"
;;
esac
if [ "$DRY_RUN" = true ]; then
info "[dry-run] Would download $asset_url"
info "[dry-run] Would install to $CARGO_HOME/bin/zeroclaw"
info "[dry-run] Would install web dashboard to $web_data_dir"
return 0
fi
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
curl -fSL --progress-bar "$asset_url" -o "$tmp_dir/$asset_name" \
|| { warn "Download failed β falling back to source build"; rm -rf "$tmp_dir"; return 1; }
# Verify checksum β all failure modes fall back to source rather than install unverified
if ! curl -fsSL "$sha256_url" -o "$tmp_dir/SHA256SUMS" 2>/dev/null; then
warn "Could not fetch SHA256SUMS β falling back to source build"
rm -rf "$tmp_dir"; return 1
fi
expected=$(grep "$asset_name" "$tmp_dir/SHA256SUMS" | awk '{print $1}')
if [ -z "$expected" ]; then
warn "Asset not found in SHA256SUMS β falling back to source build"
rm -rf "$tmp_dir"; return 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$tmp_dir/$asset_name" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "$tmp_dir/$asset_name" | awk '{print $1}')
else
warn "No checksum tool available (sha256sum/shasum) β falling back to source build"
rm -rf "$tmp_dir"; return 1
fi
if [ "$actual" != "$expected" ]; then
die "Checksum mismatch β download may be corrupt. Expected: $expected Got: $actual"
fi
info "Checksum verified"
tar -xzf "$tmp_dir/$asset_name" -C "$tmp_dir"
mkdir -p "$CARGO_HOME/bin"
install -m 755 "$tmp_dir/zeroclaw" "$CARGO_HOME/bin/zeroclaw"
# Install web dashboard assets bundled in the release tarball
if [ -d "$tmp_dir/web/dist" ]; then
mkdir -p "$web_data_dir"
cp -r "$tmp_dir/web/dist/." "$web_data_dir/"
info "Web dashboard installed to $web_data_dir"
fi
rm -rf "$tmp_dir"
trap - EXIT
return 0
}
# ββ Usage βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
usage() {
cat <<EOF
$(bold "ZeroClaw installer")
Usage: $0 [options]
Options:
--prebuilt Download and install a pre-built binary (default when asked)
--source Build from source (skips the pre-built prompt)
--preset NAME Named feature preset: 'minimal' (kernel only, ~6.6MB) or
'full' (default features). Source builds only.
--minimal Alias for --preset minimal
--features X,Y Select specific features β source only (comma-separated)
--with-gateway Force the gateway feature on (overrides preset/feature default)
--without-gateway Force the gateway feature off (overrides preset/feature default)
--list-features Print all available features and exit
--prefix PATH Install everything under PATH (default: \$HOME)
Sets CARGO_HOME, RUSTUP_HOME, source checkout, config
--dry-run Show what would happen without building or installing
--skip-onboard Skip the post-install onboarding prompt
--uninstall Remove ZeroClaw binary and optionally config/data
-h, --help Show this help
-V, --version Show version from Cargo.toml
Examples:
$0 # interactive: asks prebuilt or source
$0 --prebuilt # download pre-built binary (fast)
$0 --source # always build from source
$0 --source --minimal # smallest possible binary
$0 --source --features agent-runtime,channel-discord # custom feature set
$0 --skip-onboard # install only, configure later
$0 --prefix /tmp/zc-test --skip-onboard # isolated test install
$0 --dry-run --prebuilt # preview without installing
$0 --uninstall # remove ZeroClaw
Environment:
ZEROCLAW_INSTALL_DIR Source checkout override (default: PREFIX/.zeroclaw/src)
ZEROCLAW_CARGO_FEATURES Extra cargo features (legacy; prefer --features)
EOF
}
# ββ Uninstall βββββββββββββββββββββββββββββββββββββββββββββββββββββ
do_uninstall() {
echo
printf "%s\n" "$(bold "Uninstalling ZeroClaw")"
echo
local bin="$CARGO_HOME/bin/zeroclaw"
if [ -f "$bin" ]; then
"$bin" service stop 2>/dev/null || true
"$bin" service uninstall 2>/dev/null || true
rm -f "$bin"
info "Removed $bin"
else
warn "Binary not found at $bin"
fi
local config_dir="$PREFIX/.zeroclaw"
if [ -d "$config_dir" ]; then
if [ -t 0 ]; then
printf " Remove config and data (%s)? [y/N] " "$config_dir"
read -r confirm
case "$confirm" in
[Yy]*) rm -rf "$config_dir"; info "Removed $config_dir" ;;
*) info "Config preserved at $config_dir" ;;
esac
else
info "Config preserved at $config_dir (non-interactive β use rm -rf to remove)"
fi
fi
# Check if another zeroclaw still lurks in PATH
local other_bin
other_bin=$(PATH="$ORIGINAL_PATH" command -v zeroclaw 2>/dev/null || true)
if [ -n "$other_bin" ]; then
local other_version
other_version=$("$other_bin" --version 2>/dev/null | awk '{print $NF}' || echo "unknown")
echo
warn "Another zeroclaw found at $other_bin (v$other_version)"
warn "Remove it manually if you want a full uninstall"
fi
echo
info "ZeroClaw uninstalled"
exit 0
}
# ββ Onboarding-needed status check βββββββββββββββββββββββββββββββ
#
# Detect whether the operator already has a completed onboarding so the
# 3-way "how would you like to onboard?" prompt can skip silently on a
# re-install. We treat onboarding as complete when a config file exists at
# the expected path AND it contains at least one `[providers.models.*]` or
# `[providers.fallback]` line β i.e. some provider is configured. Empty or
# default config files still trigger the prompt.
onboarding_needed() {
cfg="$PREFIX/.zeroclaw/config.toml"
[ -f "$cfg" ] || return 0 # no config β onboard
# Already-configured signal: any of these patterns means a provider was set.
if grep -qE '^\[providers\.models\.|^fallback *=|^default_provider *=' "$cfg" 2>/dev/null; then
return 1 # configured β skip
fi
return 0 # config exists but empty β onboard
}
# ββ Interactive feature picker βββββββββββββββββββββββββββββββββββ
#
# POSIX-sh number-toggle picker over the OPTIONAL feature set (channel-*,
# observability-*, hardware/peripheral/sandbox/browser flavours). Default
# features are always on; this only surfaces the opt-in extras. The output
# is a comma-separated list of selected features written to stdout.
#
# Invoked from the interactive flow when the operator runs install.sh in a
# TTY without `--minimal`, `--preset`, or `--features`. Skipped in
# non-interactive runs (curl | bash) and in CI.
interactive_feature_picker() {
toml="$1"
parse_cargo_toml "$toml"
picker_features=""
for feat in $ALL_FEATURES; do
case "$feat" in
default|ci-all|fantoccini|landlock|metrics) continue ;;
channel-*|observability-*|hardware|peripheral-*|sandbox-*|browser-*|probe|rag-pdf|webauthn)
picker_features="${picker_features:+$picker_features }$feat" ;;
esac
done
selected=""
# Prompt-side output goes to stderr so the picker's stdout β captured
# by the caller's `PICKED=$(interactive_feature_picker β¦)` β only
# carries the final selection. Without this redirect every prompt
# silently disappears into the variable and the user sees a frozen
# terminal.
echo >&2
printf " %s\n" "$(bold "Optional features (off by default):")" >&2
printf " %s\n" "Type the numbers to toggle, blank line to confirm." >&2
printf " %s\n" "Default features (agent runtime, gateway, β¦) are always on." >&2
echo >&2
while :; do
i=1
for feat in $picker_features; do
mark=" "
case " $selected " in *" $feat "*) mark="β" ;; esac
printf " [%2d] %s %s\n" "$i" "$mark" "$feat" >&2
i=$((i + 1))
done
echo >&2
printf " toggle (e.g. \"1 3 5\"), %s confirm: " "$(bold "Enter to")" >&2
read -r choices
[ -z "$choices" ] && break
for n in $choices; do
case "$n" in
''|*[!0-9]*) continue ;;
esac
idx=1
for feat in $picker_features; do
if [ "$idx" -eq "$n" ]; then
case " $selected " in
*" $feat "*) selected=$(printf '%s' "$selected" | tr ' ' '\n' | grep -vx "$feat" | paste -sd' ' -) ;;
*) selected="${selected:+$selected }$feat" ;;
esac
break
fi
idx=$((idx + 1))
done
done
done
printf '%s' "$selected" | tr ' ' ','
}
# ββ Web dashboard build for source installs ββββββββββββββββββββββ
#
# When a source build includes the `gateway` feature, the dashboard
# (`web/dist`) needs to be built so the gateway can serve it. If Node.js
# is on PATH we run `cargo web build` from the source root so the
# generated API client is refreshed before TypeScript compiles. Without
# Node.js we warn β the gateway still starts but the dashboard route
# returns 404 until `web/dist` is populated.
build_web_dashboard() {
src_dir="$1"
if [ ! -d "$src_dir/web" ]; then
warn "Source has no web/ directory; skipping dashboard build."
return 0
fi
if [ -f "$src_dir/web/dist/index.html" ]; then
info "Web dashboard already built at $src_dir/web/dist"
return 0
fi
if ! command -v npm >/dev/null 2>&1; then
warn "npm not found β skipping dashboard build. The gateway will run"
warn " in API-only mode until you build the dashboard:"
warn " cd $src_dir && cargo web build"
return 0
fi
info "Building web dashboard (cargo web build)..."
(cd "$src_dir" && cargo web build) || {
warn "Dashboard build failed β gateway will run in API-only mode."
return 0
}
info "Web dashboard built at $src_dir/web/dist"
}
# ββ Low-memory build heuristic ββββββββββββββββββββββββββββββββββββ
#
# [profile.release] in Cargo.toml uses fat LTO + codegen-units = 1.
# With heavy crates in the graph (matrix-sdk-crypto, ruma, vodozemac)
# a single rustc process can peak past 7 GB RSS during the cross-crate
# type pass, OOM-ing 8 GB ARM devices. Thin LTO trades a small
# binary-size hit for a much lower build-time RAM peak. Apply it as
# a default on Linux hosts with under ~12 GiB MemTotal, but only when
# the user has not already pinned CARGO_PROFILE_RELEASE_LTO.
apply_low_mem_lto_default() {
[ "$(uname -s)" = "Linux" ] || return 0
[ -r /proc/meminfo ] || return 0
[ -n "${CARGO_PROFILE_RELEASE_LTO:-}" ] && return 0
mem_kb=$(awk '/^MemTotal:/{print $2; exit}' /proc/meminfo 2>/dev/null)
case "$mem_kb" in
''|*[!0-9]*) return 0 ;;
esac
# 12 GiB in KiB = 12 * 1024 * 1024
if [ "$mem_kb" -lt 12582912 ]; then
mem_gib=$((mem_kb / 1048576))
export CARGO_PROFILE_RELEASE_LTO=thin
info "Low-memory device detected (${mem_gib} GiB RAM): using thin LTO to keep build RAM bounded. Set CARGO_PROFILE_RELEASE_LTO=fat to override."
fi
}
# ββ Parse arguments βββββββββββββββββββββββββββββββββββββββββββββββ
MINIMAL=false
USER_FEATURES=""
SKIP_ONBOARD=false
LIST_FEATURES=false
UNINSTALL=false
DRY_RUN=false
PREFIX="$HOME"
INSTALL_MODE="" # ""=ask, "prebuilt"=force prebuilt, "source"=force source
PRESET="" # ""=unset, "minimal"=alias for --minimal, "full"=default-features
WITH_GATEWAY="" # ""=unset (preset/feature default applies), "true"/"false"=explicit toggle
# Support legacy env var
if [ -n "${ZEROCLAW_CARGO_FEATURES:-}" ]; then
USER_FEATURES="${USER_FEATURES:+$USER_FEATURES,}$ZEROCLAW_CARGO_FEATURES"
fi
while [ $# -gt 0 ]; do
case "$1" in
--minimal) MINIMAL=true ;;
--preset)
if [ $# -lt 2 ]; then
die "Missing value for --preset. Expected: --preset minimal|full"
fi
shift
case "$1" in
minimal) PRESET="minimal"; MINIMAL=true ;;
full) PRESET="full" ;;
*) die "Unknown preset '$1'. Expected: minimal or full" ;;
esac ;;
--features)
if [ $# -lt 2 ]; then
die "Missing value for --features. Expected: --features X,Y"
fi
shift; USER_FEATURES="${USER_FEATURES:+$USER_FEATURES,}$1" ;;
--with-gateway) WITH_GATEWAY="true" ;;
--without-gateway) WITH_GATEWAY="false" ;;
--list-features) LIST_FEATURES=true ;;
--prefix)
if [ $# -lt 2 ]; then
die "Missing value for --prefix. Expected: --prefix /path"
fi
shift; PREFIX=$(echo "$1" | sed 's|/*$||') ;;
--dry-run) DRY_RUN=true ;;
--skip-onboard) SKIP_ONBOARD=true ;;
--prebuilt) INSTALL_MODE="prebuilt" ;;
--source) INSTALL_MODE="source" ;;
--uninstall) UNINSTALL=true ;;
-h|--help) usage; exit 0 ;;
-V|--version)
if [ -f "Cargo.toml" ]; then
parse_cargo_toml "Cargo.toml"
echo "install.sh for ZeroClaw v$VERSION"
else
echo "install.sh (version unknown β not in repo)"
fi
exit 0 ;;
*) die "Unknown option: $1. Run: $0 --help" ;;
esac
shift
done
# ββ Derive paths from prefix βββββββββββββββββββββββββββββββββββββ
CARGO_HOME="${CARGO_HOME:-$PREFIX/.cargo}"
RUSTUP_HOME="${RUSTUP_HOME:-$PREFIX/.rustup}"
INSTALL_DIR="${ZEROCLAW_INSTALL_DIR:-$PREFIX/.zeroclaw/src}"
ORIGINAL_PATH="$PATH"
PATH="$CARGO_HOME/bin:$PATH"
export CARGO_HOME RUSTUP_HOME PATH
[ "$UNINSTALL" = true ] && do_uninstall
# ββ List features (can run without cloning if in repo) ββββββββββββ
if [ "$LIST_FEATURES" = true ]; then
if [ -f "Cargo.toml" ]; then
list_features "Cargo.toml"
elif [ -f "$INSTALL_DIR/Cargo.toml" ]; then
list_features "$INSTALL_DIR/Cargo.toml"
else
die "No Cargo.toml found. Clone the repo first or run from the repo root."
fi
exit 0
fi
# ββ Decide: pre-built or source βββββββββββββββββββββββββββββββββββ
# --minimal, --features, --without-gateway, or --preset full imply source.
# Prebuilt binaries always ship with default features, so any flag that
# changes the feature set must force a source build.
if [ "$MINIMAL" = true ] || [ -n "$USER_FEATURES" ] \
|| [ "$WITH_GATEWAY" = "false" ] || [ "$PRESET" = "full" ]; then
INSTALL_MODE="source"
fi
if [ "$INSTALL_MODE" = "" ]; then
triple=$(detect_target_triple)
if [ -n "$triple" ]; then
if [ -t 0 ]; then
echo
printf " %s\n" "$(bold "How would you like to install ZeroClaw?")"
printf " [P] Pre-built binary β fast, no Rust required %s\n" "$(bold "(default)")"
printf " [s] Build from source β custom features, latest code\n"
printf "\n Choice [P/s]: "
read -r install_choice
case "$install_choice" in
[Ss]*) INSTALL_MODE="source" ;;
*) INSTALL_MODE="prebuilt" ;;
esac
else
# Non-interactive (curl | bash): default to pre-built silently
INSTALL_MODE="prebuilt"
fi
else
INSTALL_MODE="source"
fi
fi
if [ "$INSTALL_MODE" = "prebuilt" ]; then
if install_prebuilt; then
PREBUILT_OK=true
else
warn "Pre-built install failed β continuing with source build"
INSTALL_MODE="source"
PREBUILT_OK=false
fi
fi
[ "${PREBUILT_OK:-false}" = true ] && [ "$DRY_RUN" != true ] && {
BIN="$CARGO_HOME/bin/zeroclaw"
if [ -f "$BIN" ]; then
NEW_VERSION=$("$BIN" --version 2>/dev/null | awk '{print $NF}' || echo "?")
SIZE=$(du -h "$BIN" | awk '{print $1}')
echo
info "Installed: $BIN (v$NEW_VERSION, $SIZE)"
fi
}
# ββ Locate source βββββββββββββββββββββββββββββββββββββββββββββββββ
[ "${PREBUILT_OK:-false}" = true ] && {
# Jump past the source build to PATH + onboard
SOURCE_SKIPPED=true
}
if [ "${SOURCE_SKIPPED:-false}" != true ]; then
echo
printf "%s\n" "$(bold "ZeroClaw β source install")"
if [ "$PREFIX" != "$HOME" ]; then
printf " prefix: %s\n" "$(bold "$PREFIX")"
fi
echo
if [ -f "Cargo.toml" ] && grep -q "zeroclaw" "Cargo.toml" 2>/dev/null; then
INSTALL_DIR="$(pwd)"
info "Building from $(pwd)"
elif [ -d "$INSTALL_DIR/.git" ]; then
info "Updating source in $INSTALL_DIR"
git -C "$INSTALL_DIR" pull --ff-only --quiet 2>/dev/null || {
warn "Fast-forward pull failed β resetting to origin/master"
git -C "$INSTALL_DIR" fetch origin master --quiet
git -C "$INSTALL_DIR" reset --hard origin/master --quiet
}
cd "$INSTALL_DIR"
else
info "Cloning into $INSTALL_DIR"
mkdir -p "$(dirname "$INSTALL_DIR")"
git clone --depth 1 "$REPO_URL" "$INSTALL_DIR"
cd "$INSTALL_DIR"
fi
# ββ Parse Cargo.toml ββββββββββββββββββββββββββββββββββββββββββββββ
parse_cargo_toml "Cargo.toml"
printf " Version: %s (MSRV: %s, edition: %s)\n" "$(bold "$VERSION")" "$MSRV" "$EDITION"
# ββ Preflight: Rust βββββββββββββββββββββββββββββββββββββββββββββββ
NEED_RUST=false
if ! command -v rustc >/dev/null 2>&1 || ! command -v cargo >/dev/null 2>&1; then
NEED_RUST=true
elif [ "$PREFIX" != "$HOME" ] && [ ! -d "$RUSTUP_HOME/toolchains" ]; then
NEED_RUST=true
fi
if [ "$NEED_RUST" = true ]; then
if [ "$DRY_RUN" = true ]; then
warn "[dry-run] Would install Rust via rustup into $RUSTUP_HOME"
else
warn "Installing Rust via rustup into $CARGO_HOME"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
--no-modify-path --default-toolchain stable
. "$CARGO_HOME/env"
fi
fi
if [ "$DRY_RUN" != true ]; then
RUST_VERSION=$(rustc --version | awk '{print $2}')
if ! version_gte "$RUST_VERSION" "$MSRV"; then
die "Rust $RUST_VERSION is too old. ZeroClaw requires $MSRV+ (edition $EDITION). Run: rustup update stable"
fi
info "Rust $RUST_VERSION (>= $MSRV)"
fi
# ββ Preflight: 32-bit ARM ββββββββββββββββββββββββββββββββββββββββ
case "$(uname -m)" in
armv7l|armv6l|armhf)
die "32-bit ARM detected β the default feature 'observability-prometheus'
requires 64-bit atomics and will not compile on this architecture.
Example (full agent without prometheus):
$0 --minimal --features agent-runtime,schema-export
See all available features:
$0 --list-features"
;;
esac
# ββ Build feature flags ββββββββββββββββββββββββββββββββββββββββββ
#
# Cargo cannot remove individual entries from `default`, so toggling
# `gateway` off requires `--no-default-features` plus an explicit list
# of the rest. Derive that list from $DEFAULT_FEATURES (parsed from
# Cargo.toml above) so it stays in sync automatically.
CARGO_FLAGS=""
if [ "$MINIMAL" = true ]; then
CARGO_FLAGS="--no-default-features"
fi
# `--without-gateway` overrides the default-features set: switch to
# --no-default-features and re-add everything in `default` except gateway.
if [ "$WITH_GATEWAY" = "false" ] && [ "$MINIMAL" != true ]; then
CARGO_FLAGS="--no-default-features"
defaults_no_gateway=$(printf '%s' "$DEFAULT_FEATURES" | tr ',' '\n' | grep -vx gateway | paste -sd, -)
USER_FEATURES="${USER_FEATURES:+$USER_FEATURES,}$defaults_no_gateway"
fi
# `--with-gateway` is a no-op when default features are on (gateway is
# already there), and additive when --no-default-features is in play.
if [ "$WITH_GATEWAY" = "true" ]; then
case "$CARGO_FLAGS" in
*--no-default-features*) USER_FEATURES="${USER_FEATURES:+$USER_FEATURES,}gateway" ;;
esac
fi
# Interactive feature picker β only when the operator did not pin
# features via the CLI and is running under a TTY. Skipped on
# `--minimal`, `--preset`, `--features`, `--with-gateway` /
# `--without-gateway`, and any non-interactive run (curl | bash).
if [ -t 0 ] \
&& [ "$MINIMAL" != true ] \
&& [ -z "$USER_FEATURES" ] \
&& [ -z "$PRESET" ] \
&& [ -z "$WITH_GATEWAY" ] \
&& [ "$DRY_RUN" != true ]; then
PICKED=$(interactive_feature_picker "Cargo.toml")
if [ -n "$PICKED" ]; then
USER_FEATURES="$PICKED"
info "Picked features: $USER_FEATURES"
fi
fi
if [ -n "$USER_FEATURES" ]; then
# Normalize: treat commas, spaces, tabs as delimiters; deduplicate; trim empty
USER_FEATURES=$(printf '%s' "$USER_FEATURES" | tr ',[:space:]' '\n' | grep -v '^$' | sort -u | paste -sd, - || true)
if [ -n "$USER_FEATURES" ]; then
# Validate each feature
OLD_IFS="$IFS"
IFS=','
for feat in $USER_FEATURES; do
[ -n "$feat" ] && validate_feature "$feat"
done
IFS="$OLD_IFS"
CARGO_FLAGS="$CARGO_FLAGS --features $USER_FEATURES"
fi
fi
# ββ Detect existing installs ββββββββββββββββββββββββββββββββββββββ
PATH_BIN=$(PATH="$ORIGINAL_PATH" command -v zeroclaw 2>/dev/null || true)
if [ -n "$PATH_BIN" ]; then
PATH_VERSION=$("$PATH_BIN" --version 2>/dev/null | awk '{print $NF}' || echo "unknown")
TARGET_BIN="$CARGO_HOME/bin/zeroclaw"
if [ "$PATH_BIN" != "$TARGET_BIN" ]; then
warn "zeroclaw found at $PATH_BIN (v$PATH_VERSION)"
warn "This install targets $TARGET_BIN"
warn "The old binary will shadow the new one unless removed or PATH is reordered"
else
warn "Existing install: $PATH_BIN (v$PATH_VERSION)"
fi
if [ "$MINIMAL" = true ] && [ "$DRY_RUN" != true ]; then
if [ -t 0 ]; then
printf " --minimal will produce a reduced binary (no agent runtime by default). Continue? [Y/n] "
read -r confirm
case "$confirm" in
[Nn]*) echo "Aborted."; exit 0 ;;
esac
fi
fi
if [ "$PRESET" = "full" ] && [ "$DRY_RUN" != true ] && [ -t 1 ]; then
info "--preset full: building from source with the full default feature set."
fi
fi
# ββ Build profile RAM heuristic (Linux low-mem hosts) βββββββββββββ
apply_low_mem_lto_default
# ββ Dry run βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
if [ "$DRY_RUN" = true ]; then
echo
printf "%s\n" "$(bold "Dry run β nothing will be built or installed")"
echo
info "Source: $INSTALL_DIR"
info "Binary: $CARGO_HOME/bin/zeroclaw"
info "Config: $PREFIX/.zeroclaw/"
info "Rust: $CARGO_HOME (CARGO_HOME), $RUSTUP_HOME (RUSTUP_HOME)"
echo
if [ -n "${CARGO_PROFILE_RELEASE_LTO:-}" ]; then
info "env: CARGO_PROFILE_RELEASE_LTO=$CARGO_PROFILE_RELEASE_LTO"
fi
if [ -n "$CARGO_FLAGS" ]; then
info "cargo install --path . --locked --force $CARGO_FLAGS"
else
info "cargo install --path . --locked --force"
fi
EXPORT_LINE=$(shell_export_syntax)
PROFILE=$(detect_shell_profile)
echo
printf " %s (%s):\n" "$(bold "Shell profile")" "$PROFILE"
printf " %s\n" "$EXPORT_LINE"
echo
exit 0
fi
# ββ Build and install βββββββββββββββββββββββββββββββββββββββββββββ
echo
printf "%s\n" "$(bold "Building ZeroClaw v$VERSION")"
if [ -n "$CARGO_FLAGS" ]; then
info "Feature flags: $CARGO_FLAGS"
else
info "Feature flags: (defaults)"
fi
echo
# shellcheck disable=SC2086
cargo install --path . --locked --force $CARGO_FLAGS
# ββ Web dashboard (gateway feature only) ββββββββββββββββββββββββββ
# When the install includes the `gateway` feature, build `web/dist` so
# the dashboard route serves something. Skips silently when the build
# excluded gateway (`--without-gateway`, `--minimal` without explicit
# gateway in --features, etc).
WANT_GATEWAY=true
case "$CARGO_FLAGS" in
*--no-default-features*)
case ",$USER_FEATURES," in
*,gateway,*) ;;
*) WANT_GATEWAY=false ;;
esac ;;
esac
if [ "$WANT_GATEWAY" = true ]; then
build_web_dashboard "$INSTALL_DIR"
fi
# ββ Summary βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
BIN="$CARGO_HOME/bin/zeroclaw"
if [ -f "$BIN" ]; then
SIZE=$(du -h "$BIN" | awk '{print $1}')
NEW_VERSION=$("$BIN" --version 2>/dev/null | awk '{print $NF}' || echo "$VERSION")
echo
info "Installed: $BIN (v$NEW_VERSION, $SIZE)"
ACTIVE_BIN=$(PATH="$ORIGINAL_PATH" command -v zeroclaw 2>/dev/null || true)
if [ -n "$ACTIVE_BIN" ] && [ "$ACTIVE_BIN" != "$BIN" ]; then
ACTIVE_VERSION=$("$ACTIVE_BIN" --version 2>/dev/null | awk '{print $NF}' || echo "unknown")
echo
warn "$(bold "WARNING:") zeroclaw in your PATH is $ACTIVE_BIN (v$ACTIVE_VERSION)"
warn "It will shadow the v$NEW_VERSION binary you just installed at $BIN"
warn "Fix: remove the old binary or put $CARGO_HOME/bin earlier in your PATH"
fi
else
warn "Binary not found at expected path: $BIN"
fi
fi # end source build block
BIN="$CARGO_HOME/bin/zeroclaw"
# ββ PATH guidance βββββββββββββββββββββββββββββββββββββββββββββββββ
PROFILE=$(detect_shell_profile)
EXPORT_LINE=$(shell_export_syntax)
SHOW_PATH_HELP=false
if [ "$PREFIX" != "$HOME" ]; then
SHOW_PATH_HELP=true
elif [ -f "$PROFILE" ] && ! grep -q "$CARGO_HOME/bin" "$PROFILE" 2>/dev/null; then
SHOW_PATH_HELP=true
elif [ ! -f "$PROFILE" ]; then
SHOW_PATH_HELP=true
fi
if [ "$SHOW_PATH_HELP" = true ]; then
echo
printf " %s (%s):\n" "$(bold "Add to your shell profile")" "$PROFILE"
echo
printf " %s\n" "$EXPORT_LINE"
echo
printf " Then reload:\n"
echo
printf " source %s\n" "$PROFILE"
echo
fi
# ββ Onboard βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
if [ "$SKIP_ONBOARD" = false ] && [ "$DRY_RUN" != true ] && [ -f "$BIN" ]; then
# Skip the prompt entirely when the operator already has a configured
# ZeroClaw β re-installs should not re-prompt.
if ! onboarding_needed; then
info "Existing ZeroClaw config detected at $PREFIX/.zeroclaw/config.toml β skipping onboard prompt."
info "Run 'zeroclaw onboard' to reconfigure."
elif [ -t 0 ]; then
# 3-way onboarding choice. Bare Enter accepts the [1] CLI default;
# option [2] foregrounds the daemon so the operator can finish in the
# browser and Ctrl+C to return; [3] skips and prints a follow-up hint.
# Non-TTY runs fall through to the silent skip in the else branch.
echo
printf "%s\n" "$(bold "ZeroClaw installed. How would you like to complete onboarding?")"
printf " [1] CLI/TUI (zeroclaw onboard)\n"
printf " [2] Open gateway in browser (zeroclaw daemon + dashboard)\n"
printf " [3] Skip for now\n"
printf " Choice [1-3, default 1]: "
read -r onboard_choice
case "${onboard_choice:-1}" in
1|"")
echo
"$BIN" onboard || warn "Onboard wizard exited with an error β run 'zeroclaw onboard' manually"
;;
2)
echo
info "Starting gateway daemon for browser-based onboarding..."
info "Open the dashboard in your browser; pair with the code shown in logs."
info "Stop the daemon with Ctrl+C when done; then run 'zeroclaw service install' for always-on."
"$BIN" daemon || warn "Daemon exited with an error β run 'zeroclaw daemon' manually"
;;
3)
info "Skipped onboarding. Run 'zeroclaw onboard' (CLI) or 'zeroclaw daemon' (browser) when ready."
;;
*)
warn "Unknown choice '$onboard_choice' β skipping. Run 'zeroclaw onboard' to configure."
;;
esac
else
info "Non-interactive β skipping onboard prompt. Run 'zeroclaw onboard' to configure."
fi
fi
echo
info "Done. Run $(bold "zeroclaw agent") to start chatting."
echo