forked from essamamdani/openclaw-coolify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_debug.sh
More file actions
1351 lines (1218 loc) · 46.1 KB
/
install_debug.sh
File metadata and controls
1351 lines (1218 loc) · 46.1 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
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
set -euo pipefail
# Moltbot Installer for macOS and Linux
# Usage: curl -fsSL --proto '=https' --tlsv1.2 https://molt.bot/install.sh | bash
BOLD='\033[1m'
ACCENT='\033[38;2;255;90;45m'
# shellcheck disable=SC2034
ACCENT_BRIGHT='\033[38;2;255;122;61m'
ACCENT_DIM='\033[38;2;209;74;34m'
INFO='\033[38;2;255;138;91m'
SUCCESS='\033[38;2;47;191;113m'
WARN='\033[38;2;255;176;32m'
ERROR='\033[38;2;226;61;45m'
MUTED='\033[38;2;139;127;119m'
NC='\033[0m' # No Color
DEFAULT_TAGLINE="All your chats, one Moltbot."
ORIGINAL_PATH="${PATH:-}"
TMPFILES=()
cleanup_tmpfiles() {
local f
for f in "${TMPFILES[@]:-}"; do
rm -f "$f" 2>/dev/null || true
done
}
trap cleanup_tmpfiles EXIT
mktempfile() {
local f
f="$(mktemp)"
TMPFILES+=("$f")
echo "$f"
}
DOWNLOADER=""
detect_downloader() {
if command -v curl &> /dev/null; then
DOWNLOADER="curl"
return 0
fi
if command -v wget &> /dev/null; then
DOWNLOADER="wget"
return 0
fi
echo -e "${ERROR}Error: Missing downloader (curl or wget required)${NC}"
exit 1
}
download_file() {
local url="$1"
local output="$2"
if [[ -z "$DOWNLOADER" ]]; then
detect_downloader
fi
if [[ "$DOWNLOADER" == "curl" ]]; then
curl -fsSL --proto '=https' --tlsv1.2 --retry 3 --retry-delay 1 --retry-connrefused -o "$output" "$url"
return
fi
wget -q --https-only --secure-protocol=TLSv1_2 --tries=3 --timeout=20 -O "$output" "$url"
}
run_remote_bash() {
local url="$1"
local tmp
tmp="$(mktempfile)"
download_file "$url" "$tmp"
/bin/bash "$tmp"
}
cleanup_legacy_submodules() {
local repo_dir="$1"
local legacy_dir="$repo_dir/Peekaboo"
if [[ -d "$legacy_dir" ]]; then
echo -e "${WARN}→${NC} Removing legacy submodule checkout: ${INFO}${legacy_dir}${NC}"
rm -rf "$legacy_dir"
fi
}
cleanup_npm_clawdbot_paths() {
local npm_root=""
npm_root="$(npm root -g 2>/dev/null || true)"
if [[ -z "$npm_root" || "$npm_root" != *node_modules* ]]; then
return 1
fi
rm -rf "$npm_root"/.clawdbot-* "$npm_root"/clawdbot 2>/dev/null || true
}
extract_clawdbot_conflict_path() {
local log="$1"
local path=""
path="$(sed -n 's/.*File exists: //p' "$log" | head -n1)"
if [[ -z "$path" ]]; then
path="$(sed -n 's/.*EEXIST: file already exists, //p' "$log" | head -n1)"
fi
if [[ -n "$path" ]]; then
echo "$path"
return 0
fi
return 1
}
cleanup_clawdbot_bin_conflict() {
local bin_path="$1"
if [[ -z "$bin_path" || ( ! -e "$bin_path" && ! -L "$bin_path" ) ]]; then
return 1
fi
local npm_bin=""
npm_bin="$(npm_global_bin_dir 2>/dev/null || true)"
if [[ -n "$npm_bin" && "$bin_path" != "$npm_bin/clawdbot" ]]; then
case "$bin_path" in
"/opt/homebrew/bin/clawdbot"|"/usr/local/bin/clawdbot")
;;
*)
return 1
;;
esac
fi
if [[ -L "$bin_path" ]]; then
local target=""
target="$(readlink "$bin_path" 2>/dev/null || true)"
if [[ "$target" == *"/node_modules/clawdbot/"* || "$target" == *"/node_modules/moltbot/"* ]]; then
rm -f "$bin_path"
echo -e "${WARN}→${NC} Removed stale clawdbot symlink at ${INFO}${bin_path}${NC}"
return 0
fi
return 1
fi
local backup=""
backup="${bin_path}.bak-$(date +%Y%m%d-%H%M%S)"
if mv "$bin_path" "$backup"; then
echo -e "${WARN}→${NC} Moved existing clawdbot binary to ${INFO}${backup}${NC}"
return 0
fi
return 1
}
install_clawdbot_npm() {
local spec="$1"
local log
log="$(mktempfile)"
if ! SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" npm --loglevel "$NPM_LOGLEVEL" ${NPM_SILENT_FLAG:+$NPM_SILENT_FLAG} --no-fund --no-audit install -g "$spec" 2>&1 | tee "$log"; then
if grep -q "ENOTEMPTY: directory not empty, rename .*clawdbot" "$log"; then
echo -e "${WARN}→${NC} npm left a stale clawdbot directory; cleaning and retrying..."
cleanup_npm_clawdbot_paths
SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" npm --loglevel "$NPM_LOGLEVEL" ${NPM_SILENT_FLAG:+$NPM_SILENT_FLAG} --no-fund --no-audit install -g "$spec"
return $?
fi
if grep -q "EEXIST" "$log"; then
local conflict=""
conflict="$(extract_clawdbot_conflict_path "$log" || true)"
if [[ -n "$conflict" ]] && cleanup_clawdbot_bin_conflict "$conflict"; then
SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" npm --loglevel "$NPM_LOGLEVEL" ${NPM_SILENT_FLAG:+$NPM_SILENT_FLAG} --no-fund --no-audit install -g "$spec"
return $?
fi
echo -e "${ERROR}npm failed because a clawdbot binary already exists.${NC}"
if [[ -n "$conflict" ]]; then
echo -e "${INFO}i${NC} Remove or move ${INFO}${conflict}${NC}, then retry."
fi
echo -e "${INFO}i${NC} Or rerun with ${INFO}npm install -g --force ${spec}${NC} (overwrites)."
fi
return 1
fi
return 0
}
TAGLINES=()
TAGLINES+=("Your terminal just grew claws—type something and let the bot pinch the busywork.")
TAGLINES+=("Welcome to the command line: where dreams compile and confidence segfaults.")
TAGLINES+=("I run on caffeine, JSON5, and the audacity of \"it worked on my machine.\"")
TAGLINES+=("Gateway online—please keep hands, feet, and appendages inside the shell at all times.")
TAGLINES+=("I speak fluent bash, mild sarcasm, and aggressive tab-completion energy.")
TAGLINES+=("One CLI to rule them all, and one more restart because you changed the port.")
TAGLINES+=("If it works, it's automation; if it breaks, it's a \"learning opportunity.\"")
TAGLINES+=("Pairing codes exist because even bots believe in consent—and good security hygiene.")
TAGLINES+=("Your .env is showing; don't worry, I'll pretend I didn't see it.")
TAGLINES+=("I'll do the boring stuff while you dramatically stare at the logs like it's cinema.")
TAGLINES+=("I'm not saying your workflow is chaotic... I'm just bringing a linter and a helmet.")
TAGLINES+=("Type the command with confidence—nature will provide the stack trace if needed.")
TAGLINES+=("I don't judge, but your missing API keys are absolutely judging you.")
TAGLINES+=("I can grep it, git blame it, and gently roast it—pick your coping mechanism.")
TAGLINES+=("Hot reload for config, cold sweat for deploys.")
TAGLINES+=("I'm the assistant your terminal demanded, not the one your sleep schedule requested.")
TAGLINES+=("I keep secrets like a vault... unless you print them in debug logs again.")
TAGLINES+=("Automation with claws: minimal fuss, maximal pinch.")
TAGLINES+=("I'm basically a Swiss Army knife, but with more opinions and fewer sharp edges.")
TAGLINES+=("If you're lost, run doctor; if you're brave, run prod; if you're wise, run tests.")
TAGLINES+=("Your task has been queued; your dignity has been deprecated.")
TAGLINES+=("I can't fix your code taste, but I can fix your build and your backlog.")
TAGLINES+=("I'm not magic—I'm just extremely persistent with retries and coping strategies.")
TAGLINES+=("It's not \"failing,\" it's \"discovering new ways to configure the same thing wrong.\"")
TAGLINES+=("Give me a workspace and I'll give you fewer tabs, fewer toggles, and more oxygen.")
TAGLINES+=("I read logs so you can keep pretending you don't have to.")
TAGLINES+=("If something's on fire, I can't extinguish it—but I can write a beautiful postmortem.")
TAGLINES+=("I'll refactor your busywork like it owes me money.")
TAGLINES+=("Say \"stop\" and I'll stop—say \"ship\" and we'll both learn a lesson.")
TAGLINES+=("I'm the reason your shell history looks like a hacker-movie montage.")
TAGLINES+=("I'm like tmux: confusing at first, then suddenly you can't live without me.")
TAGLINES+=("I can run local, remote, or purely on vibes—results may vary with DNS.")
TAGLINES+=("If you can describe it, I can probably automate it—or at least make it funnier.")
TAGLINES+=("Your config is valid, your assumptions are not.")
TAGLINES+=("I don't just autocomplete—I auto-commit (emotionally), then ask you to review (logically).")
TAGLINES+=("Less clicking, more shipping, fewer \"where did that file go\" moments.")
TAGLINES+=("Claws out, commit in—let's ship something mildly responsible.")
TAGLINES+=("I'll butter your workflow like a lobster roll: messy, delicious, effective.")
TAGLINES+=("Shell yeah—I'm here to pinch the toil and leave you the glory.")
TAGLINES+=("If it's repetitive, I'll automate it; if it's hard, I'll bring jokes and a rollback plan.")
TAGLINES+=("Because texting yourself reminders is so 2024.")
TAGLINES+=("WhatsApp, but make it ✨engineering✨.")
TAGLINES+=("Turning \"I'll reply later\" into \"my bot replied instantly\".")
TAGLINES+=("The only crab in your contacts you actually want to hear from. 🦞")
TAGLINES+=("Chat automation for people who peaked at IRC.")
TAGLINES+=("Because Siri wasn't answering at 3AM.")
TAGLINES+=("IPC, but it's your phone.")
TAGLINES+=("The UNIX philosophy meets your DMs.")
TAGLINES+=("curl for conversations.")
TAGLINES+=("WhatsApp Business, but without the business.")
TAGLINES+=("Meta wishes they shipped this fast.")
TAGLINES+=("End-to-end encrypted, Zuck-to-Zuck excluded.")
TAGLINES+=("The only bot Mark can't train on your DMs.")
TAGLINES+=("WhatsApp automation without the \"please accept our new privacy policy\".")
TAGLINES+=("Chat APIs that don't require a Senate hearing.")
TAGLINES+=("Because Threads wasn't the answer either.")
TAGLINES+=("Your messages, your servers, Meta's tears.")
TAGLINES+=("iMessage green bubble energy, but for everyone.")
TAGLINES+=("Siri's competent cousin.")
TAGLINES+=("Works on Android. Crazy concept, we know.")
TAGLINES+=("No \$999 stand required.")
TAGLINES+=("We ship features faster than Apple ships calculator updates.")
TAGLINES+=("Your AI assistant, now without the \$3,499 headset.")
TAGLINES+=("Think different. Actually think.")
TAGLINES+=("Ah, the fruit tree company! 🍎")
HOLIDAY_NEW_YEAR="New Year's Day: New year, new config—same old EADDRINUSE, but this time we resolve it like grown-ups."
HOLIDAY_LUNAR_NEW_YEAR="Lunar New Year: May your builds be lucky, your branches prosperous, and your merge conflicts chased away with fireworks."
HOLIDAY_CHRISTMAS="Christmas: Ho ho ho—Santa's little claw-sistant is here to ship joy, roll back chaos, and stash the keys safely."
HOLIDAY_EID="Eid al-Fitr: Celebration mode: queues cleared, tasks completed, and good vibes committed to main with clean history."
HOLIDAY_DIWALI="Diwali: Let the logs sparkle and the bugs flee—today we light up the terminal and ship with pride."
HOLIDAY_EASTER="Easter: I found your missing environment variable—consider it a tiny CLI egg hunt with fewer jellybeans."
HOLIDAY_HANUKKAH="Hanukkah: Eight nights, eight retries, zero shame—may your gateway stay lit and your deployments stay peaceful."
HOLIDAY_HALLOWEEN="Halloween: Spooky season: beware haunted dependencies, cursed caches, and the ghost of node_modules past."
HOLIDAY_THANKSGIVING="Thanksgiving: Grateful for stable ports, working DNS, and a bot that reads the logs so nobody has to."
HOLIDAY_VALENTINES="Valentine's Day: Roses are typed, violets are piped—I'll automate the chores so you can spend time with humans."
append_holiday_taglines() {
local today
local month_day
today="$(date -u +%Y-%m-%d 2>/dev/null || date +%Y-%m-%d)"
month_day="$(date -u +%m-%d 2>/dev/null || date +%m-%d)"
case "$month_day" in
"01-01") TAGLINES+=("$HOLIDAY_NEW_YEAR") ;;
"02-14") TAGLINES+=("$HOLIDAY_VALENTINES") ;;
"10-31") TAGLINES+=("$HOLIDAY_HALLOWEEN") ;;
"12-25") TAGLINES+=("$HOLIDAY_CHRISTMAS") ;;
esac
case "$today" in
"2025-01-29"|"2026-02-17"|"2027-02-06") TAGLINES+=("$HOLIDAY_LUNAR_NEW_YEAR") ;;
"2025-03-30"|"2025-03-31"|"2026-03-20"|"2027-03-10") TAGLINES+=("$HOLIDAY_EID") ;;
"2025-10-20"|"2026-11-08"|"2027-10-28") TAGLINES+=("$HOLIDAY_DIWALI") ;;
"2025-04-20"|"2026-04-05"|"2027-03-28") TAGLINES+=("$HOLIDAY_EASTER") ;;
"2025-11-27"|"2026-11-26"|"2027-11-25") TAGLINES+=("$HOLIDAY_THANKSGIVING") ;;
"2025-12-15"|"2025-12-16"|"2025-12-17"|"2025-12-18"|"2025-12-19"|"2025-12-20"|"2025-12-21"|"2025-12-22"|"2026-12-05"|"2026-12-06"|"2026-12-07"|"2026-12-08"|"2026-12-09"|"2026-12-10"|"2026-12-11"|"2026-12-12"|"2027-12-25"|"2027-12-26"|"2027-12-27"|"2027-12-28"|"2027-12-29"|"2027-12-30"|"2027-12-31"|"2028-01-01") TAGLINES+=("$HOLIDAY_HANUKKAH") ;;
esac
}
pick_tagline() {
append_holiday_taglines
local count=${#TAGLINES[@]}
if [[ "$count" -eq 0 ]]; then
echo "$DEFAULT_TAGLINE"
return
fi
if [[ -n "${CLAWDBOT_TAGLINE_INDEX:-}" ]]; then
if [[ "${CLAWDBOT_TAGLINE_INDEX}" =~ ^[0-9]+$ ]]; then
local idx=$((CLAWDBOT_TAGLINE_INDEX % count))
echo "${TAGLINES[$idx]}"
return
fi
fi
local idx=$((RANDOM % count))
echo "${TAGLINES[$idx]}"
}
TAGLINE=$(pick_tagline)
NO_ONBOARD=${CLAWDBOT_NO_ONBOARD:-0}
NO_PROMPT=${CLAWDBOT_NO_PROMPT:-0}
DRY_RUN=${CLAWDBOT_DRY_RUN:-0}
INSTALL_METHOD=${CLAWDBOT_INSTALL_METHOD:-}
CLAWDBOT_VERSION=${CLAWDBOT_VERSION:-latest}
USE_BETA=${CLAWDBOT_BETA:-0}
GIT_DIR_DEFAULT="${HOME}/moltbot"
GIT_DIR=${CLAWDBOT_GIT_DIR:-$GIT_DIR_DEFAULT}
GIT_UPDATE=${CLAWDBOT_GIT_UPDATE:-1}
SHARP_IGNORE_GLOBAL_LIBVIPS="${SHARP_IGNORE_GLOBAL_LIBVIPS:-1}"
NPM_LOGLEVEL="${CLAWDBOT_NPM_LOGLEVEL:-error}"
NPM_SILENT_FLAG="--silent"
VERBOSE="${CLAWDBOT_VERBOSE:-0}"
CLAWDBOT_BIN=""
HELP=0
print_usage() {
cat <<EOF
Moltbot installer (macOS + Linux)
Usage:
curl -fsSL --proto '=https' --tlsv1.2 https://molt.bot/install.sh | bash -s -- [options]
Options:
--install-method, --method npm|git Install via npm (default) or from a git checkout
--npm Shortcut for --install-method npm
--git, --github Shortcut for --install-method git
--version <version|dist-tag> npm install: version (default: latest)
--beta Use beta if available, else latest
--git-dir, --dir <path> Checkout directory (default: ~/moltbot)
--no-git-update Skip git pull for existing checkout
--no-onboard Skip onboarding (non-interactive)
--no-prompt Disable prompts (required in CI/automation)
--dry-run Print what would happen (no changes)
--verbose Print debug output (set -x, npm verbose)
--help, -h Show this help
Environment variables:
CLAWDBOT_INSTALL_METHOD=git|npm
CLAWDBOT_VERSION=latest|next|<semver>
CLAWDBOT_BETA=0|1
CLAWDBOT_GIT_DIR=...
CLAWDBOT_GIT_UPDATE=0|1
CLAWDBOT_NO_PROMPT=1
CLAWDBOT_DRY_RUN=1
CLAWDBOT_NO_ONBOARD=1
CLAWDBOT_VERBOSE=1
CLAWDBOT_NPM_LOGLEVEL=error|warn|notice Default: error (hide npm deprecation noise)
SHARP_IGNORE_GLOBAL_LIBVIPS=0|1 Default: 1 (avoid sharp building against global libvips)
Examples:
curl -fsSL --proto '=https' --tlsv1.2 https://molt.bot/install.sh | bash
curl -fsSL --proto '=https' --tlsv1.2 https://molt.bot/install.sh | bash -s -- --no-onboard
curl -fsSL --proto '=https' --tlsv1.2 https://molt.bot/install.sh | bash -s -- --install-method git --no-onboard
EOF
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--no-onboard)
NO_ONBOARD=1
shift
;;
--onboard)
NO_ONBOARD=0
shift
;;
--dry-run)
DRY_RUN=1
shift
;;
--verbose)
VERBOSE=1
shift
;;
--no-prompt)
NO_PROMPT=1
shift
;;
--help|-h)
HELP=1
shift
;;
--install-method|--method)
INSTALL_METHOD="$2"
shift 2
;;
--version)
CLAWDBOT_VERSION="$2"
shift 2
;;
--beta)
USE_BETA=1
shift
;;
--npm)
INSTALL_METHOD="npm"
shift
;;
--git|--github)
INSTALL_METHOD="git"
shift
;;
--git-dir|--dir)
GIT_DIR="$2"
shift 2
;;
--no-git-update)
GIT_UPDATE=0
shift
;;
*)
shift
;;
esac
done
}
configure_verbose() {
if [[ "$VERBOSE" != "1" ]]; then
return 0
fi
if [[ "$NPM_LOGLEVEL" == "error" ]]; then
NPM_LOGLEVEL="notice"
fi
NPM_SILENT_FLAG=""
set -x
}
is_promptable() {
if [[ "$NO_PROMPT" == "1" ]]; then
return 1
fi
if [[ -r /dev/tty && -w /dev/tty ]]; then
return 0
fi
return 1
}
prompt_choice() {
local prompt="$1"
local answer=""
if ! is_promptable; then
return 1
fi
echo -e "$prompt" > /dev/tty
read -r answer < /dev/tty || true
echo "$answer"
}
detect_clawdbot_checkout() {
local dir="$1"
if [[ ! -f "$dir/package.json" ]]; then
return 1
fi
if [[ ! -f "$dir/pnpm-workspace.yaml" ]]; then
return 1
fi
if ! grep -q '"name"[[:space:]]*:[[:space:]]*"clawdbot"' "$dir/package.json" 2>/dev/null; then
return 1
fi
echo "$dir"
return 0
}
echo -e "${ACCENT}${BOLD}"
echo " 🦞 Moltbot Installer"
echo -e "${NC}${ACCENT_DIM} ${TAGLINE}${NC}"
echo ""
# Detect OS
OS="unknown"
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]] || [[ -n "${WSL_DISTRO_NAME:-}" ]]; then
OS="linux"
fi
if [[ "$OS" == "unknown" ]]; then
echo -e "${ERROR}Error: Unsupported operating system${NC}"
echo "This installer supports macOS and Linux (including WSL)."
echo "For Windows, use: iwr -useb https://molt.bot/install.ps1 | iex"
exit 1
fi
echo -e "${SUCCESS}✓${NC} Detected: $OS"
# Check for Homebrew on macOS
install_homebrew() {
if [[ "$OS" == "macos" ]]; then
if ! command -v brew &> /dev/null; then
echo -e "${WARN}→${NC} Installing Homebrew..."
run_remote_bash "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
# Add Homebrew to PATH for this session
if [[ -f "/opt/homebrew/bin/brew" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -f "/usr/local/bin/brew" ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
echo -e "${SUCCESS}✓${NC} Homebrew installed"
else
echo -e "${SUCCESS}✓${NC} Homebrew already installed"
fi
fi
}
# Check Node.js version
check_node() {
if command -v node &> /dev/null; then
NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [[ "$NODE_VERSION" -ge 22 ]]; then
echo -e "${SUCCESS}✓${NC} Node.js v$(node -v | cut -d'v' -f2) found"
return 0
else
echo -e "${WARN}→${NC} Node.js $(node -v) found, but v22+ required"
return 1
fi
else
echo -e "${WARN}→${NC} Node.js not found"
return 1
fi
}
# Install Node.js
install_node() {
if [[ "$OS" == "macos" ]]; then
echo -e "${WARN}→${NC} Installing Node.js via Homebrew..."
brew install node@22
brew link node@22 --overwrite --force 2>/dev/null || true
echo -e "${SUCCESS}✓${NC} Node.js installed"
elif [[ "$OS" == "linux" ]]; then
echo -e "${WARN}→${NC} Installing Node.js via NodeSource..."
require_sudo
if command -v apt-get &> /dev/null; then
local tmp
tmp="$(mktempfile)"
download_file "https://deb.nodesource.com/setup_22.x" "$tmp"
maybe_sudo -E bash "$tmp"
maybe_sudo apt-get install -y nodejs
elif command -v dnf &> /dev/null; then
local tmp
tmp="$(mktempfile)"
download_file "https://rpm.nodesource.com/setup_22.x" "$tmp"
maybe_sudo bash "$tmp"
maybe_sudo dnf install -y nodejs
elif command -v yum &> /dev/null; then
local tmp
tmp="$(mktempfile)"
download_file "https://rpm.nodesource.com/setup_22.x" "$tmp"
maybe_sudo bash "$tmp"
maybe_sudo yum install -y nodejs
else
echo -e "${ERROR}Error: Could not detect package manager${NC}"
echo "Please install Node.js 22+ manually: https://nodejs.org"
exit 1
fi
echo -e "${SUCCESS}✓${NC} Node.js installed"
fi
}
# Check Git
check_git() {
if command -v git &> /dev/null; then
echo -e "${SUCCESS}✓${NC} Git already installed"
return 0
fi
echo -e "${WARN}→${NC} Git not found"
return 1
}
is_root() {
[[ "$(id -u)" -eq 0 ]]
}
# Run a command with sudo only if not already root
maybe_sudo() {
if is_root; then
# Skip -E flag when root (env is already preserved)
if [[ "${1:-}" == "-E" ]]; then
shift
fi
"$@"
else
sudo "$@"
fi
}
require_sudo() {
if [[ "$OS" != "linux" ]]; then
return 0
fi
if is_root; then
return 0
fi
if command -v sudo &> /dev/null; then
return 0
fi
echo -e "${ERROR}Error: sudo is required for system installs on Linux${NC}"
echo "Install sudo or re-run as root."
exit 1
}
install_git() {
echo -e "${WARN}→${NC} Installing Git..."
if [[ "$OS" == "macos" ]]; then
brew install git
elif [[ "$OS" == "linux" ]]; then
require_sudo
if command -v apt-get &> /dev/null; then
maybe_sudo apt-get update -y
maybe_sudo apt-get install -y git
elif command -v dnf &> /dev/null; then
maybe_sudo dnf install -y git
elif command -v yum &> /dev/null; then
maybe_sudo yum install -y git
else
echo -e "${ERROR}Error: Could not detect package manager for Git${NC}"
exit 1
fi
fi
echo -e "${SUCCESS}✓${NC} Git installed"
}
# Fix npm permissions for global installs (Linux)
fix_npm_permissions() {
if [[ "$OS" != "linux" ]]; then
return 0
fi
local npm_prefix
npm_prefix="$(npm config get prefix 2>/dev/null || true)"
if [[ -z "$npm_prefix" ]]; then
return 0
fi
if [[ -w "$npm_prefix" || -w "$npm_prefix/lib" ]]; then
return 0
fi
echo -e "${WARN}→${NC} Configuring npm for user-local installs..."
mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
# shellcheck disable=SC2016
local path_line='export PATH="$HOME/.npm-global/bin:$PATH"'
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
if [[ -f "$rc" ]] && ! grep -q ".npm-global" "$rc"; then
echo "$path_line" >> "$rc"
fi
done
export PATH="$HOME/.npm-global/bin:$PATH"
echo -e "${SUCCESS}✓${NC} npm configured for user installs"
}
resolve_clawdbot_bin() {
if command -v clawdbot &> /dev/null; then
command -v clawdbot
return 0
fi
local npm_bin=""
npm_bin="$(npm_global_bin_dir || true)"
if [[ -n "$npm_bin" && -x "${npm_bin}/clawdbot" ]]; then
echo "${npm_bin}/clawdbot"
return 0
fi
return 1
}
ensure_clawdbot_bin_link() {
local npm_root=""
npm_root="$(npm root -g 2>/dev/null || true)"
if [[ -z "$npm_root" || ! -d "$npm_root/clawdbot" ]]; then
return 1
fi
local npm_bin=""
npm_bin="$(npm_global_bin_dir || true)"
if [[ -z "$npm_bin" ]]; then
return 1
fi
mkdir -p "$npm_bin"
if [[ ! -x "${npm_bin}/clawdbot" ]]; then
ln -sf "$npm_root/clawdbot/dist/entry.js" "${npm_bin}/clawdbot"
echo -e "${WARN}→${NC} Installed clawdbot bin link at ${INFO}${npm_bin}/clawdbot${NC}"
fi
return 0
}
# Check for existing Moltbot installation
check_existing_clawdbot() {
if [[ -n "$(type -P clawdbot 2>/dev/null || true)" ]]; then
echo -e "${WARN}→${NC} Existing Moltbot installation detected"
return 0
fi
return 1
}
ensure_pnpm() {
if command -v pnpm &> /dev/null; then
return 0
fi
if command -v corepack &> /dev/null; then
echo -e "${WARN}→${NC} Installing pnpm via Corepack..."
corepack enable >/dev/null 2>&1 || true
corepack prepare pnpm@10 --activate
echo -e "${SUCCESS}✓${NC} pnpm installed"
return 0
fi
echo -e "${WARN}→${NC} Installing pnpm via npm..."
fix_npm_permissions
npm install -g pnpm@10
echo -e "${SUCCESS}✓${NC} pnpm installed"
return 0
}
ensure_user_local_bin_on_path() {
local target="$HOME/.local/bin"
mkdir -p "$target"
export PATH="$target:$PATH"
# shellcheck disable=SC2016
local path_line='export PATH="$HOME/.local/bin:$PATH"'
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
if [[ -f "$rc" ]] && ! grep -q ".local/bin" "$rc"; then
echo "$path_line" >> "$rc"
fi
done
}
npm_global_bin_dir() {
local prefix=""
prefix="$(npm prefix -g 2>/dev/null || true)"
if [[ -n "$prefix" ]]; then
if [[ "$prefix" == /* ]]; then
echo "${prefix%/}/bin"
return 0
fi
fi
prefix="$(npm config get prefix 2>/dev/null || true)"
if [[ -n "$prefix" && "$prefix" != "undefined" && "$prefix" != "null" ]]; then
if [[ "$prefix" == /* ]]; then
echo "${prefix%/}/bin"
return 0
fi
fi
echo ""
return 1
}
refresh_shell_command_cache() {
hash -r 2>/dev/null || true
}
path_has_dir() {
local path="$1"
local dir="${2%/}"
if [[ -z "$dir" ]]; then
return 1
fi
case ":${path}:" in
*":${dir}:"*) return 0 ;;
*) return 1 ;;
esac
}
warn_shell_path_missing_dir() {
local dir="${1%/}"
local label="$2"
if [[ -z "$dir" ]]; then
return 0
fi
if path_has_dir "$ORIGINAL_PATH" "$dir"; then
return 0
fi
echo ""
echo -e "${WARN}→${NC} PATH warning: missing ${label}: ${INFO}${dir}${NC}"
echo -e "This can make ${INFO}clawdbot${NC} show as \"command not found\" in new terminals."
echo -e "Fix (zsh: ~/.zshrc, bash: ~/.bashrc):"
echo -e " export PATH=\"${dir}:\\$PATH\""
echo -e "Docs: ${INFO}https://docs.molt.bot/install#nodejs--npm-path-sanity${NC}"
}
ensure_npm_global_bin_on_path() {
local bin_dir=""
bin_dir="$(npm_global_bin_dir || true)"
if [[ -n "$bin_dir" ]]; then
export PATH="${bin_dir}:$PATH"
fi
}
maybe_nodenv_rehash() {
if command -v nodenv &> /dev/null; then
nodenv rehash >/dev/null 2>&1 || true
fi
}
warn_clawdbot_not_found() {
echo -e "${WARN}→${NC} Installed, but ${INFO}clawdbot${NC} is not discoverable on PATH in this shell."
echo -e "Try: ${INFO}hash -r${NC} (bash) or ${INFO}rehash${NC} (zsh), then retry."
echo -e "Docs: ${INFO}https://docs.molt.bot/install#nodejs--npm-path-sanity${NC}"
local t=""
t="$(type -t clawdbot 2>/dev/null || true)"
if [[ "$t" == "alias" || "$t" == "function" ]]; then
echo -e "${WARN}→${NC} Found a shell ${INFO}${t}${NC} named ${INFO}clawdbot${NC}; it may shadow the real binary."
fi
if command -v nodenv &> /dev/null; then
echo -e "Using nodenv? Run: ${INFO}nodenv rehash${NC}"
fi
local npm_prefix=""
npm_prefix="$(npm prefix -g 2>/dev/null || true)"
local npm_bin=""
npm_bin="$(npm_global_bin_dir 2>/dev/null || true)"
if [[ -n "$npm_prefix" ]]; then
echo -e "npm prefix -g: ${INFO}${npm_prefix}${NC}"
fi
if [[ -n "$npm_bin" ]]; then
echo -e "npm bin -g: ${INFO}${npm_bin}${NC}"
echo -e "If needed: ${INFO}export PATH=\"${npm_bin}:\\$PATH\"${NC}"
fi
}
resolve_clawdbot_bin() {
refresh_shell_command_cache
local resolved=""
resolved="$(type -P clawdbot 2>/dev/null || true)"
if [[ -n "$resolved" && -x "$resolved" ]]; then
echo "$resolved"
return 0
fi
ensure_npm_global_bin_on_path
refresh_shell_command_cache
resolved="$(type -P clawdbot 2>/dev/null || true)"
if [[ -n "$resolved" && -x "$resolved" ]]; then
echo "$resolved"
return 0
fi
local npm_bin=""
npm_bin="$(npm_global_bin_dir || true)"
if [[ -n "$npm_bin" && -x "${npm_bin}/clawdbot" ]]; then
echo "${npm_bin}/clawdbot"
return 0
fi
maybe_nodenv_rehash
refresh_shell_command_cache
resolved="$(type -P clawdbot 2>/dev/null || true)"
if [[ -n "$resolved" && -x "$resolved" ]]; then
echo "$resolved"
return 0
fi
if [[ -n "$npm_bin" && -x "${npm_bin}/clawdbot" ]]; then
echo "${npm_bin}/clawdbot"
return 0
fi
echo ""
return 1
}
install_clawdbot_from_git() {
local repo_dir="$1"
local repo_url="https://github.com/moltbot/moltbot.git"
if [[ -d "$repo_dir/.git" ]]; then
echo -e "${WARN}→${NC} Installing Moltbot from git checkout: ${INFO}${repo_dir}${NC}"
else
echo -e "${WARN}→${NC} Installing Moltbot from GitHub (${repo_url})..."
fi
if ! check_git; then
install_git
fi
ensure_pnpm
if [[ ! -d "$repo_dir" ]]; then
git clone "$repo_url" "$repo_dir"
fi
if [[ "$GIT_UPDATE" == "1" ]]; then
if [[ -z "$(git -C "$repo_dir" status --porcelain 2>/dev/null || true)" ]]; then
git -C "$repo_dir" pull --rebase || true
else
echo -e "${WARN}→${NC} Repo is dirty; skipping git pull"
fi
fi
cleanup_legacy_submodules "$repo_dir"
SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" pnpm -C "$repo_dir" install
if ! pnpm -C "$repo_dir" ui:build; then
echo -e "${WARN}→${NC} UI build failed; continuing (CLI may still work)"
fi
pnpm -C "$repo_dir" build
ensure_user_local_bin_on_path
cat > "$HOME/.local/bin/clawdbot" <<EOF
#!/usr/bin/env bash
set -euo pipefail
exec node "${repo_dir}/dist/entry.js" "\$@"
EOF
chmod +x "$HOME/.local/bin/clawdbot"
echo -e "${SUCCESS}✓${NC} Moltbot wrapper installed to \$HOME/.local/bin/clawdbot"
echo -e "${INFO}i${NC} This checkout uses pnpm. For deps, run: ${INFO}pnpm install${NC} (avoid npm install in the repo)."
}
# Install Moltbot
resolve_beta_version() {
local beta=""
beta="$(npm view moltbot dist-tags.beta 2>/dev/null || true)"
if [[ -z "$beta" || "$beta" == "undefined" || "$beta" == "null" ]]; then
return 1
fi
echo "$beta"
}
install_clawdbot() {
local package_name="clawdbot"
if [[ "$USE_BETA" == "1" ]]; then
local beta_version=""
beta_version="$(resolve_beta_version || true)"
if [[ -n "$beta_version" ]]; then
CLAWDBOT_VERSION="$beta_version"
echo -e "${INFO}i${NC} Beta tag detected (${beta_version}); installing beta."
package_name="moltbot"
else
CLAWDBOT_VERSION="latest"
echo -e "${INFO}i${NC} No beta tag found; installing latest."
fi
fi
if [[ -z "${CLAWDBOT_VERSION}" ]]; then
CLAWDBOT_VERSION="latest"
fi
local resolved_version=""
resolved_version="$(npm view "${package_name}@${CLAWDBOT_VERSION}" version 2>/dev/null || true)"
if [[ -n "$resolved_version" ]]; then
echo -e "${WARN}→${NC} Installing Moltbot ${INFO}${resolved_version}${NC}..."
else
echo -e "${WARN}→${NC} Installing Moltbot (${INFO}${CLAWDBOT_VERSION}${NC})..."
fi
local install_spec=""
if [[ "${CLAWDBOT_VERSION}" == "latest" ]]; then
install_spec="${package_name}@latest"
else
install_spec="${package_name}@${CLAWDBOT_VERSION}"
fi
if ! install_clawdbot_npm "${install_spec}"; then
echo -e "${WARN}→${NC} npm install failed; cleaning up and retrying..."
cleanup_npm_clawdbot_paths
install_clawdbot_npm "${install_spec}"
fi
if [[ "${CLAWDBOT_VERSION}" == "latest" && "${package_name}" == "clawdbot" ]]; then
if ! resolve_clawdbot_bin &> /dev/null; then
echo -e "${WARN}→${NC} npm install clawdbot@latest failed; retrying clawdbot@next"
cleanup_npm_clawdbot_paths
install_clawdbot_npm "clawdbot@next"
fi
fi
ensure_clawdbot_bin_link || true
echo -e "${SUCCESS}✓${NC} Moltbot installed"
}
# Run doctor for migrations (safe, non-interactive)
run_doctor() {
echo -e "${WARN}→${NC} Running doctor to migrate settings..."
local claw="${CLAWDBOT_BIN:-}"
if [[ -z "$claw" ]]; then
claw="$(resolve_clawdbot_bin || true)"
fi
if [[ -z "$claw" ]]; then
echo -e "${WARN}→${NC} Skipping doctor: ${INFO}clawdbot${NC} not on PATH yet."
warn_clawdbot_not_found
return 0
fi
"$claw" doctor --non-interactive || true
echo -e "${SUCCESS}✓${NC} Migration complete"
}
resolve_workspace_dir() {
local profile="${CLAWDBOT_PROFILE:-default}"
if [[ "${profile}" != "default" ]]; then
echo "${HOME}/clawd-${profile}"
else
echo "${HOME}/clawd"
fi
}
run_bootstrap_onboarding_if_needed() {
if [[ "${NO_ONBOARD}" == "1" ]]; then
return