From f1ca6f03299cf38f9801cfdef72bd50c037b8e03 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 30 Mar 2018 12:50:00 +0100 Subject: [PATCH] Use upgrade flag to prevent global node modules from being removed --- src/freedombone-utils-nodejs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/freedombone-utils-nodejs b/src/freedombone-utils-nodejs index d3a66816..04bb0ee1 100755 --- a/src/freedombone-utils-nodejs +++ b/src/freedombone-utils-nodejs @@ -72,6 +72,7 @@ function mesh_install_nodejs { $mesh_install_nodejs_prefix wget https://deb.nodesource.com/gpgkey/nodesource.gpg.key -O /root/node.gpg.key if [ ! -f "$rootdir/root/node.gpg.key" ]; then echo $'Unable to obtain gpg key for nodejs repo' + NODE_UPGRADE= exit 6389252 fi $mesh_install_nodejs_prefix apt-key add /root/node.gpg.key @@ -82,9 +83,12 @@ function mesh_install_nodejs { $mesh_install_nodejs_prefix apt-get update $mesh_install_nodejs_prefix apt-get -yq remove --purge nodejs - if [ -d "$rootdir/usr/local/lib/node_modules" ]; then - rm -rf "$rootdir/usr/local/lib/node_modules" + if [ ! $NODE_UPGRADE ]; then + if [ -d "$rootdir/usr/local/lib/node_modules" ]; then + rm -rf "$rootdir/usr/local/lib/node_modules" + fi fi + if [ -f "$rootdir/usr/local/bin/node" ]; then rm "$rootdir/usr/local/bin/node" fi @@ -111,6 +115,7 @@ function mesh_install_nodejs { if [ ! -f "${rootdir}/usr/local/bin/node" ]; then if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then echo $'nodejs was not installed' + NODE_UPGRADE= exit 63962 fi fi @@ -118,6 +123,7 @@ function mesh_install_nodejs { if [ ! -f "$rootdir/usr/bin/node" ]; then echo $'/usr/bin/node not found' + NODE_UPGRADE= exit 7235728 fi @@ -162,9 +168,11 @@ EOF chmod +x "$rootdir/usr/bin/test_nodejs_install" if ! $mesh_install_nodejs_prefix /usr/bin/test_nodejs_install; then echo $"nodejs version numbers did not match. Architecture is $NPM_ARCH." + NODE_UPGRADE= exit 76835282 fi rm "$rootdir/usr/bin/test_nodejs_install" + NODE_UPGRADE= } function nodejs_upgrade { @@ -187,6 +195,7 @@ function nodejs_upgrade { fi read_config_param ARCHITECTURE get_npm_arch + NODE_UPGRADE=1 rootdir= mesh_install_nodejs }