-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-nodejs.sh
More file actions
executable file
·442 lines (374 loc) · 8.13 KB
/
Copy pathmake-nodejs.sh
File metadata and controls
executable file
·442 lines (374 loc) · 8.13 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
#!/usr/bin/env bash
#
# Copyright (c) Sebastian Kucharczyk <kuchen@kekse.biz>
# https://kekse.biz/ https://github.com/kekse1/utilities/
# v0.3.14
#
# JFYI: This is a really old design, so I'm not sure
# whether everything is really "fine" and "correct",
# or most "efficient", etc.. BUT IT WORX for me. ^_^
#
# AND you should know: we're using a symbolic link
# '/opt/node.js/0' by default (to a directory named
# by the real Node.js version). AND it's still up to
# you to create symlinks below '/usr/*' - mostly the
# `bin/node`, etc.. BUT this is only necessary ONE
# TIME: every future update (via this script) will
# *add* the newer version and replace the '0'-link,
# which should be the target of all your links in
# the '/usr' hierarchy! ;-)
#
# New since v0.3.11: the $tmpdir is now also below
# the '/opt/node.js/' directory. The problem was:
# I configured my '/etc/fstab' w/ the 'noexec'
# option for my '/tmp/' (on ram disk).. ;-)
#
#for termux:
#DEPENDS="binutils libc++ openssl c-ares libicu zlib libuv clang make pkg-config python"
#DEPENS="ninja-build"
#
#only used for termux build..
cpu="arm64"
os="android"
#
target="$4"
#tmpdir="/tmp/node.js/"
[[ -z "$target" ]] && target="/opt/node.js/"
originalTarget="$target"
tmpdir="${target}/tmp/"
#
url="https://nodejs.org/dist/"
comp="xz" #gz
dl="wget"
#
flags="-O2 -pipe -ftree-vectorize"
j=$((`nproc 2>/dev/null`-1))
march="native"
#
version="$1"
static="$2"
noFlags="$3"
#
termux=""
args=""
if [[ -d "/data/data/com.termux/" ]]; then
termux="yes"
else
termux="no"
fi
if [[ -z "$static" ]]; then
static="no"
elif [[ "$static" == "y" ]]; then
static="yes"
elif [[ "$static" == "static" ]]; then
static="yes"
elif [[ "$static" != "yes" ]]; then
static="no"
fi
if [[ -z "$noFlags" ]]; then
noFlags="no"
elif [[ "$noFlags" == "y" ]]; then
noFlags="yes"
elif [[ "$noFlags" == "yes" ]]; then
noFlags="yes"
elif [[ "$noFlags" == "n" ]]; then
noFlags="no"
elif [[ "$noFlags" == "no" ]]; then
noFlags="no"
else
noFlags="no"
fi
#
[[ -z "$j" ]] && j=1
termux_args=""
[[ -n "$os" ]] && termux_args="${termux_args} --dest-os='$os'"
[[ -n "$cpu" ]] && termux_args="$termux_args --dest-cpu='$cpu'"
termux_args="${termux_args} --shared-cares --shared-openssl --shared-zlib" #--with-intl=system-icu
#
if [[ -z "$version" ]]; then
echo " >> Syntax: $(basename "$0") <version> [ <static> [ <no-flags> [ <target> ] ] ]" >&2
exit 1
elif [[ "$version" == v* ]]; then
version="${version:1}"
if [[ -z "$version" ]]; then
echo " >> Please argue with a VALID version number/string!" >&2
exit 2
fi
fi
if [[ -z "$(which $dl 2>/dev/null)" ]]; then
echo " >> '$dl' can't be found (to download Node.js).." >&2
exit 3
fi
#
if [[ "$termux" == "yes" ]]; then
args="${args} ${termux_args}"
target="/data/data/com.termux/files/${target}/"
tmpdir="/data/data/com.termux/files/home/${tmpdir}/"
#
# this is new (a fix), since v0.3.9:
#
[[ ! -e "$HOME/.gyp" ]] && mkdir "$HOME/.gyp/"
gypinc="$HOME/.gyp/include.gypi"
[[ ! -e "$gypinc" ]] && touch "$gypinc"
grep 'android_ndk_path' "$gypinc" >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
add='{
"variables":
{
"android_ndk_path": ""
}
}'
if [[ `stat -c '%s' "$gypinc"` -eq 0 ]]; then
echo -e "$add" >"$gypinc"
else
echo " >> You need to add the following code to your '$gypinc':" >&2
echo -e "'$add'" >&2
echo " >> Wasn't done automatically because this file was not empty." >&2
exit 127
fi
fi
else
if [[ `id -u` -ne 0 ]]; then
echo " >> You need to be the 'root' superuser to do this.." >&2
exit 4
fi
flags="$flags -march=$march"
fi
#
if [[ ! -d "$tmpdir" ]]; then
if [[ -e "$tmpdir" ]]; then
echo " >> Temporary directory is not a directory." >&2
exit 16
else
mkdir -pv "$tmpdir"
fi
fi
#
symlink="${target}/0"
if [[ -d "${target}" ]]; then
target="$(realpath "${target}")/${version}"
elif [[ -e "${target}" ]]; then
echo " >> Target '$target' already exists, but is not a directory." >&2
exit 15
fi
if [[ -d "$target" ]]; then
echo " >> This version seems to be compiled already (--prefix path exists)" >&2
exit 5
fi
#
if [[ "$static" == "yes" ]]; then
args="${args} --fully-static"
target="${target}-static/"
else
target="${target}/"
fi
args="--prefix='${target}' ${args}"
#
if [[ "$noFlags" == "yes" ]]; then
unset MAKEFLAGS
unset CFLAGS
unset CXXFLAGS
unset CPPFLAGS
else
[[ -z "$MAKEFLAGS" ]] && export MAKEFLAGS="-j$j"
[[ -z "$CFLAGS" ]] && export CFLAGS="$flags"
[[ -z "$CXXFLAGS" ]] && export CXXFLAGS="$flags"
[[ -z "$CPPFLAGS" ]] && export CPPFLAGS="$flags"
fi
#
file="node-v${version}.tar.${comp}"
url="${url}/v${version}/${file}"
if [[ "$url" != http?://* ]]; then
echo " >> Invalid URL '$url'!" >&2
exit 6
fi
if [[ -e "$target" ]]; then
echo " >> Target directory '$target' already exists!" >&2
exit 7
fi
#
download()
{
useWget()
{
local wh="$(which "wget" 2>/dev/null)"
if [[ $? -ne 0 ]]; then
echo " >> PROBLEM: Couldn't find 'wget' to download.. aborting!" >&2
exit 8
fi
echo " >> Downloading '$file' (`pwd`).."
echo
$wh --continue "$url"
if [[ $? -ne 0 ]]; then
echo " >> FAILED to download '$url'.." >&2
exit 9
else
echo " >> Sucessfully downloaded '$url'"
fi
}
useCurl()
{
local wh="$(which "curl" 2>/dev/null)"
if [[ $? -ne 0 ]]; then
echo " >> PROBLEM: Couldn't find 'curl' to download.. aborting!" >&2
exit 10
fi
echo " >> Downloading '$file' (`pwd`).."
echo
$wh --continue-at - --output "$file" "$url"
if [[ $? -ne 0 ]]; then
echo " >> FAILED to download '$url'.." >&2
exit 11
else
echo " >> Successfully downloaded '$url'"
fi
}
useNetCut()
{
echo "(TODO) 'netcut' routine not yet implemented" >&2
exit 12
}
invalidDl()
{
echo " >> PROBLEM: Invalid downloader '$dl'! Aborting." >&2
exit 13
}
#if [[ -e "$file" ]]; then
# echo " >> File seems to be downloaded already.. old one will be deleted here!" >&2
# rm -rfv "$file"
#fi
if [[ "$dl" == "wget" ]]; then
useWget
elif [[ "$dl" == "curl" ]]; then
useCurl
elif [[ "$dl" == "netcut" ]]; then
useGet
else
invalidDl
fi
}
#
dir="node-v${version}"
untar()
{
tar -xpf "$file"
if [[ -d "$dir" ]]; then
echo " >> Unpacked (\`tar -xpf\`) to './${dir}/'"
cd "./${dir}/"
else
echo " >> FAILED to un-tar (xpf) '$file'" >&2
exit 14
fi
}
configure()
{
#cmd="CC=gcc-11 ./configure ${args}"
cmd="./configure ${args}"
echo " >> '$cmd'"
echo
eval "$cmd"
}
compile()
{
echo
make
}
install()
{
echo
make install
}
build()
{
untar
configure
compile
install
}
createSymlink()
{
[[ -e "$symlink" ]] && rm "$symlink"
ln -s "$version" "$symlink"
}
mergeSymlinks()
{
echo '(TODO: mergeSymlinks())' >&2
}
start()
{
tmpdir="$(realpath "$tmpdir")"
target="$(realpath "$target")"
cd "$tmpdir"
infos
}
really()
{
local cont; read -p " >> Do you want to continue [yes/no]? " cont
case "${cont,,}" in
y*)
begin;;
*)
echo
echo ' >> Aborting..' >&2
exit 7
esac
}
infos()
{
printf " >> That's your environment etc."
echo
echo
printf "%16s: %s\n" "Node.js version" "v${version}"
printf "%16s: %s\n" "Static build" "${static}"
printf "%16s: %s\n" "Termux build" "${termux}"
printf "%16s: %s\n" "No flags buid" "${noFlags}"
if [[ "$termux" == "yes" ]]; then
[[ -n "$os" ]] && printf "%16s: %s\n" "OS" "$os"
[[ -n "$cpu" ]] && printf "%16s: %s\n" "CPU" "$cpu"
fi
echo
printf "%16s: '%s'\n" "Temp directory" "$tmpdir"
printf "%16s: '%s'\n" "Target" "$target"
printf "%16s: '%s'\n" "Downloader" "$dl"
echo
printf "%16s: '%s'\n" "Arguments" "$args"
echo
printf "%16s: '%s'\n" "FLAGS" "$CFLAGS"
printf "%16s: '%s'\n" "MAKEFLAGS" "$MAKEFLAGS"
echo
really
echo
}
begin()
{
echo
download
build
cleanup
check
}
cleanup()
{
cd
rm -rf "$tmpdir"
if [[ $? -ne 0 ]]; then
echo " >> Unable to remove the '$tmpdir'! Maybe a process is in there?" >&2
echo " >> So please remove this directory manually afterwards.." >&2
fi
}
check()
{
echo
if [[ -d "$target" ]]; then
echo -e " >> SUCCESS (v${version} => '${target}')! \e[1m:-)\e[0m"
createSymlink
#mergeSymlinks
echo " >> You can now \`cd\` to '${originalTarget}' and \`rm -rf\` old version(s) [this is 'v${version}', btw ;-]."
else
echo -e " >> FAILED (v${version})! \e[1m:-(\e[0m"
exit 14
fi
}
#
start
#