1 |
rakinar2 |
575 |
#!/usr/bin/env sh |
2 |
|
|
|
3 |
|
|
set -e |
4 |
|
|
|
5 |
|
|
argv_0=$0 |
6 |
|
|
projectdir=$(dirname $0) |
7 |
|
|
projectdir=$(readlink -f "$projectdir") |
8 |
|
|
|
9 |
|
|
tmp_dir="$projectdir/.blaze" |
10 |
|
|
bun_dir="$tmp_dir/bun" |
11 |
|
|
bun="bun" |
12 |
|
|
|
13 |
|
|
has_curl=$(command -v curl) |
14 |
|
|
has_wget=$(command -v wget) |
15 |
|
|
|
16 |
|
|
if [ -z "$has_curl" ] && [ -z "$has_wget" ]; then |
17 |
|
|
echo "error: No curl or wget found. Please install one of them." |
18 |
|
|
exit 1 |
19 |
|
|
fi |
20 |
|
|
|
21 |
|
|
mkdir -p "$tmp_dir" |
22 |
|
|
|
23 |
|
|
getprop() { |
24 |
|
|
value=$(cat "$projectdir/blaze/wrapper/blaze_wrapper.properties" | grep "$1" | cut -d'=' -f2) |
25 |
|
|
echo $value |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
print() { |
29 |
|
|
printf "\033[${1}m$2\033[0m" |
30 |
|
|
printf " $3\n" |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
blaze_srcpath=$(getprop "blaze.srcpath") |
34 |
|
|
blaze_srcpath=$(readlink -f "$blaze_srcpath") |
35 |
|
|
|
36 |
|
|
if [ -z "$blaze_srcpath" ]; then |
37 |
|
|
print "31" "error" "blaze.srcpath is not set in blaze_wrapper.properties" |
38 |
|
|
exit 1 |
39 |
|
|
fi |
40 |
|
|
|
41 |
|
|
pushd() { |
42 |
|
|
if [ -z "$1" ]; then |
43 |
|
|
return 1 |
44 |
|
|
fi |
45 |
|
|
|
46 |
|
|
if [ -z "$DIRSTACK" ]; then |
47 |
|
|
DIRSTACK="$1" |
48 |
|
|
else |
49 |
|
|
DIRSTACK="$1:$DIRSTACK" |
50 |
|
|
fi |
51 |
|
|
|
52 |
|
|
cd "$1" |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
popd() { |
56 |
|
|
if [ -z "$DIRSTACK" ]; then |
57 |
|
|
return 1 |
58 |
|
|
fi |
59 |
|
|
|
60 |
|
|
cd "$(echo "$DIRSTACK" | cut -d: -f1)" |
61 |
|
|
DIRSTACK=$(echo "$DIRSTACK" | cut -d: -f2-) |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
summary() { |
65 |
|
|
title=$1 |
66 |
|
|
|
67 |
|
|
if [ -z "$title" ]; then |
68 |
|
|
title="Final" |
69 |
|
|
fi |
70 |
|
|
|
71 |
|
|
printf "\033[1m -- $title Configuration Summary -- \033[0m\n\n" |
72 |
|
|
print "32" "info" "Project root directory: $projectdir" |
73 |
|
|
print "32" "info" "BlazeBuild directory: $blaze_srcpath" |
74 |
|
|
print "32" "info" "Temporary directory: $tmp_dir" |
75 |
|
|
print "32" "info" "Bun executable: $bun" |
76 |
|
|
|
77 |
|
|
printf "\n" |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
bun_run_installer() { |
81 |
|
|
rm -rf "$bun_dir" |
82 |
|
|
mkdir -p "$bun_dir" |
83 |
|
|
|
84 |
|
|
if [ ! -z "$has_curl" ]; then |
85 |
|
|
export BUN_INSTALL="$bun_dir" && export PATH="$BUN_INSTALL":"$PATH":"$BUN_INSTALL" && export SHELL=blazew && (curl -fsSL https://bun.sh/install | bash -s "bun-v$1") >"$tmp_dir/bun_install.log" 2>&1 |
86 |
|
|
else |
87 |
|
|
export BUN_INSTALL="$bun_dir" && export PATH="$BUN_INSTALL":"$PATH":"$BUN_INSTALL" && export SHELL=blazew && (wget -qO- https://bun.sh/install | bash -s "bun-v$1") >"$tmp_dir/bun_install.log" 2>&1 |
88 |
|
|
fi |
89 |
|
|
|
90 |
|
|
bun="$bun_dir/bin/bun" |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
install_bun() { |
94 |
|
|
local bun_version=$(getprop "bun.version") |
95 |
|
|
|
96 |
|
|
if [ -z "$bun_version" ]; then |
97 |
|
|
print "31" "error" "bun.version is not set in blaze_wrapper.properties" |
98 |
|
|
exit 1 |
99 |
|
|
fi |
100 |
|
|
|
101 |
|
|
export PATH="$bun_dir/bin":"$PATH":"$bun_dir/bin" |
102 |
|
|
|
103 |
|
|
if [ -z "$(command -v bun)" ]; then |
104 |
|
|
print "33" "warn" "Could not find bun installation" |
105 |
|
|
print "32" "info" "Installing bun" |
106 |
|
|
bun_run_installer $bun_version |
107 |
|
|
else |
108 |
|
|
existing_version=$(bun --version) |
109 |
|
|
|
110 |
|
|
if [ "$existing_version" != "$bun_version" ]; then |
111 |
|
|
print "33" "warn" "Bun version mismatch in existing installation: required $bun_version, found $existing_version" |
112 |
|
|
print "32" "info" "Installing bun version: $bun_version" |
113 |
|
|
bun_run_installer $bun_version |
114 |
|
|
else |
115 |
|
|
bun="$(command -v bun)" |
116 |
|
|
fi |
117 |
|
|
fi |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
if [ "$BLAZEW_DEBUG" = "1" ]; then |
121 |
|
|
summary "Initial" |
122 |
|
|
fi |
123 |
|
|
|
124 |
|
|
install_bun |
125 |
|
|
|
126 |
|
|
if [ "$BLAZEW_DEBUG" = "1" ]; then |
127 |
|
|
printf "\n" |
128 |
|
|
summary |
129 |
|
|
fi |
130 |
|
|
|
131 |
|
|
$bun $projectdir/blaze/wrapper/blaze_wrapper.js $@ |