This repository was archived by the owner on Mar 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·1308 lines (1134 loc) · 43.8 KB
/
setup.sh
File metadata and controls
executable file
·1308 lines (1134 loc) · 43.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
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
#!/usr/bin/env bash
#
# Cracked Development Environment Setup
# https://github.com/schpet/cracked
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/schpet/cracked/main/setup.sh | bash
# curl -fsSL https://raw.githubusercontent.com/schpet/cracked/main/setup.sh | bash -s -- --deno
# curl -fsSL https://raw.githubusercontent.com/schpet/cracked/main/setup.sh | bash -s -- --rust
# curl -fsSL https://raw.githubusercontent.com/schpet/cracked/main/setup.sh | bash -s -- --rails
# curl -fsSL https://raw.githubusercontent.com/schpet/cracked/main/setup.sh | bash -s -- --all
#
# Options:
# --base Install base tools only (default)
# --deno Install base + Deno environment
# --rust Install base + Rust toolchain
# --rails Install base + Ruby on Rails
# --all Install everything
# --update Update already installed tools to latest versions
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Detect architecture
ARCH=$(uname -m)
OS=$(uname -s)
log_info() { echo -e "${BLUE}[INFO]${NC} $*"; }
log_success() { echo -e "${GREEN}[OK]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
# Check if running as root (we need sudo for system installs)
check_sudo() {
if [[ $EUID -eq 0 ]]; then
SUDO=""
elif command -v sudo &> /dev/null; then
SUDO="sudo"
else
log_error "This script requires sudo or root access"
exit 1
fi
}
# Detect if a command exists
has_cmd() { command -v "$1" &> /dev/null; }
# URL for cached versions file
VERSIONS_URL="https://raw.githubusercontent.com/schpet/cracked/main/versions.json"
CACHED_VERSIONS=""
# Fetch and cache versions.json on first use
fetch_cached_versions() {
if [[ -z "$CACHED_VERSIONS" ]]; then
CACHED_VERSIONS=$(curl -fsSL "$VERSIONS_URL" 2>/dev/null || echo "{}")
fi
}
# Get latest GitHub release tag for a repo
# First checks cached versions.json, falls back to GitHub API
get_latest_release() {
local repo="$1"
# Try cached version first
fetch_cached_versions
local cached_version
cached_version=$(echo "$CACHED_VERSIONS" | grep "\"$repo\"" | sed -E 's/.*: *"([^"]+)".*/\1/')
if [[ -n "$cached_version" ]]; then
echo "$cached_version"
return
fi
# Fall back to GitHub API
local curl_args=(-fsSL)
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
curl_args+=(-H "Authorization: token $GITHUB_TOKEN")
fi
local result
result=$(curl "${curl_args[@]}" "https://api.github.com/repos/${repo}/releases/latest" 2>/dev/null | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [[ -z "$result" ]]; then
log_error "Could not fetch latest release for $repo (rate limited or network error)"
exit 1
fi
echo "$result"
}
# Install system packages via apt
install_apt_packages() {
log_info "Installing system packages..."
export DEBIAN_FRONTEND=noninteractive
$SUDO apt-get update
# Fix any broken packages from previous runs before installing
$SUDO apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -f -y
$SUDO apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y --no-install-recommends \
sudo \
ca-certificates \
curl \
fish \
git \
openssh-client \
ripgrep \
fd-find \
fzf \
stow \
jq \
jo \
unzip \
xz-utils \
nodejs \
tmux \
wget
# Create fd symlink if it doesn't exist
if [[ -f /usr/bin/fdfind ]] && [[ ! -f /usr/local/bin/fd ]]; then
$SUDO ln -sf /usr/bin/fdfind /usr/local/bin/fd
fi
# Install ghostty terminfo for proper terminal support
if ! infocmp xterm-ghostty &>/dev/null; then
log_info "Installing ghostty terminfo..."
$SUDO tic -x - <<'TERMINFO'
xterm-ghostty|ghostty|Ghostty,
am, bce, ccc, hs, km, mc5i, mir, msgr, npc, xenl, AX, Su, Tc, XT, fullkbd,
colors#0x100, cols#80, it#8, lines#24, pairs#0x7fff,
acsc=++\,\,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
clear=\E[H\E[2J, cnorm=\E[?12l\E[?25h, cr=\r,
csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
cud=\E[%p1%dB, cud1=\n, cuf=\E[%p1%dC, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
cvvis=\E[?12;25h, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
dl=\E[%p1%dM, dl1=\E[M, dsl=\E]2;\007, ech=\E[%p1%dX,
ed=\E[J, el=\E[K, el1=\E[1K, flash=\E[?5h$<100/>\E[?5l,
fsl=^G, home=\E[H, hpa=\E[%i%p1%dG, ht=^I, hts=\EH,
ich=\E[%p1%d@, ich1=\E[@, il=\E[%p1%dL, il1=\E[L, ind=\n,
indn=\E[%p1%dS,
initc=\E]4;%p1%d;rgb:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
invis=\E[8m, kDC=\E[3;2~, kEND=\E[1;2F, kHOM=\E[1;2H,
kIC=\E[2;2~, kLFT=\E[1;2D, kNXT=\E[6;2~, kPRV=\E[5;2~,
kRIT=\E[1;2C, kbs=^?, kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB,
kcuf1=\EOC, kcuu1=\EOA, kdch1=\E[3~, kend=\EOF, kent=\EOM,
kf1=\EOP, kf10=\E[21~, kf11=\E[23~, kf12=\E[24~,
kf13=\E[1;2P, kf14=\E[1;2Q, kf15=\E[1;2R, kf16=\E[1;2S,
kf17=\E[15;2~, kf18=\E[17;2~, kf19=\E[18;2~, kf2=\EOQ,
kf20=\E[19;2~, kf21=\E[20;2~, kf22=\E[21;2~,
kf23=\E[23;2~, kf24=\E[24;2~, kf25=\E[1;5P, kf26=\E[1;5Q,
kf27=\E[1;5R, kf28=\E[1;5S, kf29=\E[15;5~, kf3=\EOR,
kf30=\E[17;5~, kf31=\E[18;5~, kf32=\E[19;5~,
kf33=\E[20;5~, kf34=\E[21;5~, kf35=\E[23;5~,
kf36=\E[24;5~, kf37=\E[1;6P, kf38=\E[1;6Q, kf39=\E[1;6R,
kf4=\EOS, kf40=\E[1;6S, kf41=\E[15;6~, kf42=\E[17;6~,
kf43=\E[18;6~, kf44=\E[19;6~, kf45=\E[20;6~,
kf46=\E[21;6~, kf47=\E[23;6~, kf48=\E[24;6~,
kf49=\E[1;3P, kf5=\E[15~, kf50=\E[1;3Q, kf51=\E[1;3R,
kf52=\E[1;3S, kf53=\E[15;3~, kf54=\E[17;3~,
kf55=\E[18;3~, kf56=\E[19;3~, kf57=\E[20;3~,
kf58=\E[21;3~, kf59=\E[23;3~, kf6=\E[17~, kf60=\E[24;3~,
kf61=\E[1;4P, kf62=\E[1;4Q, kf63=\E[1;4R, kf7=\E[18~,
kf8=\E[19~, kf9=\E[20~, khome=\EOH, kich1=\E[2~,
kind=\E[1;2B, kmous=\E[<, knp=\E[6~, kpp=\E[5~,
kri=\E[1;2A, oc=\E]104\007, op=\E[39;49m, rc=\E8,
rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, ri=\EM,
rin=\E[%p1%dT, ritm=\E[23m, rmacs=\E(B, rmam=\E[?7l,
rmcup=\E[?1049l, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[27m,
rmul=\E[24m, rs1=\E]\E\\\Ec, sc=\E7,
setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
sgr0=\E(B\E[m, sitm=\E[3m, smacs=\E(0, smam=\E[?7h,
smcup=\E[?1049h, smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m,
smul=\E[4m, tbc=\E[3g, tsl=\E]2;, u6=\E[%i%d;%dR, u7=\E[6n,
u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd,
BD=\E[?2004l, BE=\E[?2004h, Clmg=\E[s,
Cmg=\E[%i%p1%d;%p2%ds, Dsmg=\E[?69l, E3=\E[3J,
Enmg=\E[?69h, Ms=\E]52;%p1%s;%p2%s\007, PE=\E[201~,
PS=\E[200~, RV=\E[>c, Se=\E[2 q,
Setulc=\E[58:2::%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%d%;m,
Smulx=\E[4:%p1%dm, Ss=\E[%p1%d q,
Sync=\E[?2026%?%p1%{1}%-%tl%eh%;,
XM=\E[?1006;1000%?%p1%{1}%=%th%el%;, XR=\E[>0q,
fd=\E[?1004l, fe=\E[?1004h, kDC3=\E[3;3~, kDC4=\E[3;4~,
kDC5=\E[3;5~, kDC6=\E[3;6~, kDC7=\E[3;7~, kDN=\E[1;2B,
kDN3=\E[1;3B, kDN4=\E[1;4B, kDN5=\E[1;5B, kDN6=\E[1;6B,
kDN7=\E[1;7B, kEND3=\E[1;3F, kEND4=\E[1;4F,
kEND5=\E[1;5F, kEND6=\E[1;6F, kEND7=\E[1;7F,
kHOM3=\E[1;3H, kHOM4=\E[1;4H, kHOM5=\E[1;5H,
kHOM6=\E[1;6H, kHOM7=\E[1;7H, kIC3=\E[2;3~, kIC4=\E[2;4~,
kIC5=\E[2;5~, kIC6=\E[2;6~, kIC7=\E[2;7~, kLFT3=\E[1;3D,
kLFT4=\E[1;4D, kLFT5=\E[1;5D, kLFT6=\E[1;6D,
kLFT7=\E[1;7D, kNXT3=\E[6;3~, kNXT4=\E[6;4~,
kNXT5=\E[6;5~, kNXT6=\E[6;6~, kNXT7=\E[6;7~,
kPRV3=\E[5;3~, kPRV4=\E[5;4~, kPRV5=\E[5;5~,
kPRV6=\E[5;6~, kPRV7=\E[5;7~, kRIT3=\E[1;3C,
kRIT4=\E[1;4C, kRIT5=\E[1;5C, kRIT6=\E[1;6C,
kRIT7=\E[1;7C, kUP=\E[1;2A, kUP3=\E[1;3A, kUP4=\E[1;4A,
kUP5=\E[1;5A, kUP6=\E[1;6A, kUP7=\E[1;7A, kxIN=\E[I,
kxOUT=\E[O, rmxx=\E[29m, rv=\E\\[[0-9]+;[0-9]+;[0-9]+c,
setrgbb=\E[48:2:%p1%d:%p2%d:%p3%dm,
setrgbf=\E[38:2:%p1%d:%p2%d:%p3%dm, smxx=\E[9m,
xm=\E[<%i%p3%d;%p1%d;%p2%d;%?%p4%tM%em%;,
xr=\EP>\\|[ -~]+a\E\\,
TERMINFO
log_success "Ghostty terminfo installed"
fi
# Set fish as default shell
if has_cmd fish; then
local fish_path
fish_path=$(command -v fish)
local current_user
current_user=$(whoami)
local current_shell
current_shell=$(getent passwd "$current_user" | cut -d: -f7)
if [[ "$current_shell" != "$fish_path" ]]; then
log_info "Setting fish as default shell..."
$SUDO chsh -s "$fish_path" "$current_user"
log_success "Fish set as default shell"
fi
fi
log_success "System packages installed"
}
# Install Google Chrome for headless browsing
install_google_chrome() {
if has_cmd google-chrome || has_cmd google-chrome-stable; then
log_success "Google Chrome already installed"
return
fi
log_info "Installing Google Chrome..."
local tmpfile
tmpfile=$(mktemp --suffix=.deb)
curl -fsSL "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" -o "$tmpfile"
# dpkg will fail on missing deps, then apt-get -f install resolves them
export DEBIAN_FRONTEND=noninteractive
$SUDO dpkg -i "$tmpfile" || true
$SUDO apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -f -y
rm "$tmpfile"
if has_cmd google-chrome || has_cmd google-chrome-stable; then
log_success "Google Chrome installed"
else
log_error "Google Chrome installation failed"
return 1
fi
}
# Install eza (ls replacement)
install_eza() {
local current_version=""
if has_cmd eza; then
current_version=$(eza --version | head -1 | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "eza-community/eza") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$latest_tag" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "eza $current_version already installed (latest)"
return
fi
log_info "Installing eza $version..."
local eza_arch
case "$ARCH" in
x86_64) eza_arch="x86_64-unknown-linux-gnu" ;;
aarch64) eza_arch="aarch64-unknown-linux-gnu" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/eza-community/eza/releases/download/${latest_tag}/eza_${eza_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local/bin --strip-components=0
log_success "eza $version installed"
}
# Install jj (jujutsu VCS)
install_jj() {
local current_version=""
if has_cmd jj; then
current_version=$(jj --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "jj-vcs/jj") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "jj $current_version already installed (latest)"
return
fi
log_info "Installing jj $version..."
local jj_arch
case "$ARCH" in
x86_64) jj_arch="x86_64-unknown-linux-musl" ;;
aarch64) jj_arch="aarch64-unknown-linux-musl" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/jj-vcs/jj/releases/download/${latest_tag}/jj-${latest_tag}-${jj_arch}.tar.gz" \
| $SUDO tar -xzf - -C /usr/local/bin --strip-components=1 ./jj
log_success "jj $version installed"
}
# Install deno runtime
install_deno() {
local current_version=""
if has_cmd deno; then
current_version=$(deno --version | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "denoland/deno") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "deno $current_version already installed (latest)"
return
fi
log_info "Installing deno $version..."
local deno_arch
case "$ARCH" in
x86_64) deno_arch="x86_64-unknown-linux-gnu" ;;
aarch64) deno_arch="aarch64-unknown-linux-gnu" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
local tmpfile
tmpfile=$(mktemp)
curl -fsSL "https://github.com/denoland/deno/releases/download/${latest_tag}/deno-${deno_arch}.zip" -o "$tmpfile"
$SUDO unzip -q -o "$tmpfile" -d /usr/local/bin
rm "$tmpfile"
$SUDO chmod +x /usr/local/bin/deno
log_success "deno $version installed"
}
# Install just command runner
install_just() {
local current_version=""
if has_cmd just; then
current_version=$(just --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "casey/just") || return 0
local version="${latest_tag}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "just $current_version already installed (latest)"
return
fi
log_info "Installing just $version..."
local just_arch
case "$ARCH" in
x86_64) just_arch="x86_64-unknown-linux-musl" ;;
aarch64) just_arch="aarch64-unknown-linux-musl" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/casey/just/releases/download/${latest_tag}/just-${version}-${just_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local/bin just
log_success "just $version installed"
}
# Install GitHub CLI
install_gh() {
local current_version=""
if has_cmd gh; then
current_version=$(gh --version | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "cli/cli") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "gh $current_version already installed (latest)"
return
fi
log_info "Installing gh $version..."
local gh_arch
case "$ARCH" in
x86_64) gh_arch="linux_amd64" ;;
aarch64) gh_arch="linux_arm64" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/cli/cli/releases/download/${latest_tag}/gh_${version}_${gh_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local/bin --strip-components=2 "gh_${version}_${gh_arch}/bin/gh"
log_success "gh $version installed"
}
# Install Heroku CLI
install_heroku() {
if has_cmd heroku; then
log_success "Heroku CLI already installed"
return
fi
log_info "Installing Heroku CLI..."
curl -fsSL https://cli-assets.heroku.com/install.sh | $SUDO sh
log_success "Heroku CLI installed"
}
# Install git-delta
install_delta() {
local current_version=""
if has_cmd delta; then
current_version=$(delta --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "dandavison/delta") || return 0
local version="${latest_tag}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "delta $current_version already installed (latest)"
return
fi
log_info "Installing delta $version..."
local delta_arch
case "$ARCH" in
x86_64) delta_arch="x86_64-unknown-linux-musl" ;;
aarch64) delta_arch="aarch64-unknown-linux-gnu" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/dandavison/delta/releases/download/${version}/delta-${version}-${delta_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local/bin --strip-components=1 "delta-${version}-${delta_arch}/delta"
log_success "delta $version installed"
}
# Install sd (sed alternative)
install_sd() {
local current_version=""
if has_cmd sd; then
current_version=$(sd --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "chmln/sd") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "sd $current_version already installed (latest)"
return
fi
log_info "Installing sd $version..."
local sd_arch
case "$ARCH" in
x86_64) sd_arch="x86_64-unknown-linux-musl" ;;
aarch64) sd_arch="aarch64-unknown-linux-musl" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/chmln/sd/releases/download/${latest_tag}/sd-${latest_tag}-${sd_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local/bin --strip-components=1 "sd-${latest_tag}-${sd_arch}/sd"
log_success "sd $version installed"
}
# Install starship prompt
install_starship() {
local current_version=""
if has_cmd starship; then
current_version=$(starship --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "starship/starship") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "starship $current_version already installed (latest)"
return
fi
log_info "Installing starship $version..."
local starship_arch
case "$ARCH" in
x86_64) starship_arch="x86_64-unknown-linux-musl" ;;
aarch64) starship_arch="aarch64-unknown-linux-musl" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/starship/starship/releases/download/${latest_tag}/starship-${starship_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local/bin starship
log_success "starship $version installed"
}
# Install changelog tool
install_changelog() {
local current_version=""
if has_cmd changelog; then
current_version=$(changelog --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "schpet/changelog") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "changelog $current_version already installed (latest)"
return
fi
log_info "Installing changelog $version..."
local changelog_arch
case "$ARCH" in
x86_64) changelog_arch="x86_64-unknown-linux-gnu" ;;
aarch64) changelog_arch="aarch64-unknown-linux-gnu" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/schpet/changelog/releases/download/${latest_tag}/changelog-${changelog_arch}.tar.xz" \
| $SUDO tar -xJ -C /usr/local/bin --strip-components=1 "changelog-${changelog_arch}/changelog"
log_success "changelog $version installed"
}
# Install svbump tool
install_svbump() {
local current_version=""
if has_cmd svbump; then
current_version=$(svbump --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "schpet/svbump") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "svbump $current_version already installed (latest)"
return
fi
log_info "Installing svbump $version..."
local svbump_arch
case "$ARCH" in
x86_64) svbump_arch="x86_64-unknown-linux-gnu" ;;
aarch64) svbump_arch="aarch64-unknown-linux-gnu" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/schpet/svbump/releases/download/${latest_tag}/svbump-${svbump_arch}.tar.xz" \
| $SUDO tar -xJ -C /usr/local/bin --strip-components=1 "svbump-${svbump_arch}/svbump"
log_success "svbump $version installed"
}
# Install atuin (shell history)
install_atuin() {
local current_version=""
if has_cmd atuin; then
current_version=$(atuin --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "atuinsh/atuin") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "atuin $current_version already installed (latest)"
return
fi
log_info "Installing atuin $version..."
local atuin_arch
case "$ARCH" in
x86_64) atuin_arch="x86_64-unknown-linux-gnu" ;;
aarch64) atuin_arch="aarch64-unknown-linux-gnu" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/atuinsh/atuin/releases/download/${latest_tag}/atuin-${atuin_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local/bin --strip-components=1 "atuin-${atuin_arch}/atuin"
log_success "atuin $version installed"
}
# Install direnv
install_direnv() {
local current_version=""
if has_cmd direnv; then
current_version=$(direnv --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "direnv/direnv") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "direnv $current_version already installed (latest)"
return
fi
log_info "Installing direnv $version..."
local direnv_arch
case "$ARCH" in
x86_64) direnv_arch="linux-amd64" ;;
aarch64) direnv_arch="linux-arm64" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/direnv/direnv/releases/download/${latest_tag}/direnv.${direnv_arch}" \
-o /tmp/direnv
$SUDO install -m 755 /tmp/direnv /usr/local/bin/direnv
rm /tmp/direnv
log_success "direnv $version installed"
}
# Install fnm (Fast Node Manager)
install_fnm() {
local current_version=""
if has_cmd fnm; then
current_version=$(fnm --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "Schniz/fnm") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "fnm $current_version already installed (latest)"
return
fi
log_info "Installing fnm $version..."
local fnm_arch
case "$ARCH" in
x86_64) fnm_arch="linux" ;;
aarch64) fnm_arch="arm64" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
local tmpfile
tmpfile=$(mktemp)
curl -fsSL "https://github.com/Schniz/fnm/releases/download/${latest_tag}/fnm-${fnm_arch}.zip" -o "$tmpfile"
$SUDO unzip -q -o "$tmpfile" -d /usr/local/bin
rm "$tmpfile"
$SUDO chmod +x /usr/local/bin/fnm
log_success "fnm $version installed"
# Add fnm to fish PATH if fish is installed
if has_cmd fish; then
local fish_config_dir="${HOME}/.config/fish/conf.d"
mkdir -p "$fish_config_dir"
cat > "${fish_config_dir}/fnm.fish" <<'FISHCONFIG'
# fnm (Fast Node Manager) setup
set -gx FNM_DIR $HOME/.local/share/fnm
if type -q fnm
fnm env --use-on-cd --shell fish | source
end
FISHCONFIG
log_info "Added fnm to fish config"
fi
# Set up fnm directories and install Node.js LTS
export FNM_DIR="${HOME}/.local/share/fnm"
mkdir -p "$FNM_DIR"
# Initialize fnm for current shell
eval "$(fnm env --shell bash)"
if ! fnm list 2>/dev/null | grep -q "lts"; then
log_info "Installing Node.js LTS via fnm..."
fnm install --lts
fnm default lts-latest
log_success "Node.js LTS installed"
else
log_success "Node.js LTS already installed"
fi
}
# Install neovim
install_neovim() {
local current_version=""
if has_cmd nvim; then
current_version=$(nvim --version | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "neovim/neovim") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "neovim $current_version already installed (latest)"
return
fi
log_info "Installing neovim $version..."
local nvim_arch
case "$ARCH" in
x86_64) nvim_arch="linux-x86_64" ;;
aarch64) nvim_arch="linux-arm64" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
curl -fsSL "https://github.com/neovim/neovim/releases/download/${latest_tag}/nvim-${nvim_arch}.tar.gz" \
| $SUDO tar -xz -C /usr/local --strip-components=1
log_success "neovim $version installed"
}
# Install zellij terminal multiplexer
install_zellij() {
local current_version=""
if has_cmd zellij; then
current_version=$(zellij --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "")
fi
local latest_tag
latest_tag=$(get_latest_release "zellij-org/zellij") || return 0
local version="${latest_tag#v}"
if [[ "$current_version" == "$version" ]] && [[ -z "${FORCE_UPDATE:-}" ]]; then
log_success "zellij $current_version already installed (latest)"
return
fi
log_info "Installing zellij $version..."
local zellij_arch
case "$ARCH" in
x86_64) zellij_arch="x86_64-unknown-linux-musl" ;;
aarch64) zellij_arch="aarch64-unknown-linux-musl" ;;
*) log_error "Unsupported architecture: $ARCH"; return 1 ;;
esac
local tmpdir
tmpdir=$(mktemp -d)
curl -fsSL "https://github.com/zellij-org/zellij/releases/download/${latest_tag}/zellij-${zellij_arch}.tar.gz" \
-o "$tmpdir/zellij.tar.gz"
tar -xzf "$tmpdir/zellij.tar.gz" -C "$tmpdir"
$SUDO mv "$tmpdir/zellij" /usr/local/bin/
rm -rf "$tmpdir"
$SUDO chmod +x /usr/local/bin/zellij
log_success "zellij $version installed"
}
# Install Claude Code CLI
install_claude_code() {
if has_cmd claude; then
log_success "Claude Code already installed (run 'claude update' to update)"
return
fi
log_info "Installing Claude Code CLI..."
curl -fsSL https://claude.ai/install.sh | bash || log_warn "Claude Code install had issues"
# Add to PATH for current session
export PATH="${HOME}/.local/bin:${PATH}"
log_success "Claude Code CLI installed"
}
# Install Claude Code plugins
install_claude_plugins() {
if ! has_cmd claude; then
log_warn "Claude Code not installed, skipping plugins"
return
fi
log_info "Installing Claude Code plugins..."
claude plugin marketplace add schpet/toolbox 2>/dev/null || true
claude plugin marketplace add anthropics/claude-plugins-official 2>/dev/null || true
claude plugin marketplace add schpet/linear-cli 2>/dev/null || true
claude plugin install jj-vcs@toolbox 2>/dev/null || true
claude plugin install changelog@toolbox 2>/dev/null || true
claude plugin install svbump@toolbox 2>/dev/null || true
claude plugin install chores@toolbox 2>/dev/null || true
claude plugin install speccer@toolbox 2>/dev/null || true
claude plugin install ralph-loop@claude-plugins-official 2>/dev/null || true
claude plugin install linear-cli@linear-cli 2>/dev/null || true
log_info "Configuring MCP servers..."
# Configure chrome-devtools-mcp to connect to a running Chromium instance
# The start-chromium script (installed below) handles launching Chromium with remote debugging
claude mcp remove chrome-devtools 2>/dev/null || true
claude mcp add --scope user chrome-devtools -- npx chrome-devtools-mcp@latest --browserUrl http://127.0.0.1:9222 2>/dev/null || true
log_success "Claude Code plugins and MCP servers configured"
}
# Fix Claude Code plugin JSON files
# Claude Code hangs if these files exist but are empty (0 bytes)
# This ensures they contain valid JSON
fix_claude_plugin_json_files() {
local plugins_dir="${HOME}/.claude/plugins"
if [[ ! -d "$plugins_dir" ]]; then
return
fi
log_info "Ensuring Claude plugin JSON files have valid content..."
for json_file in known_marketplaces.json installed_plugins.json install-counts-cache.json; do
local file_path="${plugins_dir}/${json_file}"
if [[ -f "$file_path" ]] && [[ ! -s "$file_path" ]]; then
# File exists but is empty - fix it
echo "{}" > "$file_path"
log_info "Fixed empty file: $file_path"
fi
done
log_success "Claude plugin JSON files validated"
}
# Install start-chromium helper script
install_start_chromium() {
log_info "Installing start-chromium helper..."
$SUDO tee /usr/local/bin/start-chromium > /dev/null << 'SCRIPT'
#!/bin/bash
# Start Chrome/Chromium with remote debugging for chrome-devtools-mcp
# Usage: start-chromium [--kill] [--status]
if [[ "$1" == "--kill" ]]; then
pkill -f "remote-debugging-port=9222" 2>/dev/null && echo "Killed browser" || echo "No browser running"
exit 0
fi
if [[ "$1" == "--status" ]]; then
if curl -s http://127.0.0.1:9222/json/version >/dev/null 2>&1; then
echo "Browser running on port 9222"
curl -s http://127.0.0.1:9222/json/version | jq -r '.Browser' 2>/dev/null || true
exit 0
else
echo "No browser running on port 9222"
exit 1
fi
fi
# Kill any existing instance
pkill -f "remote-debugging-port=9222" 2>/dev/null || true
sleep 1
# Find browser binary (prefer Google Chrome, fall back to Chromium)
BROWSER=""
for bin in /usr/bin/google-chrome-stable /usr/bin/google-chrome /usr/bin/chromium-browser /usr/bin/chromium /snap/bin/chromium; do
if [[ -x "$bin" ]]; then
BROWSER="$bin"
break
fi
done
if [[ -z "$BROWSER" ]]; then
echo "Error: No browser found (google-chrome or chromium)"
echo "Install with: sudo apt-get install -y google-chrome-stable"
exit 1
fi
echo "Starting $BROWSER in headless mode..."
# Start browser in headless mode with remote debugging
# These flags are required for running without a display in containers
"$BROWSER" \
--headless \
--no-sandbox \
--disable-gpu \
--disable-software-rasterizer \
--disable-dev-shm-usage \
--remote-debugging-port=9222 \
--remote-debugging-address=127.0.0.1 \
>/dev/null 2>&1 &
# Wait for it to start
for i in {1..10}; do
if curl -s http://127.0.0.1:9222/json/version >/dev/null 2>&1; then
echo "Browser started with remote debugging on port 9222"
curl -s http://127.0.0.1:9222/json/version | jq -r '.Browser' 2>/dev/null || true
exit 0
fi
sleep 0.5
done
echo "Error: Browser failed to start"
exit 1
SCRIPT
$SUDO chmod +x /usr/local/bin/start-chromium
log_success "start-chromium helper installed"
}
# Install dotfiles
install_dotfiles() {
local dotfiles_dir="${HOME}/dotfiles"
if [[ -d "$dotfiles_dir" ]]; then
log_info "Updating dotfiles..."
cd "$dotfiles_dir"
git pull --ff-only || log_warn "Could not update dotfiles"
else
log_info "Cloning dotfiles..."
git clone --depth 1 https://github.com/schpet/dotfiles.git "$dotfiles_dir"
fi
log_info "Installing dotfiles with stow..."
cd "$dotfiles_dir"
# --adopt moves existing files into dotfiles dir, then we restore from git
# This ensures dotfiles always win over pre-existing system config
stow . -t "$HOME" -v 2 --adopt 2>&1 || log_warn "Stow had some issues (this may be normal)"
git checkout . 2>/dev/null || true
log_success "Dotfiles installed"
}
# Install deno tools (gogreen, easy-bead-oven)
install_deno_tools() {
local tools_dir="${HOME}/tools"
mkdir -p "$tools_dir"
# gogreen
local gogreen_dir="${tools_dir}/gogreen"
if [[ -d "$gogreen_dir" ]]; then
log_info "Updating gogreen..."
cd "$gogreen_dir"
git pull --ff-only || log_warn "Could not update gogreen"
else
log_info "Installing gogreen..."
git clone --depth 1 https://github.com/schpet/gogreen.git "$gogreen_dir"
fi
cd "$gogreen_dir"
just install || log_warn "gogreen install had issues"
# easy-bead-oven
local ebo_dir="${tools_dir}/easy-bead-oven"
if [[ -d "$ebo_dir" ]]; then
log_info "Updating easy-bead-oven..."
cd "$ebo_dir"
git pull --ff-only || log_warn "Could not update easy-bead-oven"
else
log_info "Installing easy-bead-oven..."
git clone --depth 1 https://github.com/schpet/easy-bead-oven.git "$ebo_dir"
fi
cd "$ebo_dir"
deno install -c ./deno.json -A -g -f -n ebo ./main.ts || log_warn "ebo install had issues"
# linear-cli
local linear_dir="${tools_dir}/linear-cli"
if [[ -d "$linear_dir" ]]; then
log_info "Updating linear-cli..."
cd "$linear_dir"
git pull --ff-only || log_warn "Could not update linear-cli"
else
log_info "Installing linear-cli..."
git clone --depth 1 https://github.com/schpet/linear-cli.git "$linear_dir"
fi
cd "$linear_dir"
deno task install || log_warn "linear-cli install had issues"
log_success "Deno tools installed"
}
# Clone cracked repo for easy development
install_cracked_repo() {
local tools_dir="${HOME}/tools"
mkdir -p "$tools_dir"
local cracked_dir="${tools_dir}/cracked"
if [[ -d "$cracked_dir" ]]; then
log_info "Updating cracked repo..."
cd "$cracked_dir"
git pull --ff-only || log_warn "Could not update cracked"
else
log_info "Cloning cracked repo..."
git clone --depth 1 https://github.com/schpet/cracked.git "$cracked_dir"
fi
log_success "Cracked repo available at ~/tools/cracked"
}
# ============================================================================
# Language-specific environments
# ============================================================================
# Install Deno environment (user-local via official installer)
setup_deno_env() {
log_info "Setting up Deno environment..."
export DENO_INSTALL="${HOME}/.deno"
if [[ -f "${DENO_INSTALL}/bin/deno" ]]; then
log_info "Updating Deno..."
fi
curl -fsSL https://deno.land/install.sh | sh
# Add to PATH for this session
export PATH="${DENO_INSTALL}/bin:${PATH}"
log_success "Deno environment ready"
deno --version
}
# Install Rust environment
setup_rust_env() {
log_info "Setting up Rust environment..."
# Install build dependencies
export DEBIAN_FRONTEND=noninteractive