Skip to content

Commit 73a4c2b

Browse files
committed
Fix script of latest nodejs, and to fix armv6 install
1 parent 6763adc commit 73a4c2b

File tree

1 file changed

+51
-34
lines changed

1 file changed

+51
-34
lines changed

deb/update-nodejs-and-nodered

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ tgta16=16.20.2 # need armv6l latest from https://unofficial-builds.nodejs.org/
2626
tgtl16=16.20.2 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/
2727
tgta18=18.20.3 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/
2828
tgtl18=18.20.3 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/
29-
tgta20=20.14.0 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/
30-
tgtl20=20.14.0 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/
29+
tgta20=20.15.0 # need armv6l latest from https://unofficial-builds.nodejs.org/download/release/
30+
tgtl20=20.15.0 # need x86 latest from https://unofficial-builds.nodejs.org/download/release/
3131

3232
usage() {
3333
cat << EOL
@@ -44,11 +44,11 @@ Options:
4444
--update-nodes run npm update on existing installed nodes (within scope of package.json)
4545
--no-init don't ask to initialise settings if they don't exist
4646
--nodered-user specify the user to run as, useful for installing as sudo - e.g. --nodered-user=pi
47-
--nodered-version if not set, the latest version is used - e.g. --nodered-version="3.0.1"
47+
--nodered-version if not set, the latest version is used - e.g. --nodered-version="4.0.2"
4848
--node16 if set, forces install of major version of nodejs 16 LTS
4949
--node18 if set, forces install of major version of nodejs 18 LTS
5050
--node20 if set, forces install of major version of nodejs 20 LTS
51-
if none set, install nodejs 18 LTS if nodejs version is less than 16,
51+
if none set, install nodejs 20 LTS if nodejs version is less than 18,
5252
otherwise leave current install
5353
5454
Note: if you use allow-low-ports it may affect the node modules paths - see https://stackoverflow.com/a/65560687
@@ -103,6 +103,10 @@ if [ $# -gt 0 ]; then
103103
NODE_VERSION="20"
104104
shift
105105
;;
106+
--node22)
107+
NODE_VERSION="22"
108+
shift
109+
;;
106110
--restart)
107111
RESTART="y"
108112
shift
@@ -222,7 +226,7 @@ if curl -I https://registry.npmjs.org/@node-red/util >/dev/null 2>&1; then
222226
echo -e '\033]2;'$NODERED_USER@`hostname`: Node-RED update'\007'
223227
echo " "
224228
echo "This script checks the version of node.js installed is 16 or greater. It will try to"
225-
echo "install node 18 if none is found. It can optionally install node 16, 18 or 20 LTS for you."
229+
echo "install node 20 if none is found. It can optionally install node 18 or 20 LTS for you."
226230
echo " "
227231
echo "If necessary it will then remove the old core of Node-RED, before then installing the latest"
228232
echo "version. You can also optionally specify the version required."
@@ -308,15 +312,15 @@ case $yn in
308312
NODE_VERSION="12"
309313
fi
310314

311-
if [[ "$nv" -lt 16 && "$nv" -ne 0 && "$nrv" != 1 ]]; then
315+
if [[ "$nv" -lt 18 && "$nv" -ne 0 && "$nrv" != 1 ]]; then
312316
if [[ "$NODE_VERSION" == "" ]]; then
313317
echo "Nodejs $nv too old and new version not specified - exiting" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
314318
echo "Node-RED v3.x no longer supports Nodejs $nv "
315319
# echo " Node-RED v2 no longer supports Nodejs $nv. Please update."
316320
# echo " "
317321
# echo " You can use the old v1 branch by specifying --nodered-version=1.*"
318322
echo " "
319-
echo " You can force an install of node 16, 18 or 20 by adding --node18 or --node20 to the end of the command line above."
323+
echo " You can force an install of node 18 or 20 by adding --node18 or --node20 to the end of the command line above."
320324
echo " However doing so may break some nodes that may need re-installing manually."
321325
echo " Generally it is recommended to update all nodes to their latest versions before upgrading."
322326
echo " "
@@ -400,12 +404,15 @@ case $yn in
400404
tgtl=$tgtl18
401405
tgta=$tgta18
402406
elif [[ "$NODE_VERSION" == "20" ]]; then
403-
tgtl="None"
407+
tgtl=$tgtl20
404408
tgta=$tgta20
409+
elif [[ "$NODE_VERSION" == "22" ]]; then
410+
tgtl="None"
411+
tgta="None"
405412
else
406-
tgtl=$tgtl18
407-
tgta=$tgta18
408-
NODE_VERSION="18"
413+
tgtl=$tgtl20
414+
tgta=$tgta20
415+
NODE_VERSION="20"
409416
fi
410417
# maybe remove Node.js - or upgrade if nodesource.list exists
411418
if [[ -d $NODERED_HOME/.nvm ]]; then
@@ -448,33 +455,37 @@ case $yn in
448455
rm /tmp/node.tgz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
449456
echo -ne " Install Node.js for i686 $CHAR"
450457
else
451-
echo -ne " Nodejs 20 for i686 does not exist $CROSS"
458+
echo -ne " Nodejs "$tgtl" for i686 does not exist $CROSS"
452459
fi
453460
elif uname -m | grep -q armv6l ; then
454-
$SUDO apt remove -y nodejs nodejs-legacy npm 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
455-
$SUDO rm -rf /etc/apt/sources.d/nodesource.list /usr/lib/node_modules/npm*
456-
echo -ne " Remove old version of Node.js $TICK $nv2\r\n"
457-
echo -ne " Install Node.js for Armv6 \r"
458-
# f=$(curl -sL https://nodejs.org/download/release/latest-dubnium/ | grep "armv6l.tar.gz" | cut -d '"' -f 2)
459-
# curl -sL -o node.tgz https://nodejs.org/download/release/latest-dubnium/$f 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
460-
curl -sSL -o /tmp/node.tgz https://unofficial-builds.nodejs.org/download/release/v$tgta/node-v$tgta-linux-armv6l.tar.gz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
461-
# unpack it into the correct places
462-
hd=$(head -c 6 /tmp/node.tgz)
463-
if [ "$hd" == "<!DOCT" ] || [ "$hd" == "<html>" ]; then
464-
CHAR="$CROSS File $f not downloaded";
465-
else
466-
if [[ -d /tmp/nodejs ]]; then
467-
$SUDO rm -rf /tmp/nodejs
461+
if [[ "$tgta" != "None" ]]; then
462+
$SUDO apt remove -y nodejs nodejs-legacy npm 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
463+
$SUDO rm -rf /etc/apt/sources.d/nodesource.list /usr/lib/node_modules/npm*
464+
echo -ne " Remove old version of Node.js $TICK $nv2\r\n"
465+
echo -ne " Install Node.js for Armv6 \r"
466+
# f=$(curl -sL https://nodejs.org/download/release/latest-dubnium/ | grep "armv6l.tar.gz" | cut -d '"' -f 2)
467+
# curl -sL -o node.tgz https://nodejs.org/download/release/latest-dubnium/$f 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
468+
curl -sSL -o /tmp/node.tgz https://unofficial-builds.nodejs.org/download/release/v$tgta/node-v$tgta-linux-armv6l.tar.gz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
469+
# unpack it into the correct places
470+
hd=$(head -c 6 /tmp/node.tgz)
471+
if [ "$hd" == "<!DOCT" ] || [ "$hd" == "<html>" ]; then
472+
CHAR="$CROSS File $f not downloaded";
473+
else
474+
if [[ -d /tmp/nodejs ]]; then
475+
$SUDO rm -rf /tmp/nodejs
476+
fi
477+
mkdir -p /tmp/nodejs
478+
$SUDO tar -zxof /tmp/node.tgz --strip-components=1 -C /tmp/nodejs
479+
$SUDO chown -R 0:0 /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
480+
if $SUDO cp -PR /tmp/nodejs/* /usr/ 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi
481+
$SUDO rm -rf /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
468482
fi
469-
mkdir -p /tmp/nodejs
470-
$SUDO tar -zxof /tmp/node.tgz --strip-components=1 -C /tmp/nodejs
471-
$SUDO chown -R 0:0 /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
472-
if $SUDO cp -PR /tmp/nodejs/* /usr/ 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null; then CHAR=$TICK; else CHAR=$CROSS; fi
473-
$SUDO rm -rf /tmp/nodejs 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
483+
# remove the tgz file to save space
484+
rm /tmp/node.tgz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
485+
echo -ne " Install Node.js for Armv6 $CHAR"
486+
else
487+
echo -ne " Nodejs "$tgta" for Armv6 does not exist $CROSS"
474488
fi
475-
# remove the tgz file to save space
476-
rm /tmp/node.tgz 2>&1 | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
477-
echo -ne " Install Node.js for Armv6 $CHAR"
478489
else
479490
echo "Installing nodejs $NODE_VERSION" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
480491
# clean out old nodejs stuff
@@ -566,6 +577,7 @@ case $yn in
566577
# install any nodes, that were installed globally, as local instead
567578
echo "Now create basic package.json for the user and move any global nodes" | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
568579
mkdir -p "$NODERED_HOME/.node-red/node_modules"
580+
$SUDO chown $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red 2>&1 >>/dev/null
569581
$SUDO chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red/node_modules 2>&1 >>/dev/null
570582
# Make it more secure by making settings owned by root and removing nopasswd file for default user.
571583
# $SUDO chown -Rf 0:0 $NODERED_HOME/.node-red/settings.js 2>&1 >>/dev/null
@@ -613,6 +625,11 @@ case $yn in
613625
fi
614626
echo -ne " Install extra Pi nodes $CHAR\r\n"
615627

628+
# If armv6 then remove the bcrypt binary to workaround illegal instruction error
629+
if uname -m | grep -q armv6l ; then
630+
$SUDO rm -rf /usr/lib/node_modules/node-red/node_modules/@node-rs | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
631+
fi
632+
616633
popd 2>&1 >>/dev/null
617634
if [ -d "$NODERED_HOME/.npm" ]; then
618635
$SUDO chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.npm 2>&1 >>/dev/null

0 commit comments

Comments
 (0)