Fix static analysis failures

This commit is contained in:
Bob Mottram 2018-03-02 20:33:00 +00:00
parent dd2faeb37c
commit 65ded7b2eb
1 changed files with 38 additions and 39 deletions

View File

@ -62,7 +62,7 @@ function get_npm_arch {
function mesh_install_nodejs { function mesh_install_nodejs {
mesh_install_nodejs_prefix= mesh_install_nodejs_prefix=
if [ $rootdir ]; then if [ "$rootdir" ]; then
mesh_install_nodejs_prefix="chroot $rootdir" mesh_install_nodejs_prefix="chroot $rootdir"
fi 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 libxext-dev libxtst-dev libxkbfile-dev
$mesh_install_nodejs_prefix apt-get -yq install apt-transport-https $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 $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' echo $'Unable to obtain gpg key for nodejs repo'
exit 6389252 exit 6389252
fi fi
$mesh_install_nodejs_prefix apt-key add /root/node.gpg.key $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 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-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 update
$mesh_install_nodejs_prefix apt-get -yq remove --purge nodejs $mesh_install_nodejs_prefix apt-get -yq remove --purge nodejs
if [ -d $rootdir/usr/local/lib/node_modules ]; then if [ -d "$rootdir/usr/local/lib/node_modules" ]; then
rm -rf $rootdir/usr/local/lib/node_modules rm -rf "$rootdir/usr/local/lib/node_modules"
fi fi
if [ -f $rootdir/usr/local/bin/node ]; then if [ -f "$rootdir/usr/local/bin/node" ]; then
rm $rootdir/usr/local/bin/node rm "$rootdir/usr/local/bin/node"
fi fi
if [ -f $rootdir/usr/bin/node ]; then if [ -f "$rootdir/usr/bin/node" ]; then
rm /usr/bin/node rm /usr/bin/node
fi fi
if [ -f $rootdir/usr/bin/nodejs ]; then if [ -f "$rootdir/usr/bin/nodejs" ]; then
rm $rootdir/usr/bin/nodejs rm "$rootdir/usr/bin/nodejs"
fi fi
$mesh_install_nodejs_prefix apt-get -yq install nodejs $mesh_install_nodejs_prefix apt-get -yq install nodejs
if [ -f $rootdir/usr/bin/nodejs ]; then if [ -f "$rootdir/usr/bin/nodejs" ]; then
cp $rootdir/usr/bin/nodejs $rootdir/usr/bin/node cp "$rootdir/usr/bin/nodejs" "$rootdir/usr/bin/node"
fi fi
if [ ! -f ${rootdir}/usr/bin/node ]; then if [ ! -f "${rootdir}/usr/bin/node" ]; then
if [ ! -f ${rootdir}/usr/local/bin/node ]; then if [ ! -f "${rootdir}/usr/local/bin/node" ]; then
if [ ! -f ${rootdir}/usr/bin/nodejs ]; then if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then
echo $'nodejs was not installed' echo $'nodejs was not installed'
exit 63962 exit 63962
fi fi
fi fi
fi fi
if [ ! -f $rootdir/usr/bin/node ]; then if [ ! -f "$rootdir/usr/bin/node" ]; then
echo $'/usr/bin/node not found' echo $'/usr/bin/node not found'
exit 7235728 exit 7235728
fi fi
@ -118,25 +118,25 @@ function mesh_install_nodejs {
$mesh_install_nodejs_prefix npm config set unsafe-perm true $mesh_install_nodejs_prefix npm config set unsafe-perm true
$mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save
if [ -f $rootdir/usr/local/bin/npm ]; then if [ -f "$rootdir/usr/local/bin/npm" ]; then
cp $rootdir/usr/local/bin/npm /usr/bin/npm cp "$rootdir/usr/local/bin/npm" /usr/bin/npm
fi fi
cp $rootdir/usr/bin/npm $rootdir/root/npm cp "$rootdir/usr/bin/npm" "$rootdir/root/npm"
# update from the old debian nodejs version # 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 npm install --arch=$NPM_ARCH -g n@${NODEJS_N_VERSION} --save
$mesh_install_nodejs_prefix n --arch $N_ARCH ${NODEJS_VERSION} $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 # deliberate second install of npm
$mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save
if [ -f $rootdir/usr/local/bin/npm ]; then if [ -f "$rootdir/usr/local/bin/npm" ]; then
cp $rootdir/usr/local/bin/npm /usr/bin/npm cp "$rootdir/usr/local/bin/npm" /usr/bin/npm
fi fi
cp $rootdir/usr/bin/npm $rootdir/root/npm cp "$rootdir/usr/bin/npm" "$rootdir/root/npm"
# check the version numbers # check the version numbers
cat <<EOF > $rootdir/usr/bin/test_nodejs_install cat <<EOF > "$rootdir/usr/bin/test_nodejs_install"
#!/bin/bash #!/bin/bash
node_version=\$(node -v) node_version=\$(node -v)
if [[ "\$node_version" != "v${NODEJS_VERSION}" ]]; then if [[ "\$node_version" != "v${NODEJS_VERSION}" ]]; then
@ -149,25 +149,24 @@ if [[ "\$npm_version" != "${NPM_VERSION}" ]]; then
exit 2 exit 2
fi fi
EOF EOF
chmod +x $rootdir/usr/bin/test_nodejs_install chmod +x "$rootdir/usr/bin/test_nodejs_install"
$mesh_install_nodejs_prefix /usr/bin/test_nodejs_install if ! $mesh_install_nodejs_prefix /usr/bin/test_nodejs_install; then
if [ ! "$?" = "0" ]; then
echo $"nodejs version numbers did not match. Architecture is $NPM_ARCH." echo $"nodejs version numbers did not match. Architecture is $NPM_ARCH."
exit 76835282 exit 76835282
fi fi
rm $rootdir/usr/bin/test_nodejs_install rm "$rootdir/usr/bin/test_nodejs_install"
} }
function remove_nodejs { function remove_nodejs {
if [ ! $1 ]; then if [ ! "$1" ]; then
return return
fi fi
if [ ! -f $NODEJS_INSTALLED_APPS_FILE ]; then if [ ! -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
#remove_app nodejs #remove_app nodejs
return return
fi fi
sed -i "/install_${1}/d" $NODEJS_INSTALLED_APPS_FILE sed -i "/install_${1}/d" "$NODEJS_INSTALLED_APPS_FILE"
if ! grep -q "install_" $NODEJS_INSTALLED_APPS_FILE; then if ! grep -q "install_" "$NODEJS_INSTALLED_APPS_FILE"; then
apt-get -yq remove --purge nodejs apt-get -yq remove --purge nodejs
if [ -f /usr/bin/nodejs ]; then if [ -f /usr/bin/nodejs ]; then
@ -188,7 +187,7 @@ function remove_nodejs {
remove_app nodejs remove_app nodejs
rm $NODEJS_INSTALLED_APPS_FILE rm "$NODEJS_INSTALLED_APPS_FILE"
apt-get -yq autoremove apt-get -yq autoremove
fi fi
@ -218,7 +217,7 @@ function upgrade_nodejs {
} }
function install_nodejs { function install_nodejs {
if [ $INSTALLING_MESH ]; then if [ "$INSTALLING_MESH" ]; then
mesh_install_nodejs mesh_install_nodejs
return return
fi fi
@ -227,7 +226,7 @@ function install_nodejs {
return return
fi fi
if [ ! $ARCHITECTURE ]; then if [ ! "$ARCHITECTURE" ]; then
ARCHITECTURE=$(uname -m) ARCHITECTURE=$(uname -m)
fi fi
rootdir= rootdir=
@ -250,9 +249,9 @@ function install_nodejs {
exit 5274527 exit 5274527
fi fi
if [ $1 ]; then if [ "$1" ]; then
if ! grep -q "install_${1}" $NODEJS_INSTALLED_APPS_FILE; then if ! grep -q "install_${1}" "$NODEJS_INSTALLED_APPS_FILE"; then
echo "install_${1}" >> $NODEJS_INSTALLED_APPS_FILE echo "install_${1}" >> "$NODEJS_INSTALLED_APPS_FILE"
fi fi
fi fi