Преглед изворни кода

Fix static analysis failures

Bob Mottram пре 7 година
родитељ
комит
65ded7b2eb
1 измењених фајлова са 38 додато и 39 уклоњено
  1. 38
    39
      src/freedombone-utils-nodejs

+ 38
- 39
src/freedombone-utils-nodejs Прегледај датотеку

62
 
62
 
63
 function mesh_install_nodejs {
63
 function mesh_install_nodejs {
64
     mesh_install_nodejs_prefix=
64
     mesh_install_nodejs_prefix=
65
-    if [ $rootdir ]; then
65
+    if [ "$rootdir" ]; then
66
         mesh_install_nodejs_prefix="chroot $rootdir"
66
         mesh_install_nodejs_prefix="chroot $rootdir"
67
     fi
67
     fi
68
 
68
 
70
     $mesh_install_nodejs_prefix apt-get -yq install libxext-dev libxtst-dev libxkbfile-dev
70
     $mesh_install_nodejs_prefix apt-get -yq install libxext-dev libxtst-dev libxkbfile-dev
71
     $mesh_install_nodejs_prefix apt-get -yq install apt-transport-https
71
     $mesh_install_nodejs_prefix apt-get -yq install apt-transport-https
72
     $mesh_install_nodejs_prefix wget https://deb.nodesource.com/gpgkey/nodesource.gpg.key -O /root/node.gpg.key
72
     $mesh_install_nodejs_prefix wget https://deb.nodesource.com/gpgkey/nodesource.gpg.key -O /root/node.gpg.key
73
-    if [ ! -f $rootdir/root/node.gpg.key ]; then
73
+    if [ ! -f "$rootdir/root/node.gpg.key" ]; then
74
         echo $'Unable to obtain gpg key for nodejs repo'
74
         echo $'Unable to obtain gpg key for nodejs repo'
75
         exit 6389252
75
         exit 6389252
76
     fi
76
     fi
77
     $mesh_install_nodejs_prefix apt-key add /root/node.gpg.key
77
     $mesh_install_nodejs_prefix apt-key add /root/node.gpg.key
78
-    echo "deb https://deb.nodesource.com/node_6.x stretch main" > $rootdir/etc/apt/sources.list.d/nodesource.list
79
-    echo "deb-src https://deb.nodesource.com/node_6.x stretch main" >> $rootdir/etc/apt/sources.list.d/nodesource.list
78
+    echo "deb https://deb.nodesource.com/node_6.x stretch main" > "$rootdir/etc/apt/sources.list.d/nodesource.list"
79
+    echo "deb-src https://deb.nodesource.com/node_6.x stretch main" >> "$rootdir/etc/apt/sources.list.d/nodesource.list"
80
 
80
 
81
     $mesh_install_nodejs_prefix apt-get update
81
     $mesh_install_nodejs_prefix apt-get update
82
     $mesh_install_nodejs_prefix apt-get -yq remove --purge nodejs
82
     $mesh_install_nodejs_prefix apt-get -yq remove --purge nodejs
83
 
83
 
84
-    if [ -d $rootdir/usr/local/lib/node_modules ]; then
85
-        rm -rf $rootdir/usr/local/lib/node_modules
84
+    if [ -d "$rootdir/usr/local/lib/node_modules" ]; then
85
+        rm -rf "$rootdir/usr/local/lib/node_modules"
86
     fi
86
     fi
87
-    if [ -f $rootdir/usr/local/bin/node ]; then
88
-        rm $rootdir/usr/local/bin/node
87
+    if [ -f "$rootdir/usr/local/bin/node" ]; then
88
+        rm "$rootdir/usr/local/bin/node"
89
     fi
89
     fi
90
-    if [ -f $rootdir/usr/bin/node ]; then
90
+    if [ -f "$rootdir/usr/bin/node" ]; then
91
         rm /usr/bin/node
91
         rm /usr/bin/node
92
     fi
92
     fi
93
-    if [ -f $rootdir/usr/bin/nodejs ]; then
94
-        rm $rootdir/usr/bin/nodejs
93
+    if [ -f "$rootdir/usr/bin/nodejs" ]; then
94
+        rm "$rootdir/usr/bin/nodejs"
95
     fi
95
     fi
96
 
96
 
97
     $mesh_install_nodejs_prefix apt-get -yq install nodejs
97
     $mesh_install_nodejs_prefix apt-get -yq install nodejs
98
 
98
 
99
-    if [ -f $rootdir/usr/bin/nodejs ]; then
100
-        cp $rootdir/usr/bin/nodejs $rootdir/usr/bin/node
99
+    if [ -f "$rootdir/usr/bin/nodejs" ]; then
100
+        cp "$rootdir/usr/bin/nodejs" "$rootdir/usr/bin/node"
101
     fi
101
     fi
102
 
102
 
103
-    if [ ! -f ${rootdir}/usr/bin/node ]; then
104
-        if [ ! -f ${rootdir}/usr/local/bin/node ]; then
105
-            if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
103
+    if [ ! -f "${rootdir}/usr/bin/node" ]; then
104
+        if [ ! -f "${rootdir}/usr/local/bin/node" ]; then
105
+            if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then
106
                 echo $'nodejs was not installed'
106
                 echo $'nodejs was not installed'
107
                 exit 63962
107
                 exit 63962
108
             fi
108
             fi
109
         fi
109
         fi
110
     fi
110
     fi
111
 
111
 
112
-    if [ ! -f $rootdir/usr/bin/node ]; then
112
+    if [ ! -f "$rootdir/usr/bin/node" ]; then
113
         echo $'/usr/bin/node not found'
113
         echo $'/usr/bin/node not found'
114
         exit 7235728
114
         exit 7235728
115
     fi
115
     fi
118
 
118
 
119
     $mesh_install_nodejs_prefix npm config set unsafe-perm true
119
     $mesh_install_nodejs_prefix npm config set unsafe-perm true
120
     $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save
120
     $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save
121
-    if [ -f $rootdir/usr/local/bin/npm ]; then
122
-        cp $rootdir/usr/local/bin/npm /usr/bin/npm
121
+    if [ -f "$rootdir/usr/local/bin/npm" ]; then
122
+        cp "$rootdir/usr/local/bin/npm" /usr/bin/npm
123
     fi
123
     fi
124
-    cp $rootdir/usr/bin/npm $rootdir/root/npm
124
+    cp "$rootdir/usr/bin/npm" "$rootdir/root/npm"
125
 
125
 
126
     # update from the old debian nodejs version
126
     # update from the old debian nodejs version
127
     $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g n@${NODEJS_N_VERSION} --save
127
     $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g n@${NODEJS_N_VERSION} --save
128
     $mesh_install_nodejs_prefix n --arch $N_ARCH ${NODEJS_VERSION}
128
     $mesh_install_nodejs_prefix n --arch $N_ARCH ${NODEJS_VERSION}
129
-    cp $rootdir/root/npm $rootdir/usr/bin/npm
129
+    cp "$rootdir/root/npm" "$rootdir/usr/bin/npm"
130
 
130
 
131
     # deliberate second install of npm
131
     # deliberate second install of npm
132
     $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save
132
     $mesh_install_nodejs_prefix npm install --arch=$NPM_ARCH -g npm@${NPM_VERSION} --save
133
-    if [ -f $rootdir/usr/local/bin/npm ]; then
134
-        cp $rootdir/usr/local/bin/npm /usr/bin/npm
133
+    if [ -f "$rootdir/usr/local/bin/npm" ]; then
134
+        cp "$rootdir/usr/local/bin/npm" /usr/bin/npm
135
     fi
135
     fi
136
-    cp $rootdir/usr/bin/npm $rootdir/root/npm
136
+    cp "$rootdir/usr/bin/npm" "$rootdir/root/npm"
137
 
137
 
138
     # check the version numbers
138
     # check the version numbers
139
-    cat <<EOF > $rootdir/usr/bin/test_nodejs_install
139
+    cat <<EOF > "$rootdir/usr/bin/test_nodejs_install"
140
 #!/bin/bash
140
 #!/bin/bash
141
 node_version=\$(node -v)
141
 node_version=\$(node -v)
142
 if [[ "\$node_version" != "v${NODEJS_VERSION}" ]]; then
142
 if [[ "\$node_version" != "v${NODEJS_VERSION}" ]]; then
149
     exit 2
149
     exit 2
150
 fi
150
 fi
151
 EOF
151
 EOF
152
-    chmod +x $rootdir/usr/bin/test_nodejs_install
153
-    $mesh_install_nodejs_prefix /usr/bin/test_nodejs_install
154
-    if [ ! "$?" = "0" ]; then
152
+    chmod +x "$rootdir/usr/bin/test_nodejs_install"
153
+    if ! $mesh_install_nodejs_prefix /usr/bin/test_nodejs_install; then
155
         echo $"nodejs version numbers did not match. Architecture is $NPM_ARCH."
154
         echo $"nodejs version numbers did not match. Architecture is $NPM_ARCH."
156
         exit 76835282
155
         exit 76835282
157
     fi
156
     fi
158
-    rm $rootdir/usr/bin/test_nodejs_install
157
+    rm "$rootdir/usr/bin/test_nodejs_install"
159
 }
158
 }
160
 
159
 
161
 function remove_nodejs {
160
 function remove_nodejs {
162
-    if [ ! $1 ]; then
161
+    if [ ! "$1" ]; then
163
         return
162
         return
164
     fi
163
     fi
165
-    if [ ! -f $NODEJS_INSTALLED_APPS_FILE ]; then
164
+    if [ ! -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
166
         #remove_app nodejs
165
         #remove_app nodejs
167
         return
166
         return
168
     fi
167
     fi
169
-    sed -i "/install_${1}/d" $NODEJS_INSTALLED_APPS_FILE
170
-    if ! grep -q "install_" $NODEJS_INSTALLED_APPS_FILE; then
168
+    sed -i "/install_${1}/d" "$NODEJS_INSTALLED_APPS_FILE"
169
+    if ! grep -q "install_" "$NODEJS_INSTALLED_APPS_FILE"; then
171
         apt-get -yq remove --purge nodejs
170
         apt-get -yq remove --purge nodejs
172
 
171
 
173
         if [ -f /usr/bin/nodejs ]; then
172
         if [ -f /usr/bin/nodejs ]; then
188
 
187
 
189
         remove_app nodejs
188
         remove_app nodejs
190
 
189
 
191
-        rm $NODEJS_INSTALLED_APPS_FILE
190
+        rm "$NODEJS_INSTALLED_APPS_FILE"
192
 
191
 
193
         apt-get -yq autoremove
192
         apt-get -yq autoremove
194
     fi
193
     fi
218
 }
217
 }
219
 
218
 
220
 function install_nodejs {
219
 function install_nodejs {
221
-    if [ $INSTALLING_MESH ]; then
220
+    if [ "$INSTALLING_MESH" ]; then
222
         mesh_install_nodejs
221
         mesh_install_nodejs
223
         return
222
         return
224
     fi
223
     fi
227
         return
226
         return
228
     fi
227
     fi
229
 
228
 
230
-    if [ ! $ARCHITECTURE ]; then
229
+    if [ ! "$ARCHITECTURE" ]; then
231
         ARCHITECTURE=$(uname -m)
230
         ARCHITECTURE=$(uname -m)
232
     fi
231
     fi
233
     rootdir=
232
     rootdir=
250
         exit 5274527
249
         exit 5274527
251
     fi
250
     fi
252
 
251
 
253
-    if [ $1 ]; then
254
-        if ! grep -q "install_${1}" $NODEJS_INSTALLED_APPS_FILE; then
255
-            echo "install_${1}" >> $NODEJS_INSTALLED_APPS_FILE
252
+    if [ "$1" ]; then
253
+        if ! grep -q "install_${1}" "$NODEJS_INSTALLED_APPS_FILE"; then
254
+            echo "install_${1}" >> "$NODEJS_INSTALLED_APPS_FILE"
256
         fi
255
         fi
257
     fi
256
     fi
258
 
257