Use upgrade flag to prevent global node modules from being removed

This commit is contained in:
Bob Mottram 2018-03-30 12:50:00 +01:00
parent f6becba882
commit f1ca6f0329
1 changed files with 11 additions and 2 deletions

View File

@ -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
}