-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
install.sh
executable file
·509 lines (409 loc) · 13.6 KB
/
install.sh
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
#!/bin/bash
##################################################################################################
# hoobs-core #
# Copyright (C) 2020 HOOBS #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
##################################################################################################
OS=""
ARCH=""
REBOOT_AFTER="false"
INSTANCE_SUPPORT="false"
CORE_FILE=""
NODE_INSTALLED="false"
NODE_VERSION=""
NODE_TARGET=""
NODE_PREFIX=""
NPM_INSTALLED="false"
NPM_VERSION=""
NPM_TARGET=""
NPM_PREFIX=""
HOOBS_INSTALLED="false"
SELINUX_INSTALLED="false"
PACKAGE_MNGR=""
usage()
{
echo ""
echo "help: install [-r | --reboot] [-i | --instance] [-n | --node version]"
echo " Display information about builtin commands."
echo ""
echo " Installs HOOBS with prerequisites, including Node, NPM and Avachi."
echo " This script allows you to adjust the version of Node, using the"
echo " -n (or --node) flag. It also allows you to adjust the version of"
echo " NPM using -m (or --npm) flag."
echo ""
echo " Note:"
echo " This script requires elevated permissions, please run this with"
echo " SUDO or ROOT privileges."
echo ""
echo " Options:"
echo " -r, --reboot reboots after install"
echo " -i, --instance install for instances"
echo " -n, --node [version] the desired Node version"
echo " -m, --npm [version] the desired NPM version"
echo " -c, --core [file] file path to NPM pack file"
echo " --reset resets to factory settings"
echo " -h, --help displays this help menu"
echo ""
echo " Returns:"
echo " Returns success unless the install fails."
echo ""
}
hr()
{
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
}
lr()
{
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
}
reset()
{
echo ""
echo "Reseting device"
echo ""
rm -fR /home/hoobs/.hoobs/
shutdown -r now
}
get_os()
{
OS=$(uname)
ARCH=$(uname -m)
}
get_node()
{
NODE_INSTALLED="false"
NODE_VERSION=""
NODE_PREFIX="/usr/local"
if command -v node > /dev/null; then
NODE_INSTALLED="true"
NODE_VERSION=$(node -v)
NODE_VERSION=${NODE_VERSION#"v"}
WORKING="$PATH"
IFS=':'
read -ra ADDR <<< "$WORKING"
for DIR in "${ADDR[@]}";
do
if [[ -f "$DIR/node" ]]; then
NODE_PREFIX=$(cd $DIR/../;pwd)
break
fi
done
IFS=' '
fi
}
get_npm()
{
NPM_INSTALLED="false"
NPM_VERSION=""
NPM_PREFIX="/usr/local"
if command -v npm > /dev/null; then
NPM_INSTALLED="true"
NPM_VERSION=$(npm -v)
NPM_PREFIX=$(npm get prefix)
fi
}
get_package_manager()
{
if command -v yum > /dev/null; then
PACKAGE_MNGR="yum"
elif command -v dnf > /dev/null; then
PACKAGE_MNGR="dnf"
elif command -v apt-get > /dev/null; then
PACKAGE_MNGR="apt"
fi
}
check_existing_install()
{
if command -v hoobs > /dev/null; then
HOOBS_INSTALLED="true"
else
HOOBS_INSTALLED="false"
fi
if command -v setsebool > /dev/null; then
SELINUX_INSTALLED="true"
else
SELINUX_INSTALLED="false"
fi
}
install_prequsits()
{
get_package_manager
case $PACKAGE_MNGR in
"yum")
yum install -y curl tar git policycoreutils
;;
"dnf")
dnf install -y curl tar git policycoreutils
;;
"apt")
apt-get update
apt-get install -y curl tar git
;;
esac
if [[ "$SELINUX_INSTALLED" = "true" ]]; then
setsebool -P httpd_can_network_connect 1
fi
}
install_node_prequsits()
{
get_node
get_package_manager
case $PACKAGE_MNGR in
"yum")
yum install -y python make gcc gcc-c++
;;
"dnf")
dnf install -y python make gcc gcc-c++
;;
"apt")
apt-get install -y python make gcc g++
;;
esac
if [[ "$NODE_INSTALLED" = "false" ]]; then
case $PACKAGE_MNGR in
"yum")
yum install -y nodejs
;;
"dnf")
dnf install -y nodejs
;;
"apt")
apt-get install -y nodejs npm
;;
esac
fi
}
install_node()
{
export npm_config_loglevel=error
get_os
get_node
get_npm
case $OS in
"Linux")
case $ARCH in
"x86_64")
curl -k -O https://nodejs.org/dist/v$NODE_TARGET/node-v$NODE_TARGET-linux-x64.tar.gz
tar -xzf ./node-v$NODE_TARGET-linux-x64.tar.gz -C $NODE_PREFIX --strip-components=1 --no-same-owner > /dev/null 2>&1
rm -f ./node-v$NODE_TARGET-linux-x64.tar.gz > /dev/null 2>&1
npm config set -g prefix $NPM_PREFIX
npm install -g npm@$NPM_TARGET
npm config set -g prefix $NPM_PREFIX
setcap CAP_NET_BIND_SERVICE=+eip $NODE_PREFIX/bin/node
;;
"armv6l")
curl -k -O https://unofficial-builds.nodejs.org/download/release/v$NODE_TARGET/node-v$NODE_TARGET-linux-armv6l.tar.gz
tar -xzf ./node-v$NODE_TARGET-linux-armv6l.tar.gz -C $NODE_PREFIX --strip-components=1 --no-same-owner > /dev/null 2>&1
rm -f ./node-v$NODE_TARGET-linux-armv6l.tar.gz > /dev/null 2>&1
npm config set -g prefix $NPM_PREFIX
npm install -g npm@$NPM_TARGET
npm config set -g prefix $NPM_PREFIX
setcap CAP_NET_BIND_SERVICE=+eip $NODE_PREFIX/bin/node
;;
"armv7l")
curl -k -O https://nodejs.org/dist/v$NODE_TARGET/node-v$NODE_TARGET-linux-armv7l.tar.gz
tar -xzf ./node-v$NODE_TARGET-linux-armv7l.tar.gz -C $NODE_PREFIX --strip-components=1 --no-same-owner > /dev/null 2>&1
rm -f ./node-v$NODE_TARGET-linux-armv7l.tar.gz > /dev/null 2>&1
npm config set -g prefix $NPM_PREFIX
npm install -g npm@$NPM_TARGET
npm config set -g prefix $NPM_PREFIX
setcap CAP_NET_BIND_SERVICE=+eip $NODE_PREFIX/bin/node
;;
"armv8l")
curl -k -O https://nodejs.org/dist/v$NODE_TARGET/node-v$NODE_TARGET-linux-arm64.tar.gz
tar -xzf ./node-v$NODE_TARGET-linux-arm64.tar.gz -C $NODE_PREFIX --strip-components=1 --no-same-owner > /dev/null 2>&1
rm -f ./node-v$NODE_TARGET-linux-arm64.tar.gz > /dev/null 2>&1
npm config set -g prefix $NPM_PREFIX
npm install -g npm@$NPM_TARGET
npm config set -g prefix $NPM_PREFIX
setcap CAP_NET_BIND_SERVICE=+eip $NODE_PREFIX/bin/node
;;
esac
;;
"Darwin")
curl -k -O https://nodejs.org/dist/v$NODE_TARGET/node-v$NODE_TARGET-darwin-x64.tar.gz
tar -xzf ./node-v$NODE_TARGET-darwin-x64.tar.gz -C $NODE_PREFIX --strip-components=1 --no-same-owner > /dev/null 2>&1
rm -f ./node-v$NODE_TARGET-darwin-x64.tar.gz > /dev/null 2>&1
npm config set -g prefix $NPM_PREFIX
npm install -g npm@$NPM_TARGET
npm config set -g prefix $NPM_PREFIX
;;
esac
}
install_npm()
{
get_npm
if [[ "$NPM_INSTALLED" = "false" ]]; then
if [[ "$NPM_TARGET" == "" ]]; then
NPM_TARGET="latest"
fi
npm install -g npm@$NPM_TARGET
fi
}
clear_npm_cache()
{
get_npm
if [[ "$NPM_INSTALLED" = "true" ]]; then
npm cache clean --force > /dev/null 2>&1
fi
}
if [[ "$(id -u)" != "0" ]]; then
usage
exit
fi
while [ "$1" != "" ]; do
case $1 in
-r | --reboot ) REBOOT_AFTER="true"
;;
-i | --instance ) INSTANCE_SUPPORT="true"
;;
--reset ) reset
exit
;;
-n | --node ) shift
NODE_TARGET=$1
if [[ "$NODE_TARGET" == "lts" || "$NODE_TARGET" == "stable" ]]; then
NODE_TARGET="14.16.0"
elif [[ "$NODE_TARGET" == "latest" ]]; then
NODE_TARGET="15.2.1"
fi
;;
-m | --npm ) shift
NPM_TARGET=$1
if [[ "$NODE_TARGET" == "stable" || "$NODE_TARGET" == "lts" ]]; then
NODE_TARGET="latest"
fi
;;
-c | --core ) shift
CORE_FILE=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit
esac
shift
done
get_os
get_node
get_npm
get_package_manager
check_existing_install
echo ""
echo "Thank You for choosing HOOBS"
hr
if [[ "$NODE_INSTALLED" = "true" ]]; then
echo "Node Version $NODE_VERSION"
elif [[ "$OS" == "Darwin" ]]; then
echo "Can Not Install Node"
lr
echo "Please go to https://nodejs.org/ and download and install"
echo "Node for macOS."
lr
exit
elif [[ "$NODE_TARGET" == "" ]]; then
NODE_TARGET="14.16.0"
NPM_TARGET="6.14.5"
fi
echo "Updating Repositories"
install_prequsits
if [[ "$NODE_INSTALLED" = "false" || ( "$NODE_TARGET" != "" && "$NODE_VERSION" != "$NODE_TARGET" ) ]]; then
if [[ "$ARCH" == "armv6l" && "$NODE_TARGET" > "10.18.0" ]]; then
echo "Can Not Install Node"
lr
echo "Node $NODE_VERSION is not supported on your system."
lr
fi
echo ""
echo "Installing Node"
hr
install_node_prequsits
install_node
get_node
get_npm
lr
echo "Node $NODE_VERSION Installed"
echo ""
fi
if [[ "$NPM_TARGET" != "" && "$NPM_VERSION" != "$NPM_TARGET" ]]; then
install_npm
get_npm
lr
echo "NPM $NPM_VERSION Installed"
echo ""
fi
clear_npm_cache
if [[ "$HOOBS_INSTALLED" = "true" ]]; then
if [[ "$NODE_TARGET" != "" ]]; then
if [[ "$CORE_FILE" != "" ]]; then
npm install -g --unsafe-perm "$CORE_FILE"
else
npm install -g --unsafe-perm @hoobs/hoobs
fi
npm uninstall -g @hoobs/hoobs
if [[ "$CORE_FILE" != "" ]]; then
npm install -g --unsafe-perm "$CORE_FILE"
else
npm install -g --unsafe-perm @hoobs/hoobs
fi
fi
for f in /home/*;
do
[ -d "$f/.hoobs/dist" ] && rm -fR $f/.hoobs/dist
[ -d "$f/.hoobs/lib" ] && rm -fR $f/.hoobs/lib
done;
[ -d "/root/.hoobs/dist" ] && rm -fR /root/.hoobs/dist
[ -d "/root/.hoobs/lib" ] && rm -fR /root/.hoobs/lib
[ -d "/var/root/.hoobs/dist" ] && rm -fR /var/root/.hoobs/dist
[ -d "/var/root/.hoobs/lib" ] && rm -fR /var/root/.hoobs/lib
if [[ "$OS" != "Darwin" ]]; then
if command -v hoobs > /dev/null; then
echo ""
echo "Restarting HOOBS"
hr
hoobs switch hoobs
hoobs service restart
if [[ "$REBOOT_AFTER" = "true" ]]; then
shutdown -r now
fi
fi
fi
else
if [[ "$CORE_FILE" != "" ]]; then
npm install -g --unsafe-perm "$CORE_FILE"
else
npm install -g --unsafe-perm @hoobs/hoobs
fi
if [[ "$INSTANCE_SUPPORT" == "false" && "$OS" != "Darwin" ]]; then
get_node
if command -v setcap > /dev/null; then
setcap CAP_NET_BIND_SERVICE=+eip $NODE_PREFIX/bin/node
fi
if command -v hoobs > /dev/null; then
echo ""
echo "Initializing HOOBS"
hr
if [[ "$REBOOT_AFTER" = "true" ]]; then
hoobs service install --reboot
else
hoobs service install
fi
if [[ "$REBOOT_AFTER" = "true" ]]; then
shutdown -r now
fi
fi
fi
fi