瀏覽代碼

Use upgrade flag to prevent global node modules from being removed

Bob Mottram 7 年之前
父節點
當前提交
f1ca6f0329
共有 1 個文件被更改,包括 11 次插入2 次删除
  1. 11
    2
      src/freedombone-utils-nodejs

+ 11
- 2
src/freedombone-utils-nodejs 查看文件

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
+        NODE_UPGRADE=
75
         exit 6389252
76
         exit 6389252
76
     fi
77
     fi
77
     $mesh_install_nodejs_prefix apt-key add /root/node.gpg.key
78
     $mesh_install_nodejs_prefix apt-key add /root/node.gpg.key
82
     $mesh_install_nodejs_prefix apt-get update
83
     $mesh_install_nodejs_prefix apt-get update
83
     $mesh_install_nodejs_prefix apt-get -yq remove --purge nodejs
84
     $mesh_install_nodejs_prefix apt-get -yq remove --purge nodejs
84
 
85
 
85
-    if [ -d "$rootdir/usr/local/lib/node_modules" ]; then
86
-        rm -rf "$rootdir/usr/local/lib/node_modules"
86
+    if [ ! $NODE_UPGRADE ]; then
87
+        if [ -d "$rootdir/usr/local/lib/node_modules" ]; then
88
+            rm -rf "$rootdir/usr/local/lib/node_modules"
89
+        fi
87
     fi
90
     fi
91
+
88
     if [ -f "$rootdir/usr/local/bin/node" ]; then
92
     if [ -f "$rootdir/usr/local/bin/node" ]; then
89
         rm "$rootdir/usr/local/bin/node"
93
         rm "$rootdir/usr/local/bin/node"
90
     fi
94
     fi
111
         if [ ! -f "${rootdir}/usr/local/bin/node" ]; then
115
         if [ ! -f "${rootdir}/usr/local/bin/node" ]; then
112
             if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then
116
             if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then
113
                 echo $'nodejs was not installed'
117
                 echo $'nodejs was not installed'
118
+                NODE_UPGRADE=
114
                 exit 63962
119
                 exit 63962
115
             fi
120
             fi
116
         fi
121
         fi
118
 
123
 
119
     if [ ! -f "$rootdir/usr/bin/node" ]; then
124
     if [ ! -f "$rootdir/usr/bin/node" ]; then
120
         echo $'/usr/bin/node not found'
125
         echo $'/usr/bin/node not found'
126
+        NODE_UPGRADE=
121
         exit 7235728
127
         exit 7235728
122
     fi
128
     fi
123
 
129
 
162
     chmod +x "$rootdir/usr/bin/test_nodejs_install"
168
     chmod +x "$rootdir/usr/bin/test_nodejs_install"
163
     if ! $mesh_install_nodejs_prefix /usr/bin/test_nodejs_install; then
169
     if ! $mesh_install_nodejs_prefix /usr/bin/test_nodejs_install; then
164
         echo $"nodejs version numbers did not match. Architecture is $NPM_ARCH."
170
         echo $"nodejs version numbers did not match. Architecture is $NPM_ARCH."
171
+        NODE_UPGRADE=
165
         exit 76835282
172
         exit 76835282
166
     fi
173
     fi
167
     rm "$rootdir/usr/bin/test_nodejs_install"
174
     rm "$rootdir/usr/bin/test_nodejs_install"
175
+    NODE_UPGRADE=
168
 }
176
 }
169
 
177
 
170
 function nodejs_upgrade {
178
 function nodejs_upgrade {
187
     fi
195
     fi
188
     read_config_param ARCHITECTURE
196
     read_config_param ARCHITECTURE
189
     get_npm_arch
197
     get_npm_arch
198
+    NODE_UPGRADE=1
190
     rootdir=
199
     rootdir=
191
     mesh_install_nodejs
200
     mesh_install_nodejs
192
 }
201
 }