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
2 changed files with 30 additions and 67 deletions

View File

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

View File

@@ -1,76 +1,41 @@
#!/bin/bash #!/bin/bash
# consider installing with apt when updated next # follows https://github.com/nodesource/distributions/blob/master/README.md#manual-installation
# https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
VERSION="v18.12.0" VERSION="20"
# command info # command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "config script to install NodeJs $VERSION" echo "config script to install NodeJs $VERSION"
echo "bonus.nodejs.sh [on|off|info]" echo "bonus.nodejs.sh [on|off]"
exit 1 exit 1
fi 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"
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 # switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then if [ "$1" = "1" ] || [ "$1" = "on" ]; then
# check if nodeJS was installed # check if nodeJS was installed
if [ "$(node -v)" = "${VERSION}" ]; then if node -v | grep "${VERSION}"; then
echo "nodeJS $VERSION is already installed" echo "nodeJS $VERSION is already installed"
else else
# install latest nodejs KEYRING=/usr/share/keyrings/nodesource.gpg
# https://github.com/nodejs/help/wiki/Installation curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
echo "*** Install NodeJS $VERSION-$DISTRO ***" # wget can also be used:
echo "VERSION: ${VERSION}" # wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
echo "DISTRO: ${DISTRO}" gpg --no-default-keyring --keyring "$KEYRING" --list-keys
echo sudo chmod a+r /usr/share/keyrings/nodesource.gpg
# download # Replace with the keyring above, if different
cd /home/admin/download || exit 1 KEYRING=/usr/share/keyrings/nodesource.gpg
wget -O node-$VERSION-$DISTRO.tar.xz https://nodejs.org/dist/$VERSION/node-$VERSION-$DISTRO.tar.xz # The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
# checksum # - For Debian distributions: jessie, sid, etc...
wget -O SHASUMS256.txt https://nodejs.org/dist/$VERSION/SHASUMS256.txt # - For Ubuntu distributions: xenial, bionic, etc...
if ! sha256sum -c SHASUMS256.txt --ignore-missing; then # - 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.
echo "FAIL: The checksum of node-$VERSION-$DISTRO.tar.xz is not found in the SHASUMS256.txt" DISTRO="$(lsb_release -s -c)"
rm -f node-$VERSION-$DISTRO.tar.xz* echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/node_$VERSION.x $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
exit 1 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
fi
echo "OK the checksum of nodeJS is OK" sudo apt-get update
sleep 3 sudo apt-get install -y nodejs
# 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
# check if nodeJS was installed # check if nodeJS was installed
if node -v; then if node -v; then
@@ -87,9 +52,9 @@ fi
# switch off # switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# setting value in raspiblitz config
echo "*** REMOVING NODEJS ***" 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." echo "OK NodeJS removed."
exit 0 exit 0
fi fi