Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·1266 lines (1135 loc) · 41.9 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·1266 lines (1135 loc) · 41.9 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
os=$(uname -s | tr '[:upper:]' '[:lower:]' | sed 's,^darwin$,macos,') # macos or linux
install_from_package_manager() {
if declare -f "install_$1_package" >/dev/null; then
"install_$1_package" "$2"
elif command -v brew &>/dev/null; then
brew install "$1"
elif command -v yay; then # endeavoros
sudo yay -S --noconfirm "$1"
elif command -v pacman; then # arch
sudo pacman -S --noconfirm "$1"
elif command -v dnf; then
sudo dnf install -y "$1"
elif command -v apt-get; then
sudo apt-get install -y "$1"
else
exit 1
fi
}
package_manager_semver() {
if command -v brew &>/dev/null; then
(brew info "$1" | sed -n '1p' | parse_semver | sed -n '1p') || (echo "package $1 not found in brew" >&2 && return 1)
elif command -v yay &>/dev/null; then
yay -Qi "$1" | parse_semver || (echo "package $1 not found in yay" && return 1)
elif command -v pacman &>/dev/null; then
pacman -Qi "$1" | parse_semver || (echo "package $1 not found in pacman" && return 1)
elif command -v dnf &>/dev/null; then
(dnf --cacheonly info "$1" 2>/dev/null | grep "^Version" | parse_semver | head -n1) || return 1
elif command -v apt-get &>/dev/null; then
apt_package_semver "$1"
else
exit 1
fi
}
apt_package_semver() {
apt-cache policy "$1" 2>/dev/null |
awk '$1 == "Candidate:" { print $2 }' | parse_semver | head -n1
}
package_semver() {
if declare -f "$1_package_semver" >/dev/null; then
"$1_package_semver" || (echo "Failed to get semver for based on custom script: $1" >&2 && return 1)
else
package_manager_semver "$1" || (echo "Failed to get semver for: $1" >&2 && return 1)
fi
}
install_imagemagick_package() {
# NOTE: ImageMagick 6 provides convert; version 7 provides magick.
if command -v magick >/dev/null || command -v convert >/dev/null; then
return 0
fi
if command -v brew >/dev/null; then
brew install imagemagick
elif command -v yay >/dev/null; then
sudo yay -S --noconfirm imagemagick
elif command -v pacman >/dev/null; then
sudo pacman -S --noconfirm imagemagick
elif command -v dnf >/dev/null; then
sudo dnf install -y ImageMagick
elif command -v apt-get >/dev/null; then
sudo apt-get install -y imagemagick
else
return 1
fi
}
install_fd_package() {
# Check if fd is already installed and working
if command -v fd &>/dev/null; then
echo "fd already installed, skipping package manager installation"
return 0
fi
if command -v brew &>/dev/null; then
brew install fd
elif command -v yay; then
sudo yay -S --noconfirm fd
elif command -v pacman; then
sudo pacman -S --noconfirm fd
elif command -v dnf; then
# For dnf systems, prefer cargo installation if there are conflicts
if rpm -qa | grep -q "^fd-"; then
echo "Existing fd package found, will install via cargo to avoid conflict"
return 1 # This will trigger the fallback to cargo installation
fi
sudo dnf install -y fd-find
elif command -v apt-get; then
sudo apt-get install -y fd-find
else
exit 1
fi
}
fd_package_semver() {
if command -v brew &>/dev/null; then
(brew info fd | head -n1 | parse_semver | head -n1) || (echo "package fd not found in brew" && return 1)
elif command -v yay &>/dev/null; then
yay -Qi fd | parse_semver || (echo "package fd not found in yay" && return 1)
elif command -v pacman &>/dev/null; then
pacman -Qi fd | parse_semver || (echo "package fd not found in pacman" && return 1)
elif command -v dnf &>/dev/null; then
(dnf --cacheonly info fd-find 2>/dev/null | grep "^Version" | parse_semver | head -n1) || return 1
elif command -v apt-get &>/dev/null; then
apt_package_semver fd-find
else
exit 1
fi
}
install_explicitly() {
if declare -f "install_$1_from_release" >/dev/null; then
echo "Installing $1 $2 from release"
"install_$1_from_release" "$2"
elif declare -f "install_$1_from_source" >/dev/null; then
echo "Installing $1 $2 from source"
"install_$1_from_source" "$2"
elif declare -f "install_$1_package" >/dev/null; then
"install_$1_package" "$2"
else
echo "Unable to install: $1" >&2
exit 1
fi
}
install_package() {
local package=$1
local version=$2
local package_version
package_version=$(package_semver "$package") || package_version=""
if [ -z "$package_version" ]; then
echo "$package is not found in package manager"
elif semver_ge "$package_version" "$version"; then
echo "$package $package_version is available in package manager"
if install_from_package_manager "$package" "$version"; then
local installed
installed=$(installed_semver "$package") || installed=""
if [ -n "$installed" ] && semver_ge "$installed" "$version"; then
return 0
fi
fi
else
echo "$package needs to be explicitly upgraded '$package_version' < '$version'"
fi
# Otherwise, install the package explicitly
install_explicitly "$package" "$version" || (echo "Failed to install: $package" && exit 1)
}
install_gh_package() {
if command -v dnf &>/dev/null; then
sudo dnf install 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh --repo gh-cli -y
elif command -v brew &>/dev/null; then
brew install gh
elif command -v yay &>/dev/null; then
sudo yay -S --noconfirm github-cli
elif command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm github-cli
elif command -v apt-get &>/dev/null; then
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
else
echo "No supported package manager found for gh installation"
exit 1
fi
# Check if gh is authenticated
setup_gh_auth
}
setup_gh_auth() {
if ! command -v gh &>/dev/null; then
echo "gh command not found, skipping authentication setup"
return 0
fi
# Check if already authenticated
if gh auth status &>/dev/null; then
echo "GitHub CLI already authenticated"
install_gh_extensions
else
echo ""
echo "🔐 GitHub CLI is not authenticated yet."
echo "To use GitHub CLI features and install extensions, you need to authenticate."
echo ""
echo "Run the following command when you're ready:"
echo " gh auth login"
echo ""
echo "After authentication, you can install useful extensions:"
echo " gh extension install github/gh-copilot"
echo " gh extension install https://github.com/github/gh-models"
echo ""
# Ask if user wants to authenticate now
if [ -t 0 ]; then # Check if running interactively
read -p "Would you like to authenticate with GitHub now? (y/n): " -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
gh auth login && install_gh_extensions
fi
fi
fi
}
install_gh_extensions() {
echo "Installing GitHub CLI extensions..."
# Install copilot extension if not already installed
if gh copilot --help >/dev/null 2>&1; then
echo "GitHub Copilot already available"
elif ! gh extension list | grep -q "github/gh-copilot"; then
gh extension install github/gh-copilot || echo "Failed to install gh-copilot extension"
else
echo "gh-copilot extension already installed"
fi
# Install models extension if not already installed
if ! gh extension list | grep -q "github/gh-models"; then
gh extension install https://github.com/github/gh-models || echo "Failed to install gh-models extension"
else
echo "gh-models extension already installed"
fi
}
semver_ge() {
local installed_version="$1"
local required_version="$2"
# Split versions into components - more compatible approach
local installed_major installed_minor installed_patch
local required_major required_minor required_patch
# Parse installed version
IFS=. read -r installed_major installed_minor installed_patch <<< "$installed_version"
# Parse required version
IFS=. read -r required_major required_minor required_patch <<< "$required_version"
# Set defaults for missing components
installed_major=${installed_major:-0}
installed_minor=${installed_minor:-0}
installed_patch=${installed_patch:-0}
required_major=${required_major:-0}
required_minor=${required_minor:-0}
required_patch=${required_patch:-0}
# Convert to numbers and compare
if [ "$installed_major" -gt "$required_major" ]; then
return 0
elif [ "$installed_major" -lt "$required_major" ]; then
return 1
elif [ "$installed_minor" -gt "$required_minor" ]; then
return 0
elif [ "$installed_minor" -lt "$required_minor" ]; then
return 1
elif [ "$installed_patch" -ge "$required_patch" ]; then
return 0
else
return 1
fi
}
install_glibc() {
local version=$1
# Download glibc 2.29
curl -fLO "https://ftp.gnu.org/gnu/glibc/glibc-$version.tar.gz"
# Download glibc 2.29 checksum
curl -fLO "https://ftp.gnu.org/gnu/glibc/glibc-$version.tar.gz.sig"
# Import the glibc PGP key
# gpg --keyserver keys.gnupg.net --recv-keys 16792B4EA25340F8
# PGP verify the checksum
gpg --verify "glibc-$version.tar.gz.sig"
tar -zxvf glibc-"$version".tar.gz
mkdir -p glibc-"$version"/build
cd glibc-"$version"/build || exit 1
../configure --prefix=/opt/glibc
make
sudo make install
}
install_neovim_from_source() (
mkdir -p "$HOME/src/oss"
if [ ! -d ~/src/oss/neovim ]; then
git clone https://github.com/neovim/neovim.git ~/src/oss/neovim --depth 1
fi
git -C ~/src/oss/neovim fetch --tags --force --prune || exit 1
git -C ~/src/oss/neovim checkout "v$1" || exit 1
cd ~/src/oss/neovim || exit 1
make clean
rm -rf .deps/
make install CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX="$HOME/.local"
)
# WARN: installing glibc makes this more like a dentist visit
# install_neovim_from_release() {
# # Pull latest neovim binary from the latest github release
# curl -fLO "https://github.com/neovim/neovim/releases/latest/download/nvim-$distro.tar.gz"
# # Also download the checksum file
# curl -fLO "https://github.com/neovim/neovim/releases/latest/download/nvim-$distro.tar.gz.sha256sum"
# # Verify the checksum
# sha256sum -c "nvim-$distro.tar.gz.sha256sum"
#
# # Extract the binary
# tar xzf "nvim-$distro.tar.gz"
#
# # Link the binary to ~/.local/bin
# ln -fs "$(pwd)/nvim-$distro/bin/nvim" "$HOME/.local/bin/nvim"
#
# if [ "$os" = "linux" ]; then
# # If bison isn't available, install it
# if ! command -v bison &>/dev/null; then
# install_package bison
# fi
#
# # install glibc if not installed or if version is not 2.29
# if getconf GNU_LIBC_VERSION | grep -q "glibc 2.29"; then
# echo "glibc is installed"
# else
# install_glibc "2.29"
# fi
# fi
# }
parse_semver() {
grep -Eo '[0-9]+\.[0-9]+(\.[0-9]+)?'
}
current_heuristic_semver() {
("$1" --version | parse_semver | head -n1) 2>/dev/null || return 1
}
neovim_current_semver() {
nvim --version 2>/dev/null | head -n1 | parse_semver | head -n1
}
ripgrep_current_semver() {
rg --version 2>/dev/null | head -n1 | parse_semver | head -n1
}
skim_current_semver() {
sk --version 2>/dev/null | parse_semver
}
git-delta_current_semver() {
delta --version 2>/dev/null | parse_semver
}
git-crypt_current_semver() {
git-crypt version 2>/dev/null | parse_semver | head -n1
}
go_current_semver() {
go version | parse_semver | head -n1
}
node_current_semver() {
node --version 2>/dev/null | sed 's/^v//' | parse_semver
}
cargo_current_semver() {
cargo --version 2>/dev/null | parse_semver | head -n1
}
rust_current_semver() {
rustc --version 2>/dev/null | parse_semver | head -n1
}
install_go_package() {
if command -v dnf &>/dev/null; then
sudo dnf install -y golang
# Refresh PATH to pick up go
export PATH=$PATH:/usr/bin
hash -r
elif command -v yay &>/dev/null; then
sudo yay -S --noconfirm go
elif command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm go
elif command -v apt-get &>/dev/null; then
sudo apt-get install -y golang-go
elif command -v brew &>/dev/null; then
brew install go
else
# Install from source as fallback
install_go_from_release "$1"
fi
}
install_go_from_release() (
local go_arch
case "$(uname -m)" in
x86_64) go_arch=amd64 ;;
arm64|aarch64) go_arch=arm64 ;;
*) echo "Unsupported Go architecture" >&2; exit 1 ;;
esac
local go_os
go_os=$(uname -s | tr '[:upper:]' '[:lower:]')
local go_root="$HOME/.local/share/go" go_target="$HOME/.local/share/go/$1"
mkdir -p "$go_root" "$HOME/.local/bin" || exit 1
if [ -x "$go_target/bin/go" ] && [ "$("$go_target/bin/go" version | parse_semver | head -n1)" = "$1" ]; then
ln -fs "$go_target/bin/go" "$HOME/.local/bin/go" || exit 1
ln -fs "$go_target/bin/gofmt" "$HOME/.local/bin/gofmt" || exit 1
exit 0
fi
local go_stage
go_stage=$(mktemp -d "$go_root/.install-XXXXXX") || exit 1
trap 'rm -rf "$go_stage"' EXIT
curl -fsSL "https://go.dev/dl/go$1.$go_os-$go_arch.tar.gz" -o "$go_stage/go.tar.gz" || exit 1
tar -xzf "$go_stage/go.tar.gz" -C "$go_stage" || exit 1
[ "$("$go_stage/go/bin/go" version | parse_semver | head -n1)" = "$1" ] || exit 1
if [ -e "$go_target" ]; then
mv "$go_target" "$go_stage/previous" || exit 1
fi
if ! mv "$go_stage/go" "$go_target"; then
[ ! -e "$go_stage/previous" ] || mv "$go_stage/previous" "$go_target"
exit 1
fi
ln -fs "$go_target/bin/go" "$HOME/.local/bin/go" || exit 1
ln -fs "$go_target/bin/gofmt" "$HOME/.local/bin/gofmt" || exit 1
)
install_glow_from_source() {
install_package_version go 1.22
go install github.com/charmbracelet/glow/v2@v"$1"
}
installed_semver() {
explicit_current_semver "$1" || current_heuristic_semver "$1" || go_binary_semver "$1"
}
go_binary_semver() {
local binary
binary=$(command -v "$1") || return 1
command -v go >/dev/null || return 1
go version -m "$binary" 2>/dev/null | awk '$1 == "mod" { print $3 }' | parse_semver | head -n1
}
explicit_current_semver() {
if declare -f "$1_current_semver" >/dev/null; then
"$1_current_semver"
else
return 1
fi
}
install_package_version() {
local package=$1
local min_version=$2
local preferred_version=${3:-$min_version}
local current_version
current_version=$(installed_semver "$package") || current_version=""
if [ -n "$current_version" ]; then
echo "Package $package is already installed at version $current_version <=> $min_version"
# check if current version is greater than or equal to min version
if semver_ge "$current_version" "$min_version"; then
# if current version is greater than or equal to min version, return
echo "$package $current_version >= $min_version"
return 0
fi
fi
# install package to preferred version
install_package "$package" "$preferred_version" || return 1
hash -r
current_version=$(installed_semver "$package") || current_version=""
if [ -z "$current_version" ] || ! semver_ge "$current_version" "$min_version"; then
echo "Failed to install $package >= $min_version (found ${current_version:-none})" >&2
return 1
fi
echo "Installed $package $current_version"
}
install_fzf_from_source() {
mkdir -p "$HOME/src/oss"
if [ -d ~/src/oss/fzf ]; then
git -C ~/src/oss/fzf fetch --tags --force
git -C ~/src/oss/fzf checkout -f "v$1"
else
git clone --depth 1 --branch "v$1" https://github.com/junegunn/fzf.git ~/src/oss/fzf
fi
~/src/oss/fzf/install --all --no-fish --key-bindings --completion --no-update-rc --xdg
ln -fs ~/src/oss/fzf/bin/fzf "$HOME/.local/bin/fzf"
}
install_ripgrep_from_release() {
cargo install ripgrep -q --locked --version "$1"
}
install_starship_from_release() {
cargo install starship -q --locked --version "$1"
}
load_dotfiles_config() {
local dotfiles_root resolved
dotfiles_root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || return 1
resolved=$(python3 "$dotfiles_root/scripts/dotfiles-config.py" --platform "$os" --format shell) || return 1
# The resolver validates the plan and shell-quotes every emitted value.
eval "$resolved"
}
install_zellij_runtime() {
# OSC 7501 is merged on main but absent from stable 0.45.1:
# https://github.com/zellij-org/zellij/pull/5734
# Pin lanej/zellij with our native fixes until a stable release includes both.
local dotfiles_root
dotfiles_root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || return 1
load_dotfiles_config || return 1
case "$DOTFILES_ZELLIJ_SOURCE" in
patched) bash "$dotfiles_root/scripts/install-zellij" ;;
main) install_zellij_from_main ;;
release) install_zellij_from_release 0.45.1 ;;
esac || return 1
python3 "$dotfiles_root/scripts/install-zellij-navigation.py" || return 1
if [ "$DOTFILES_ZELLIJ_SOURCE" != release ]; then
python3 "$dotfiles_root/scripts/install-zellij-command-prompt.py" || return 1
fi
}
install_zellij_from_main() (
# OSC 7501 is merged on main but absent from stable 0.45.1:
# https://github.com/zellij-org/zellij/pull/5734
# This is an explicit experimental choice; the local native fixes are not applied.
local zellij_revision=bf517077c848d91f75091f66d1996cfeb84f4732
local zellij_prefix="$HOME/.local/share/zellij-build/$zellij_revision" zellij_stage
if [ ! -x "$zellij_prefix/bin/zellij" ]; then
rustup toolchain install 1.95.0 --profile minimal || exit 1
cargo +1.95.0 install --locked --git https://github.com/zellij-org/zellij.git \
--rev "$zellij_revision" --root "$zellij_prefix" --bin zellij \
--no-default-features --features plugins_from_target,vendored_curl,web_server_capability \
zellij || exit 1
fi
"$zellij_prefix/bin/zellij" --version || exit 1
mkdir -p "$HOME/.local/bin" || exit 1
zellij_stage=$(mktemp "$HOME/.local/bin/.zellij-XXXXXX") || exit 1
trap 'rm -f "$zellij_stage"' EXIT
install -m 755 "$zellij_prefix/bin/zellij" "$zellij_stage" || exit 1
mv -f "$zellij_stage" "$HOME/.local/bin/zellij" || exit 1
)
install_zellij_from_release() (
local zellij_arch zellij_target zellij_stage zellij_url
case "$(uname -m)" in
x86_64) zellij_arch=x86_64 ;;
arm64|aarch64) zellij_arch=aarch64 ;;
*) echo "Unsupported Zellij architecture" >&2; exit 1 ;;
esac
case "$(uname -s)" in
Darwin) zellij_target="$zellij_arch-apple-darwin" ;;
Linux) zellij_target="$zellij_arch-unknown-linux-musl" ;;
*) echo "Unsupported Zellij OS" >&2; exit 1 ;;
esac
zellij_stage=$(mktemp -d) || exit 1
trap 'rm -rf "$zellij_stage"' EXIT
zellij_url="https://github.com/zellij-org/zellij/releases/download/v$1/zellij-$zellij_target.tar.gz"
curl -fsSL "$zellij_url" -o "$zellij_stage/zellij.tar.gz" || exit 1
curl -fsSL "${zellij_url%.tar.gz}.sha256sum" -o "$zellij_stage/release.sha256sum" || exit 1
tar --no-same-owner -xzf "$zellij_stage/zellij.tar.gz" -C "$zellij_stage" || exit 1
# Upstream checksums identify the extracted binary by its CI build path.
awk '$1 ~ /^[[:xdigit:]]+$/ && length($1) == 64 { print $1 " zellij"; exit }' \
"$zellij_stage/release.sha256sum" > "$zellij_stage/binary.sha256sum"
test -s "$zellij_stage/binary.sha256sum" || exit 1
cd "$zellij_stage" || exit 1
if command -v sha256sum >/dev/null; then
sha256sum -c binary.sha256sum || exit 1
else
shasum -a 256 -c binary.sha256sum || exit 1
fi
if [ "$(./zellij --version | parse_semver | head -n1)" != "$1" ]; then
echo "Zellij release does not report expected version $1" >&2
exit 1
fi
mkdir -p "$HOME/.local/bin" || exit 1
install -m 755 zellij "$HOME/.local/bin/zellij.new" || exit 1
mv -f "$HOME/.local/bin/zellij.new" "$HOME/.local/bin/zellij" || exit 1
)
install_btop_from_release() (
case "$os" in
macos) brew install btop; exit $? ;;
linux) ;;
*) echo "Unsupported btop OS: $os" >&2; exit 1 ;;
esac
local btop_arch btop_stage
case "$(uname -m)" in
x86_64) btop_arch=x86_64 ;;
arm64|aarch64) btop_arch=aarch64 ;;
*) echo "Unsupported btop architecture" >&2; exit 1 ;;
esac
btop_stage=$(mktemp -d) || exit 1
trap 'rm -rf "$btop_stage"' EXIT
curl -fsSL "https://github.com/aristocratos/btop/releases/download/v$1/btop-${btop_arch}-unknown-linux-musl.tar.gz" \
-o "$btop_stage/btop.tar.gz" || exit 1
tar -xzf "$btop_stage/btop.tar.gz" -C "$btop_stage" || exit 1
mkdir -p "$HOME/.local/bin" "$HOME/.local/share/btop/themes" || exit 1
cp "$btop_stage/btop/themes/"*.theme "$HOME/.local/share/btop/themes/" || exit 1
install -m 755 "$btop_stage/btop/bin/btop" "$HOME/.local/bin/btop" || exit 1
)
install_skim_from_release() {
cargo install skim -q --locked --version "$1"
}
install_git-delta_from_release() {
cargo install git-delta -q --locked --version "$1"
}
install_bat_from_release() {
cargo install bat -q --locked --version "$1"
}
install_fd_from_release() {
cargo install fd-find -q --locked --version "$1"
}
install_eza_from_release() {
cargo install eza -q --locked --version "$1"
}
install_shfmt_from_release() {
install_package_version go 1.22
go install mvdan.cc/sh/v3/cmd/shfmt@v3.10.0
}
install_node_from_release() {
# Download and install nvm:
local node_stage
node_stage=$(mktemp) || return 1
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh -o "$node_stage" ||
{ rm -f "$node_stage"; return 1; }
PROFILE=/dev/null bash "$node_stage" || { rm -f "$node_stage"; return 1; }
rm -f "$node_stage"
# Set up nvm environment - must be sourced fresh for new installation
export NVM_DIR="$HOME/.nvm"
# NOTE: NVM generates these files outside the repository.
# shellcheck disable=SC1091
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# shellcheck disable=SC1091
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Download and install Node.js:
nvm install "$1" || { echo "Failed to install node@$1 via nvm" >&2; return 1; }
nvm alias default "$1" || return 1
nvm use "$1" || return 1
# WHY: NVM can replace its PATH entry in place, behind another Node executable.
export PATH="$NVM_BIN:$PATH"
hash -r
# Verify installation is working
echo "Node installed: $(node --version 2>/dev/null || echo 'FAILED')"
echo "NPM installed: $(npm --version 2>/dev/null || echo 'FAILED')"
}
install_codex_from_release() {
install_package_version node 24 || return 1
npm install -g "@openai/codex@$1"
}
install_firstmate_release() (
local tool=$1 version=$2 release_os release_arch stage archive
case "$(uname -s)" in
Darwin) release_os=darwin ;;
Linux) release_os=linux ;;
*) echo "Unsupported Firstmate tool OS" >&2; exit 1 ;;
esac
case "$(uname -m)" in
arm64|aarch64) release_arch=arm64 ;;
x86_64|amd64) release_arch=amd64 ;;
*) echo "Unsupported Firstmate tool architecture" >&2; exit 1 ;;
esac
stage=$(mktemp -d) || exit 1
trap 'rm -rf "$stage"' EXIT
archive="$tool-v$version-$release_os-$release_arch.tar.gz"
local url="https://github.com/kunchenguid/$tool/releases/download/v$version"
curl -fsSL "$url/$archive" -o "$stage/$archive" || exit 1
curl -fsSL "$url/checksums.txt" -o "$stage/checksums.txt" || exit 1
awk -v archive="$archive" '$2 == archive { print }' "$stage/checksums.txt" > "$stage/selected.sha256"
test -s "$stage/selected.sha256" || exit 1
cd "$stage" || exit 1
if command -v sha256sum >/dev/null; then
sha256sum -c selected.sha256 || exit 1
else
shasum -a 256 -c selected.sha256 || exit 1
fi
tar -xzf "$archive" || exit 1
if ! "./$tool" --version; then
if [ "$tool" != treehouse ] || [ "$release_os" != linux ]; then
echo "Downloaded $tool cannot run on this host" >&2
exit 1
fi
# WHY: Upstream Linux releases may require a newer glibc than this host.
echo "Building Treehouse v$version from source for this host"
curl -fsSL "https://github.com/kunchenguid/treehouse/archive/refs/tags/v$version.tar.gz" -o source.tar.gz || exit 1
mkdir source || exit 1
tar -xzf source.tar.gz -C source --strip-components=1 || exit 1
(cd source && CGO_ENABLED=0 go build -buildvcs=false -ldflags "-X main.version=v$version" -o "$stage/$tool" .) || exit 1
"./$tool" --version || exit 1
fi
mkdir -p "$HOME/.local/bin" || exit 1
install -m 755 "$tool" "$HOME/.local/bin/$tool"
)
install_treehouse_from_release() {
install_firstmate_release treehouse "$1"
}
install_no-mistakes_from_release() {
install_firstmate_release no-mistakes "$1"
}
install_treehouse_tools() {
install_package_version treehouse 3.1.6 || return 1
make -C "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" treehouse-config
}
install_firstmate_tools() {
install_package_version no-mistakes 1.84.0 || return 1
local tool version tool_version firstmate_checkout
firstmate_checkout=${FIRSTMATE_HOME:-"$HOME/src/firstmate"}
for tool_version in gh-axi:0.1.44 tasks-axi:0.2.6 quota-axi:0.1.68 chrome-devtools-axi:0.1.45 lavish-axi:0.1.93; do
tool=${tool_version%:*}
version=${tool_version#*:}
if ! command -v "$tool" >/dev/null || ! semver_ge "$(installed_semver "$tool")" "$version"; then
npm install --global --prefix "$HOME/.local" "$tool@$version" || return 1
fi
done
if [ ! -e "$firstmate_checkout" ]; then
mkdir -p "$(dirname "$firstmate_checkout")" || return 1
git clone https://github.com/kunchenguid/firstmate "$firstmate_checkout" || return 1
fi
make -C "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" "FIRSTMATE_HOME=$firstmate_checkout" firstmate-config
}
claude-code_current_semver() {
current_heuristic_semver claude
}
install_claude-code_from_release() (
claude_stage=$(mktemp) || exit 1
trap 'rm -f "$claude_stage"' EXIT
curl -fsSL https://claude.ai/install.sh -o "$claude_stage" || exit 1
bash "$claude_stage" "$1" || exit 1
)
install_pi_from_release() {
install_package_version node 24 || return 1
npm install -g --ignore-scripts "@earendil-works/pi-coding-agent@$1"
}
install_stylua_from_release() {
install_package_version node 24
npm install -g "@johnnymorganz/stylua-bin@$1"
}
install_bash-language-server_from_release() {
install_package_version node 24
npm install -g "bash-language-server@$1"
}
install_mmdc_from_release() (
install_package_version node 24 || exit 1
npm install -g --ignore-scripts "@mermaid-js/mermaid-cli@$1" || exit 1
local mermaid_root
mermaid_root=$(npm root -g) || exit 1
cd "$mermaid_root/@mermaid-js/mermaid-cli/node_modules/puppeteer" || exit 1
# WHY: npm can block Puppeteer's browser download; run only that setup explicitly.
node install.mjs
)
install_jq_from_release() (
case "$(uname -m)" in
x86_64) jq_arch=amd64 ;;
arm64|aarch64) jq_arch=arm64 ;;
*) echo "Unsupported jq architecture" >&2; exit 1 ;;
esac
jq_asset="jq-$os-$jq_arch"
jq_stage=$(mktemp -d) || exit 1
trap 'rm -rf "$jq_stage"' EXIT
curl -fsSL "https://github.com/jqlang/jq/releases/download/jq-$1/$jq_asset" -o "$jq_stage/$jq_asset" || exit 1
curl -fsSL "https://github.com/jqlang/jq/releases/download/jq-$1/sha256sum.txt" -o "$jq_stage/checksums" || exit 1
awk -v asset="$jq_asset" '$2 == asset || $2 == "*" asset' "$jq_stage/checksums" > "$jq_stage/selected"
[ -s "$jq_stage/selected" ] || exit 1
if command -v sha256sum >/dev/null; then
(cd "$jq_stage" && sha256sum -c selected) || exit 1
else
(cd "$jq_stage" && shasum -a 256 -c selected) || exit 1
fi
mkdir -p "$HOME/.local/bin" || exit 1
install -m 755 "$jq_stage/$jq_asset" "$HOME/.local/bin/jq" || exit 1
)
install_yq_from_release() {
local yq_arch yq_os
case "$(uname -m)" in
x86_64) yq_arch=amd64 ;;
arm64|aarch64) yq_arch=arm64 ;;
*) echo "Unsupported yq architecture" >&2; return 1 ;;
esac
case "$os" in
macos) yq_os=darwin ;;
linux) yq_os=linux ;;
*) echo "Unsupported yq OS" >&2; return 1 ;;
esac
mkdir -p "$HOME/.local/bin" || return 1
curl -fsSL "https://github.com/mikefarah/yq/releases/download/v$1/yq_${yq_os}_${yq_arch}" \
-o "$HOME/.local/bin/yq" || return 1
chmod +x "$HOME/.local/bin/yq"
}
install_typescript-language-server_from_release() {
install_package_version node 24
npm install -g typescript-language-server@"$1"
}
install_rust-analyzer_from_release() {
rustup component add rust-analyzer
}
zsh-autosuggestions_current_semver() {
local version
if command -v brew &>/dev/null; then
version=$(brew list --versions zsh-autosuggestions 2>/dev/null | parse_semver | tail -n1) || version=""
if [ -n "$version" ]; then
echo "$version"
return 0
fi
fi
head -n3 "$HOME/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" 2>/dev/null | parse_semver
}
install_gopls_from_release() {
install_package_version go 1.22
go install golang.org/x/tools/gopls@v"$1"
}
gopls_current_semver() {
gopls version 2>/dev/null | parse_semver
}
install_gotestsum_from_release() {
install_package_version go 1.22
go install gotest.tools/gotestsum@v"$1"
}
gotestsum_current_semver() {
gotestsum --version 2>/dev/null | parse_semver
}
install_zsh-autosuggestions_from_source() {
if [ ! -d "$HOME/.zsh/plugins/zsh-autosuggestions" ]; then
git clone --depth 1 https://github.com/zsh-users/zsh-autosuggestions.git "$HOME/.zsh/plugins/zsh-autosuggestions"
fi
git -C "$HOME/.zsh/plugins/zsh-autosuggestions" fetch --tags --force
git -C "$HOME/.zsh/plugins/zsh-autosuggestions" checkout -f "v$1"
}
yaml-language-server_current_semver() {
command -v yaml-language-server >/dev/null || return 1
npm list --global yaml-language-server --depth=0 --json 2>/dev/null |
jq -r '.dependencies["yaml-language-server"].version // empty'
}
install_yaml-language-server_from_release() {
install_package_version node 24
npm install -g yaml-language-server@"$1"
}
install_hexyl_from_release() {
cargo install hexyl -q --locked --version "$1"
}
install_direnv_from_release() {
# WARN: this is a security risk
curl -sfL https://direnv.net/install.sh | bash
}
install_uv_from_release() (
uv_stage=$(mktemp) || exit 1
trap 'rm -f "$uv_stage"' EXIT
curl -fsSL "https://github.com/astral-sh/uv/releases/download/$1/uv-installer.sh" \
-o "$uv_stage" || exit 1
UV_INSTALL_DIR="$HOME/.local/bin" UV_NO_MODIFY_PATH=1 sh "$uv_stage" || exit 1
"$HOME/.local/bin/uv" --version || exit 1
)
install_atuin_from_release() (
# Use musl on Linux so older dev-box glibc versions work too.
# Binary releases also avoid requiring Atuin's newer Rust toolchain.
case "$(uname -m)" in
x86_64) atuin_arch=x86_64 ;;
arm64|aarch64) atuin_arch=aarch64 ;;
*) echo "Unsupported Atuin architecture" >&2; exit 1 ;;
esac
case "$(uname -s)" in
Darwin) atuin_target="$atuin_arch-apple-darwin" ;;
Linux) atuin_target="$atuin_arch-unknown-linux-musl" ;;
*) echo "Unsupported Atuin OS" >&2; exit 1 ;;
esac
atuin_program=${2:-atuin}
case "$atuin_program" in
atuin) atuin_bin="${CARGO_HOME:-$HOME/.cargo}/bin" ;;
atuin-server) atuin_bin="$HOME/.local/bin" ;;
*) echo "Unsupported Atuin program" >&2; exit 1 ;;
esac
atuin_stage=$(mktemp -d) || exit 1
trap 'rm -rf "$atuin_stage"' EXIT
atuin_archive="$atuin_program-$atuin_target.tar.gz"
atuin_url="https://github.com/atuinsh/atuin/releases/download/v$1/$atuin_archive"
curl -fsSL "$atuin_url" -o "$atuin_stage/$atuin_archive" || exit 1
curl -fsSL "$atuin_url.sha256" -o "$atuin_stage/$atuin_archive.sha256" || exit 1
if command -v sha256sum >/dev/null; then
(cd "$atuin_stage" && sha256sum -c "$atuin_archive.sha256") || exit 1
else
(cd "$atuin_stage" && shasum -a 256 -c "$atuin_archive.sha256") || exit 1
fi
tar -xzf "$atuin_stage/$atuin_archive" -C "$atuin_stage" || exit 1
"$atuin_stage/$atuin_program-$atuin_target/$atuin_program" --version || exit 1
mkdir -p "$atuin_bin" || exit 1
install -m 755 "$atuin_stage/$atuin_program-$atuin_target/$atuin_program" "$atuin_bin/$atuin_program.new" || exit 1
mv -f "$atuin_bin/$atuin_program.new" "$atuin_bin/$atuin_program" || exit 1
)
install_cargo-sweep_from_release() {
cargo install cargo-sweep --locked --version "$1"
}
install_cargo-cache_from_release() {
cargo install cargo-cache --locked --version "$1"
}
install_tree-sitter-cli_from_release() {
cargo install tree-sitter-cli --locked --version "$1"
}
tree-sitter-cli_current_semver() {
tree-sitter --version 2>/dev/null | parse_semver | head -n1
}
install_git-crypt_from_source() (
# git-crypt needs to be built from source on some systems
mkdir -p "$HOME/src/oss"
if [ ! -d ~/src/oss/git-crypt ]; then
git clone https://github.com/AGWA/git-crypt.git ~/src/oss/git-crypt --depth 1
fi
git -C ~/src/oss/git-crypt fetch --tags --force --prune || exit 1
git -C ~/src/oss/git-crypt checkout "$1" || exit 1
cd ~/src/oss/git-crypt || exit 1
make clean
make
make install PREFIX="$HOME/.local"
)
install_ctags-lsp_package() {
if command -v brew &>/dev/null; then
brew install netmute/tap/ctags-lsp
fi
}
install_ctags-lsp_from_source() {
go install github.com/netmute/ctags-lsp@latest
}
install_cargo_from_release() {
local rust_stage
rust_stage=$(mktemp) || return 1
curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs -o "$rust_stage" ||
{ rm -f "$rust_stage"; return 1; }
RUSTUP_INIT_SKIP_PATH_CHECK=yes sh "$rust_stage" --default-toolchain "$1" --profile minimal --no-modify-path -y ||
{ rm -f "$rust_stage"; return 1; }
rm -f "$rust_stage"
# NOTE: rustup generates this file outside the repository.
# shellcheck disable=SC1091
source "$HOME"/.cargo/env
}
install_just_from_release() {
cargo install just --locked --version "$1"
}
prepare_bootstrap_environment() {
mkdir -p "$HOME/.local/bin"
export GOPATH="${GOPATH:-$HOME/.local/go}"
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:${GOPATH%%:*}/bin:/usr/local/go/bin:$PATH"
# Dev VM images provide Go outside PATH.
if ! command -v go >/dev/null; then