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 {
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 <<EOF > $rootdir/usr/bin/test_nodejs_install
cat <<EOF > "$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