Nodejs update to v20.x with apt (#4032)

* nodejs update to v20.x with apt
* remove info option from command info
This commit is contained in:
openoms 2023-07-29 16:08:17 +02:00 committed by GitHub
parent df662a1349
commit 1da893ed06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 67 deletions

View File

@ -150,17 +150,16 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "# Compile WebUI"
/home/admin/config.scripts/bonus.nodejs.sh on
source <(/home/admin/config.scripts/bonus.nodejs.sh info)
if ! npm install --global yarn; then
echo "error='install yarn failed'"
exit 1
fi
${NODEPATH}/yarn config set --home enableTelemetry 0
if ! ${NODEPATH}/yarn install; then
yarn config set --home enableTelemetry 0
if ! yarn install; then
echo "error='yarn install failed'"
exit 1
fi
if ! ${NODEPATH}/yarn build; then
if ! yarn build; then
echo "error='yarn build failed'"
exit 1
fi
@ -192,9 +191,8 @@ if [ "$1" = "update" ]; then
git reset --hard origin/${currentBranch}
newCommit=$(git rev-parse HEAD)
if [ "${oldCommit}" != "${newCommit}" ]; then
source <(/home/admin/config.scripts/bonus.nodejs.sh info)
${NODEPATH}/yarn install
${NODEPATH}/yarn build
yarn install
yarn build
sudo rm -r /var/www/public/* 2>/dev/null
sudo cp -r /home/blitzapi/blitz_web/build/* /var/www/public
sudo chown www-data:www-data -R /var/www/public

View File

@ -1,76 +1,41 @@
#!/bin/bash
# consider installing with apt when updated next
# https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
# follows https://github.com/nodesource/distributions/blob/master/README.md#manual-installation
VERSION="v18.12.0"
VERSION="20"
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "config script to install NodeJs $VERSION"
echo "bonus.nodejs.sh [on|off|info]"
exit 1
fi
# determine nodeJS VERSION and DISTRO
isARM=$(uname -m | grep -c 'arm')
isAARCH64=$(uname -m | grep -c 'aarch64')
isX86_64=$(uname -m | grep -c 'x86_64')
if [ ${isARM} -eq 1 ] ; then
DISTRO="linux-armv7l"
elif [ ${isAARCH64} -eq 1 ] ; then
DISTRO="linux-arm64"
elif [ ${isX86_64} -eq 1 ] ; then
DISTRO="linux-x64"
elif [ ${#DISTRO} -eq 0 ]; then
echo "# FAIL: Was not able to determine architecture"
echo "config script to install NodeJs $VERSION"
echo "bonus.nodejs.sh [on|off]"
exit 1
fi
# info
if [ "$1" = "info" ]; then
echo "NODEVERSION='${VERSION}'"
echo "NODEDISTRO='${DISTRO}'"
echo "NODEPATH='/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin'"
exit 0
fi
# switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
# check if nodeJS was installed
if [ "$(node -v)" = "${VERSION}" ]; then
if node -v | grep "${VERSION}"; then
echo "nodeJS $VERSION is already installed"
else
# install latest nodejs
# https://github.com/nodejs/help/wiki/Installation
echo "*** Install NodeJS $VERSION-$DISTRO ***"
echo "VERSION: ${VERSION}"
echo "DISTRO: ${DISTRO}"
echo
KEYRING=/usr/share/keyrings/nodesource.gpg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
# wget can also be used:
# wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
gpg --no-default-keyring --keyring "$KEYRING" --list-keys
sudo chmod a+r /usr/share/keyrings/nodesource.gpg
# download
cd /home/admin/download || exit 1
wget -O node-$VERSION-$DISTRO.tar.xz https://nodejs.org/dist/$VERSION/node-$VERSION-$DISTRO.tar.xz
# checksum
wget -O SHASUMS256.txt https://nodejs.org/dist/$VERSION/SHASUMS256.txt
if ! sha256sum -c SHASUMS256.txt --ignore-missing; then
echo "FAIL: The checksum of node-$VERSION-$DISTRO.tar.xz is not found in the SHASUMS256.txt"
rm -f node-$VERSION-$DISTRO.tar.xz*
exit 1
fi
echo "OK the checksum of nodeJS is OK"
sleep 3
# install
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs
rm -f node-$VERSION-$DISTRO.tar.xz*
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
sudo ln -sf /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/node /usr/bin/node
sudo ln -sf /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/npm /usr/bin/npm
sudo ln -sf /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/npx /usr/bin/npx
# add to PATH permanently
sudo bash -c "echo 'PATH=\$PATH:/usr/local/lib/nodejs/node-${VERSION}-${DISTRO}/bin/' >> /etc/profile"
echo
# Replace with the keyring above, if different
KEYRING=/usr/share/keyrings/nodesource.gpg
# The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
# - For Debian distributions: jessie, sid, etc...
# - For Ubuntu distributions: xenial, bionic, etc...
# - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
DISTRO="$(lsb_release -s -c)"
echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/node_$VERSION.x $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/node_$VERSION.x $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install -y nodejs
# check if nodeJS was installed
if node -v; then
@ -87,9 +52,9 @@ fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# setting value in raspiblitz config
echo "*** REMOVING NODEJS ***"
sudo rm -rf /usr/local/lib/nodejs
sudo apt remove nodejs -y
sudo rm /etc/apt/sources.list.d/nodesource.list
echo "OK NodeJS removed."
exit 0
fi