From 65ded7b2eb42ad43db76ac820f692a67bf489981 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 2 Mar 2018 20:33:00 +0000 Subject: [PATCH] Fix static analysis failures --- src/freedombone-utils-nodejs | 77 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/src/freedombone-utils-nodejs b/src/freedombone-utils-nodejs index f83be531..28b13cb2 100755 --- a/src/freedombone-utils-nodejs +++ b/src/freedombone-utils-nodejs @@ -62,7 +62,7 @@ function get_npm_arch { function mesh_install_nodejs { mesh_install_nodejs_prefix= - if [ $rootdir ]; then + if [ "$rootdir" ]; then mesh_install_nodejs_prefix="chroot $rootdir" fi @@ -70,46 +70,46 @@ function mesh_install_nodejs { $mesh_install_nodejs_prefix apt-get -yq install libxext-dev libxtst-dev libxkbfile-dev $mesh_install_nodejs_prefix apt-get -yq install apt-transport-https $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 + if [ ! -f "$rootdir/root/node.gpg.key" ]; then echo $'Unable to obtain gpg key for nodejs repo' exit 6389252 fi $mesh_install_nodejs_prefix apt-key add /root/node.gpg.key - echo "deb https://deb.nodesource.com/node_6.x stretch main" > $rootdir/etc/apt/sources.list.d/nodesource.list - echo "deb-src https://deb.nodesource.com/node_6.x stretch main" >> $rootdir/etc/apt/sources.list.d/nodesource.list + echo "deb https://deb.nodesource.com/node_6.x stretch main" > "$rootdir/etc/apt/sources.list.d/nodesource.list" + echo "deb-src https://deb.nodesource.com/node_6.x stretch main" >> "$rootdir/etc/apt/sources.list.d/nodesource.list" $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 [ -d "$rootdir/usr/local/lib/node_modules" ]; then + rm -rf "$rootdir/usr/local/lib/node_modules" fi - if [ -f $rootdir/usr/local/bin/node ]; then - rm $rootdir/usr/local/bin/node + if [ -f "$rootdir/usr/local/bin/node" ]; then + rm "$rootdir/usr/local/bin/node" fi - if [ -f $rootdir/usr/bin/node ]; then + if [ -f "$rootdir/usr/bin/node" ]; then rm /usr/bin/node fi - if [ -f $rootdir/usr/bin/nodejs ]; then - rm $rootdir/usr/bin/nodejs + if [ -f "$rootdir/usr/bin/nodejs" ]; then + rm "$rootdir/usr/bin/nodejs" fi $mesh_install_nodejs_prefix apt-get -yq install nodejs - if [ -f $rootdir/usr/bin/nodejs ]; then - cp $rootdir/usr/bin/nodejs $rootdir/usr/bin/node + if [ -f "$rootdir/usr/bin/nodejs" ]; then + cp "$rootdir/usr/bin/nodejs" "$rootdir/usr/bin/node" fi - if [ ! -f ${rootdir}/usr/bin/node ]; then - if [ ! -f ${rootdir}/usr/local/bin/node ]; then - if [ ! -f ${rootdir}/usr/bin/nodejs ]; then + if [ ! -f "${rootdir}/usr/bin/node" ]; then + if [ ! -f "${rootdir}/usr/local/bin/node" ]; then + if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then echo $'nodejs was not installed' exit 63962 fi fi fi - if [ ! -f $rootdir/usr/bin/node ]; then + if [ ! -f "$rootdir/usr/bin/node" ]; then echo $'/usr/bin/node not found' exit 7235728 fi @@ -118,25 +118,25 @@ function mesh_install_nodejs { $mesh_install_nodejs_prefix npm config set unsafe-perm true $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save - if [ -f $rootdir/usr/local/bin/npm ]; then - cp $rootdir/usr/local/bin/npm /usr/bin/npm + if [ -f "$rootdir/usr/local/bin/npm" ]; then + cp "$rootdir/usr/local/bin/npm" /usr/bin/npm fi - cp $rootdir/usr/bin/npm $rootdir/root/npm + cp "$rootdir/usr/bin/npm" "$rootdir/root/npm" # update from the old debian nodejs version $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g n@${NODEJS_N_VERSION} --save $mesh_install_nodejs_prefix n --arch $N_ARCH ${NODEJS_VERSION} - cp $rootdir/root/npm $rootdir/usr/bin/npm + cp "$rootdir/root/npm" "$rootdir/usr/bin/npm" # deliberate second install of npm $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save - if [ -f $rootdir/usr/local/bin/npm ]; then - cp $rootdir/usr/local/bin/npm /usr/bin/npm + if [ -f "$rootdir/usr/local/bin/npm" ]; then + cp "$rootdir/usr/local/bin/npm" /usr/bin/npm fi - cp $rootdir/usr/bin/npm $rootdir/root/npm + cp "$rootdir/usr/bin/npm" "$rootdir/root/npm" # check the version numbers - cat < $rootdir/usr/bin/test_nodejs_install + cat < "$rootdir/usr/bin/test_nodejs_install" #!/bin/bash node_version=\$(node -v) if [[ "\$node_version" != "v${NODEJS_VERSION}" ]]; then @@ -149,25 +149,24 @@ if [[ "\$npm_version" != "${NPM_VERSION}" ]]; then exit 2 fi EOF - chmod +x $rootdir/usr/bin/test_nodejs_install - $mesh_install_nodejs_prefix /usr/bin/test_nodejs_install - if [ ! "$?" = "0" ]; then + 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." exit 76835282 fi - rm $rootdir/usr/bin/test_nodejs_install + rm "$rootdir/usr/bin/test_nodejs_install" } function remove_nodejs { - if [ ! $1 ]; then + if [ ! "$1" ]; then return fi - if [ ! -f $NODEJS_INSTALLED_APPS_FILE ]; then + if [ ! -f "$NODEJS_INSTALLED_APPS_FILE" ]; then #remove_app nodejs return fi - sed -i "/install_${1}/d" $NODEJS_INSTALLED_APPS_FILE - if ! grep -q "install_" $NODEJS_INSTALLED_APPS_FILE; then + sed -i "/install_${1}/d" "$NODEJS_INSTALLED_APPS_FILE" + if ! grep -q "install_" "$NODEJS_INSTALLED_APPS_FILE"; then apt-get -yq remove --purge nodejs if [ -f /usr/bin/nodejs ]; then @@ -188,7 +187,7 @@ function remove_nodejs { remove_app nodejs - rm $NODEJS_INSTALLED_APPS_FILE + rm "$NODEJS_INSTALLED_APPS_FILE" apt-get -yq autoremove fi @@ -218,7 +217,7 @@ function upgrade_nodejs { } function install_nodejs { - if [ $INSTALLING_MESH ]; then + if [ "$INSTALLING_MESH" ]; then mesh_install_nodejs return fi @@ -227,7 +226,7 @@ function install_nodejs { return fi - if [ ! $ARCHITECTURE ]; then + if [ ! "$ARCHITECTURE" ]; then ARCHITECTURE=$(uname -m) fi rootdir= @@ -250,9 +249,9 @@ function install_nodejs { exit 5274527 fi - if [ $1 ]; then - if ! grep -q "install_${1}" $NODEJS_INSTALLED_APPS_FILE; then - echo "install_${1}" >> $NODEJS_INSTALLED_APPS_FILE + if [ "$1" ]; then + if ! grep -q "install_${1}" "$NODEJS_INSTALLED_APPS_FILE"; then + echo "install_${1}" >> "$NODEJS_INSTALLED_APPS_FILE" fi fi