From 33fe399457d154ad7dbabaa96711cd0f62ce913a Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Thu, 14 Sep 2017 13:19:30 +0100
Subject: [PATCH] Update node version on mesh build

---
 src/freedombone-image-customise |  8 +-------
 src/freedombone-utils-nodejs    | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise
index de95e087c..42114ee3e 100755
--- a/src/freedombone-image-customise
+++ b/src/freedombone-image-customise
@@ -562,13 +562,7 @@ INSTALL_DIR=$HOME/build
 INSTALLING_MESH=
 
 install_patchwork() {
-    NPM_ARCH='ia32'
-    if [[ $ARCHITECTURE == 'arm'* ]]; then
-        NPM_ARCH='armv7l'
-    fi
-    if [[ $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'amd64' ]]; then
-        NPM_ARCH='x64'
-    fi
+    get_npm_arch
 
     git clone https://github.com/ssbc/patchwork $rootdir/etc/patchwork
 
diff --git a/src/freedombone-utils-nodejs b/src/freedombone-utils-nodejs
index 4fdb4a4c6..ed680ed6b 100755
--- a/src/freedombone-utils-nodejs
+++ b/src/freedombone-utils-nodejs
@@ -43,6 +43,16 @@ NPM_VERSION='4.0.5'
 # so that it can be removed if tere are no apps which need it
 NODEJS_INSTALLED_APPS_FILE=$HOME/.nodejs-apps
 
+function get_npm_arch {
+    NPM_ARCH='ia32'
+    if [[ $ARCHITECTURE == 'arm'* ]]; then
+        NPM_ARCH='armv7l'
+    fi
+    if [[ $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'amd64' ]]; then
+        NPM_ARCH='x64'
+    fi
+}
+
 function mesh_install_nodejs {
     chroot "$rootdir" apt-get -yq install g++ m4 libtool automake nodejs curl
     chroot "$rootdir" apt-get -yq install libxext-dev libxtst-dev libxkbfile-dev
@@ -73,6 +83,14 @@ function mesh_install_nodejs {
         sed -i "s|t=\"\${npm_install}\"|t=\"$NPM_VERSION\"|g" $rootdir/root/npm_install.sh
         chroot "$rootdir" /root/npm_install.sh
     fi
+    if [ ! -f $rootdir/usr/bin/npm ]; then
+        echo $'npm was not installed'
+        exit 5290462
+    fi
+
+    # update from the old debian nodejs version
+    get_npm_arch
+    chroot "$rootdir" npm install --arch=$NPM_ARCH node@$NODEJS_VERSION -g
 }
 
 function remove_nodejs {
-- 
GitLab