{{ message }}
forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·1694 lines (1496 loc) · 36.6 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·1694 lines (1496 loc) · 36.6 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/sh
# Version: 28
# A script that installs the dependencies needed to build and test Bun.
# This should work on macOS and Linux with a POSIX shell.
# If this script does not work on your machine, please open an issue:
# https://github.com/oven-sh/bun/issues
# If you need to make a change to this script, such as upgrading a dependency,
# increment the version comment to indicate that a new image should be built.
# Otherwise, the existing image will be retroactively updated.
pid="$$"
print() {
echo "$@"
}
error() {
print "error: $@" >&2
if ! [ "$$" = "$pid" ]; then
kill -s TERM "$pid"
fi
exit 1
}
execute() {
local opts=$-
set -x
"$@"
{ local status=$?; set +x "$opts"; } 2> /dev/null
if [ "$status" -ne 0 ]; then
error "Command failed: $@"
fi
}
execute_sudo() {
if [ "$sudo" = "1" ] || [ -z "$can_sudo" ]; then
execute "$@"
else
execute sudo -n "$@"
fi
}
execute_as_user() {
sh="$(require sh)"
if [ "$sudo" = "1" ] || [ "$can_sudo" = "1" ]; then
if [ -f "$(which sudo)" ]; then
execute sudo -n -u "$user" "$sh" -lc "$*"
elif [ -f "$(which doas)" ]; then
execute doas -u "$user" "$sh" -lc "$*"
elif [ -f "$(which su)" ]; then
execute su -s "$sh" "$user" -lc "$*"
else
execute "$sh" -lc "$*"
fi
else
execute "$sh" -lc "$*"
fi
}
grant_to_user() {
path="$1"
if ! [ -f "$path" ] && ! [ -d "$path" ]; then
error "Could not find file or directory: \"$path\""
fi
chown="$(require chown)"
execute_sudo "$chown" -R "$user:$group" "$path"
execute_sudo chmod -R 777 "$path"
}
which() {
command -v "$1"
}
require() {
path="$(which "$1")"
if ! [ -f "$path" ]; then
error "Command \"$1\" is required, but is not installed."
fi
print "$path"
}
fetch() {
curl="$(which curl)"
if [ -f "$curl" ]; then
execute "$curl" -fsSL "$1"
else
wget="$(which wget)"
if [ -f "$wget" ]; then
execute "$wget" -qO- "$1"
else
error "Command \"curl\" or \"wget\" is required, but is not installed."
fi
fi
}
compare_version() {
if [ "$1" = "$2" ]; then
print "0"
elif [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]; then
print "-1"
else
print "1"
fi
}
create_directory() {
path="$1"
path_dir="$path"
while ! [ -d "$path_dir" ]; do
path_dir="$(dirname "$path_dir")"
done
path_needs_sudo="0"
if ! [ -r "$path_dir" ] || ! [ -w "$path_dir" ]; then
path_needs_sudo="1"
fi
mkdir="$(require mkdir)"
if [ "$path_needs_sudo" = "1" ]; then
execute_sudo "$mkdir" -p "$path"
else
execute "$mkdir" -p "$path"
fi
grant_to_user "$path"
}
create_tmp_directory() {
mktemp="$(require mktemp)"
path="$(execute "$mktemp" -d)"
grant_to_user "$path"
print "$path"
}
create_file() {
path="$1"
path_dir="$(dirname "$path")"
if ! [ -d "$path_dir" ]; then
create_directory "$path_dir"
fi
path_needs_sudo="0"
if ! [ -r "$path" ] || ! [ -w "$path" ]; then
path_needs_sudo="1"
fi
if [ "$path_needs_sudo" = "1" ]; then
execute_sudo touch "$path"
else
execute touch "$path"
fi
content="$2"
if [ -n "$content" ]; then
append_file "$path" "$content"
fi
grant_to_user "$path"
}
append_file() {
path="$1"
if ! [ -f "$path" ]; then
create_file "$path"
fi
path_needs_sudo="0"
if ! [ -r "$path" ] || ! [ -w "$path" ]; then
path_needs_sudo="1"
fi
content="$2"
print "$content" | while read -r line; do
if ! grep -q "$line" "$path"; then
sh="$(require sh)"
if [ "$path_needs_sudo" = "1" ]; then
execute_sudo "$sh" -c "echo '$line' >> '$path'"
else
execute "$sh" -c "echo '$line' >> '$path'"
fi
fi
done
}
download_file() {
file_url="$1"
file_tmp_dir="$(create_tmp_directory)"
file_tmp_path="$file_tmp_dir/$(basename "$file_url")"
fetch "$file_url" > "$file_tmp_path"
grant_to_user "$file_tmp_path"
print "$file_tmp_path"
}
# path=$(download_and_verify_file URL sha256)
download_and_verify_file() {
file_url="$1"
hash="$2"
path=$(download_file "$file_url")
execute sh -c 'echo "'"$hash $path"'" | sha256sum -c -' >/dev/null 2>&1
print "$path"
}
append_to_profile() {
content="$1"
profiles=".profile .zprofile .bash_profile .bashrc .zshrc .cshrc"
for profile in $profiles; do
for profile_path in "$current_home/$profile" "$home/$profile"; do
if [ "$ci" = "1" ] || [ -f "$profile_path" ]; then
append_file "$profile_path" "$content"
fi
done
done
}
append_to_path() {
path="$1"
if ! [ -d "$path" ]; then
error "Could not find directory: \"$path\""
fi
append_to_profile "export PATH=\"$path:\$PATH\""
export PATH="$path:$PATH"
}
move_to_bin() {
exe_path="$1"
if ! [ -f "$exe_path" ]; then
error "Could not find executable: \"$exe_path\""
fi
usr_paths="/usr/bin /usr/local/bin"
for usr_path in $usr_paths; do
if [ -d "$usr_path" ] && [ -w "$usr_path" ]; then
break
fi
done
grant_to_user "$exe_path"
execute_sudo mv -f "$exe_path" "$usr_path/$(basename "$exe_path")"
}
check_features() {
print "Checking features..."
for arg in "$@"; do
case "$arg" in
*--ci*)
ci=1
print "CI: enabled"
;;
*--osxcross*)
osxcross=1
print "Cross-compiling to macOS: enabled"
;;
*--gcc-13*)
gcc_version="13"
print "GCC 13: enabled"
;;
esac
done
}
check_operating_system() {
print "Checking operating system..."
uname="$(require uname)"
os="$("$uname" -s)"
case "$os" in
Linux)
os="linux"
;;
Darwin)
os="darwin"
;;
*)
error "Unsupported operating system: $os"
;;
esac
print "Operating System: $os"
arch="$("$uname" -m)"
case "$arch" in
x86_64 | x64 | amd64)
arch="x64"
;;
aarch64 | arm64)
arch="aarch64"
;;
*)
error "Unsupported architecture: $arch"
;;
esac
print "Architecture: $arch"
kernel="$("$uname" -r)"
print "Kernel: $kernel"
case "$os" in
linux)
if [ -f "/etc/alpine-release" ]; then
distro="alpine"
abi="musl"
alpine="$(cat /etc/alpine-release)"
if [ "$alpine" ~ "_" ]; then
release="$(print "$alpine" | cut -d_ -f1)-edge"
else
release="$alpine"
fi
elif [ -f "/etc/os-release" ]; then
. /etc/os-release
if [ -n "$ID" ]; then
distro="$ID"
fi
if [ -n "$VERSION_ID" ]; then
release="$VERSION_ID"
fi
fi
;;
darwin)
sw_vers="$(which sw_vers)"
if [ -f "$sw_vers" ]; then
distro="$("$sw_vers" -productName)"
release="$("$sw_vers" -productVersion)"
fi
case "$arch" in
x64)
sysctl="$(which sysctl)"
if [ -f "$sysctl" ] && [ "$("$sysctl" -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
arch="aarch64"
rosetta="1"
print "Rosetta: enabled"
fi
;;
esac
;;
esac
if [ -n "$distro" ]; then
print "Distribution: $distro $release"
fi
case "$os" in
linux)
ldd="$(which ldd)"
if [ -f "$ldd" ]; then
ldd_version="$($ldd --version 2>&1)"
abi_version="$(print "$ldd_version" | grep -o -E '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n 1)"
case "$ldd_version" in
*musl*)
abi="musl"
;;
*GNU* | *GLIBC*)
abi="gnu"
;;
esac
fi
if [ -n "$abi" ]; then
print "ABI: $abi $abi_version"
fi
;;
esac
}
check_inside_docker() {
if ! [ "$os" = "linux" ]; then
return
fi
print "Checking if inside Docker..."
if [ -f "/.dockerenv" ]; then
docker=1
else
if [ -f "/proc/1/cgroup" ]; then
case "$(cat /proc/1/cgroup)" in
*/docker/*)
docker=1
;;
esac
fi
if [ -f "/proc/self/mountinfo" ]; then
case "$(cat /proc/self/mountinfo)" in
*/docker/*)
docker=1
;;
esac
fi
fi
if [ "$docker" = "1" ]; then
print "Docker: enabled"
fi
}
check_package_manager() {
print "Checking package manager..."
case "$os" in
darwin)
if ! [ -f "$(which brew)" ]; then
install_brew
fi
pm="brew"
;;
linux)
if [ -f "$(which apt-get)" ]; then
pm="apt"
elif [ -f "$(which dnf)" ]; then
pm="dnf"
elif [ -f "$(which yum)" ]; then
pm="yum"
elif [ -f "$(which apk)" ]; then
pm="apk"
else
error "No package manager found. (apt, dnf, yum, apk)"
fi
;;
esac
print "Package manager: $pm"
print "Updating package manager..."
case "$pm" in
apt)
export DEBIAN_FRONTEND=noninteractive
package_manager update -y
;;
apk)
package_manager update
;;
esac
}
check_user() {
print "Checking user..."
if [ -n "$SUDO_USER" ]; then
user="$SUDO_USER"
else
id="$(require id)"
user="$("$id" -un)"
group="$("$id" -gn)"
fi
if [ -z "$user" ]; then
error "Could not determine user"
fi
print "User: $user"
print "Group: $group"
home="$(execute_as_user echo '~')"
if [ -z "$home" ] || [ "$home" = "~" ]; then
error "Could not determine home directory for user: $user"
fi
print "Home: $home"
id="$(which id)"
if [ -f "$id" ] && [ "$($id -u)" = "0" ]; then
sudo=1
print "Sudo: enabled"
elif [ -f "$(which sudo)" ] && [ "$(sudo -n echo 1 2>/dev/null)" = "1" ]; then
can_sudo=1
print "Sudo: can be used"
fi
current_user="$user"
current_group="$group"
current_home="$home"
}
check_ulimit() {
if ! [ "$os" = "linux" ]; then
return
fi
if ! [ "$ci" = "1" ]; then
return
fi
print "Checking ulimits..."
systemd_conf="/etc/systemd/system.conf"
limits_conf="/etc/security/limits.d/99-unlimited.conf"
create_file "$limits_conf"
limits="core data fsize memlock nofile rss stack cpu nproc as locks sigpending msgqueue"
for limit in $limits; do
limit_upper="$(print "$limit" | tr '[:lower:]' '[:upper:]')"
limit_value="unlimited"
case "$limit" in
nofile | nproc)
limit_value="1048576"
;;
esac
if [ -f "$limits_conf" ]; then
limit_users="root *"
for limit_user in $limit_users; do
append_file "$limits_conf" "$limit_user soft $limit $limit_value"
append_file "$limits_conf" "$limit_user hard $limit $limit_value"
done
fi
if [ -f "$systemd_conf" ]; then
# in systemd's configuration you need to say "infinity" when you mean "unlimited"
if [ "$limit_value" = "unlimited" ]; then
limit_value="infinity"
fi
append_file "$systemd_conf" "DefaultLimit$limit_upper=$limit_value"
fi
done
rc_conf="/etc/rc.conf"
if [ -f "$rc_conf" ]; then
rc_ulimit=""
limit_flags="c d e f i l m n q r s t u v x"
for limit_flag in $limit_flags; do
limit_value="unlimited"
case "$limit_flag" in
n | u)
limit_value="1048576"
;;
esac
rc_ulimit="$rc_ulimit -$limit_flag $limit_value"
done
append_file "$rc_conf" "rc_ulimit=\"$rc_ulimit\""
fi
pam_confs="/etc/pam.d/common-session /etc/pam.d/common-session-noninteractive"
for pam_conf in $pam_confs; do
if [ -f "$pam_conf" ]; then
append_file "$pam_conf" "session optional pam_limits.so"
fi
done
systemctl="$(which systemctl)"
if [ -f "$systemctl" ]; then
execute_sudo "$systemctl" daemon-reload
fi
# Configure dpkg and apt for faster operation in CI environments
if [ "$ci" = "1" ] && [ "$pm" = "apt" ]; then
dpkg_conf="/etc/dpkg/dpkg.cfg.d/01-ci-options"
execute_sudo create_directory "$(dirname "$dpkg_conf")"
append_file "$dpkg_conf" "force-unsafe-io"
append_file "$dpkg_conf" "no-debsig"
apt_conf="/etc/apt/apt.conf.d/99-ci-options"
execute_sudo create_directory "$(dirname "$apt_conf")"
append_file "$apt_conf" 'Acquire::Languages "none";'
append_file "$apt_conf" 'Acquire::GzipIndexes "true";'
append_file "$apt_conf" 'Acquire::CompressionTypes::Order:: "gz";'
append_file "$apt_conf" 'APT::Get::Install-Recommends "false";'
append_file "$apt_conf" 'APT::Get::Install-Suggests "false";'
append_file "$apt_conf" 'Dpkg::Options { "--force-confdef"; "--force-confold"; }'
fi
}
package_manager() {
case "$pm" in
apt)
execute_sudo apt-get "$@"
;;
dnf)
case "$distro" in
rhel)
execute_sudo dnf \
--disableplugin=subscription-manager \
"$@"
;;
*)
execute_sudo dnf "$@"
;;
esac
;;
yum)
execute_sudo yum "$@"
;;
apk)
execute_sudo apk "$@"
;;
brew)
execute_as_user brew "$@"
;;
pkg)
execute_sudo pkg "$@"
;;
*)
error "Unsupported package manager: $pm"
;;
esac
}
check_package() {
case "$pm" in
apt)
apt-cache policy "$1"
;;
dnf | yum | brew)
package_manager info "$1"
;;
*)
error "Unsupported package manager: $pm"
;;
esac
}
install_packages() {
case "$pm" in
apt)
package_manager install \
--yes \
--no-install-recommends \
--fix-missing \
"$@"
;;
dnf)
package_manager install \
--assumeyes \
--nodocs \
--noautoremove \
--allowerasing \
"$@"
;;
yum)
package_manager install -y "$@"
;;
brew)
package_manager install \
--force \
--formula \
"$@"
package_manager link \
--force \
--overwrite \
"$@"
;;
apk)
package_manager add \
--no-cache \
--no-interactive \
--no-progress \
"$@"
;;
pkg)
package_manager install "$@"
;;
*)
error "Unsupported package manager: $pm"
;;
esac
}
install_brew() {
print "Installing Homebrew..."
bash="$(require bash)"
script=$(download_file "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh")
execute_as_user "$bash" -lc "NONINTERACTIVE=1 $script"
case "$arch" in
x64)
append_to_path "/usr/local/bin"
;;
aarch64)
append_to_path "/opt/homebrew/bin"
;;
esac
case "$ci" in
1)
append_to_profile "export HOMEBREW_NO_INSTALL_CLEANUP=1"
append_to_profile "export HOMEBREW_NO_AUTO_UPDATE=1"
append_to_profile "export HOMEBREW_NO_ANALYTICS=1"
;;
esac
}
install_common_software() {
case "$pm" in
apt)
# software-properties-common is not available in Debian Trixie
if [ "$distro" = "debian" ] && [ "$release" = "13" ]; then
install_packages \
apt-transport-https
else
install_packages \
apt-transport-https \
software-properties-common
fi
# https://packages.debian.org
# https://packages.ubuntu.com
install_packages \
bash \
ca-certificates \
curl \
htop \
gnupg \
git \
unzip \
wget \
libc6-dbg
;;
dnf)
# https://packages.fedoraproject.org
install_packages \
bash \
ca-certificates \
curl \
htop \
gnupg \
git \
unzip \
wget \
dnf-plugins-core
;;
apk)
# https://pkgs.alpinelinux.org/packages
install_packages \
bash \
ca-certificates \
curl \
htop \
gnupg \
git \
unzip \
wget \
;;
pkg)
# https://www.freshports.org
install_packages \
shells/bash \
ftp/curl \
sysutils/htop \
security/gnupg \
devel/git \
archivers/unzip \
ftp/wget \
editors/vim \
sysutils/neofetch \
;;
esac
case "$distro" in
amzn | alpine)
install_packages \
tar
;;
rhel)
rhel_version="$(execute rpm -E %rhel)"
install_packages \
"https://dl.fedoraproject.org/pub/epel/epel-release-latest-$rhel_version.noarch.rpm"
;;
centos)
install_packages \
epel-release
;;
esac
crb="$(which crb)"
if [ -f "$crb" ]; then
execute "$crb" enable
fi
install_rosetta
install_nodejs
install_bun
install_tailscale
install_buildkite
}
nodejs_version_exact() {
print "24.3.0"
}
nodejs_version() {
print "$(nodejs_version_exact)" | cut -d. -f1
}
install_nodejs() {
# Download Node.js directly from nodejs.org
nodejs_version="$(nodejs_version_exact)"
# Determine platform name for Node.js download
case "$os" in
darwin)
nodejs_platform="darwin"
;;
linux)
nodejs_platform="linux"
;;
*)
error "Unsupported OS for Node.js download: $os"
;;
esac
# Determine architecture name for Node.js download
case "$arch" in
x64)
nodejs_arch="x64"
;;
aarch64)
nodejs_arch="arm64"
;;
*)
error "Unsupported architecture for Node.js download: $arch"
;;
esac
case "$abi" in
musl)
nodejs_mirror="https://bun-nodejs-release.s3.us-west-1.amazonaws.com"
nodejs_foldername="node-v$nodejs_version-$nodejs_platform-$nodejs_arch-musl"
;;
*)
nodejs_mirror="https://nodejs.org/dist"
nodejs_foldername="node-v$nodejs_version-$nodejs_platform-$nodejs_arch"
;;
esac
# Download Node.js binary archive
nodejs_url="$nodejs_mirror/v$nodejs_version/$nodejs_foldername.tar.gz"
nodejs_tar="$(download_file "$nodejs_url")"
nodejs_extract_dir="$(dirname "$nodejs_tar")"
# Extract Node.js
execute tar -xzf "$nodejs_tar" -C "$nodejs_extract_dir"
# Install Node.js binaries to system
nodejs_dir="$nodejs_extract_dir/$nodejs_foldername"
# Copy bin files preserving symlinks
for file in "$nodejs_dir/bin/"*; do
filename="$(basename "$file")"
if [ -L "$file" ]; then
# Get the symlink target
target="$(readlink "$file")"
# The symlinks are relative (like ../lib/node_modules/npm/bin/npm-cli.js)
# and will work correctly from /usr/local/bin since we're copying
# node_modules to /usr/local/lib/node_modules
execute_sudo ln -sf "$target" "/usr/local/bin/$filename"
elif [ -f "$file" ]; then
# Copy regular files
execute_sudo cp -f "$file" "/usr/local/bin/$filename"
execute_sudo chmod +x "/usr/local/bin/$filename"
fi
done
# Copy node_modules directory to lib
if [ -d "$nodejs_dir/lib/node_modules" ]; then
execute_sudo mkdir -p "/usr/local/lib"
execute_sudo cp -Rf "$nodejs_dir/lib/node_modules" "/usr/local/lib/"
fi
# Copy include files if they exist
if [ -d "$nodejs_dir/include" ]; then
execute_sudo mkdir -p "/usr/local/include"
execute_sudo cp -Rf "$nodejs_dir/include/node" "/usr/local/include/"
fi
# Copy share files if they exist (man pages, etc.)
if [ -d "$nodejs_dir/share" ]; then
execute_sudo mkdir -p "/usr/local/share"
# Copy only node-specific directories
for sharedir in "$nodejs_dir/share/"*; do
if [ -d "$sharedir" ]; then
dirname="$(basename "$sharedir")"
execute_sudo cp -Rf "$sharedir" "/usr/local/share/"
fi
done
fi
# Ensure /usr/local/bin is in PATH
if ! echo "$PATH" | grep -q "/usr/local/bin"; then
print "Adding /usr/local/bin to PATH"
append_to_profile 'export PATH="/usr/local/bin:$PATH"'
export PATH="/usr/local/bin:$PATH"
fi
# Verify Node.js installation
if ! command -v node >/dev/null 2>&1; then
error "Node.js installation failed: 'node' command not found in PATH"
fi
installed_version="$(node --version 2>/dev/null || echo "unknown")"
expected_version="v$nodejs_version"
if [ "$installed_version" != "$expected_version" ]; then
error "Node.js installation failed: expected version $expected_version but got $installed_version. Please check your PATH and try running 'which node' to debug."
fi
print "Node.js $installed_version installed successfully"
# Ensure that Node.js headers are always pre-downloaded so that we don't rely on node-gyp
install_nodejs_headers
}
install_nodejs_headers() {
nodejs_version="$(nodejs_version_exact)"
nodejs_headers_tar="$(download_file "https://nodejs.org/download/release/v$nodejs_version/node-v$nodejs_version-headers.tar.gz")"
nodejs_headers_dir="$(dirname "$nodejs_headers_tar")"
execute tar -xzf "$nodejs_headers_tar" -C "$nodejs_headers_dir"
nodejs_headers_include="$nodejs_headers_dir/node-v$nodejs_version/include"
execute_sudo cp -R "$nodejs_headers_include" "/usr/local/"
# Also install to node-gyp cache locations for different node-gyp versions
# This ensures node-gyp finds headers without downloading them
setup_node_gyp_cache "$nodejs_version" "$nodejs_headers_dir/node-v$nodejs_version"
}
setup_node_gyp_cache() {
nodejs_version="$1"
headers_source="$2"
cache_dir="$home/.cache/node-gyp/$nodejs_version"
create_directory "$cache_dir"
# Copy headers
if [ -d "$headers_source/include" ]; then
cp -R "$headers_source/include" "$cache_dir/" 2>/dev/null || true
fi
# Create installVersion file (node-gyp expects this)
echo "11" > "$cache_dir/installVersion" 2>/dev/null || true
# For Linux, we don't need .lib files like Windows
# but create the directory structure node-gyp expects
case "$arch" in
x86_64|amd64)
create_directory "$cache_dir/lib/x64" 2>/dev/null || true
;;
aarch64|arm64)
create_directory "$cache_dir/lib/arm64" 2>/dev/null || true
;;
*)
create_directory "$cache_dir/lib" 2>/dev/null || true
;;
esac
# Ensure entire path is accessible, not just last component
grant_to_user "$home/.cache"
}
bun_version_exact() {
print "1.3.1"
}
install_bun() {
install_packages unzip
case "$pm" in
apk)
install_packages \
libgcc \
libstdc++
;;
esac
case "$abi" in
musl)
bun_triplet="bun-$os-$arch-$abi"
;;
*)
bun_triplet="bun-$os-$arch"
;;
esac
unzip="$(require unzip)"
bun_download_url="https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/bun-v$(bun_version_exact)/$bun_triplet.zip"
bun_zip="$(download_file "$bun_download_url")"
bun_tmpdir="$(dirname "$bun_zip")"
execute "$unzip" -o "$bun_zip" -d "$bun_tmpdir"
move_to_bin "$bun_tmpdir/$bun_triplet/bun"
bun_path="$(require bun)"
execute_sudo ln -sf "$bun_path" "$(dirname "$bun_path")/bunx"
}
install_cmake() {
case "$os-$pm" in
darwin-* | linux-apk)
install_packages cmake
;;
linux-*)
sh="$(require sh)"
cmake_version="3.30.5"
case "$arch" in
x64)
cmake_url="https://github.com/Kitware/CMake/releases/download/v$cmake_version/cmake-$cmake_version-linux-x86_64.sh"
You can’t perform that action at this time.
