1 | #!/bin/sh
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | if [ "x$0" = "xsh" ]; then
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | curl -f -L -s https://www.npmjs.org/install.sh > npm-install-$$.sh
|
22 | ret=$?
|
23 | if [ $ret -eq 0 ]; then
|
24 | (exit 0)
|
25 | else
|
26 | rm npm-install-$$.sh
|
27 | echo "Failed to download script" >&2
|
28 | exit $ret
|
29 | fi
|
30 | sh npm-install-$$.sh
|
31 | ret=$?
|
32 | rm npm-install-$$.sh
|
33 | exit $ret
|
34 | fi
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | configures="`env | grep 'npm_config_' | sed -e 's|^npm_config_||g'`"
|
40 |
|
41 | npm_config_loglevel="error"
|
42 | if [ "x$npm_debug" = "x" ]; then
|
43 | (exit 0)
|
44 | else
|
45 | echo "Running in debug mode."
|
46 | echo "Note that this requires bash or zsh."
|
47 | set -o xtrace
|
48 | set -o pipefail
|
49 | npm_config_loglevel="verbose"
|
50 | fi
|
51 | export npm_config_loglevel
|
52 |
|
53 |
|
54 | node=`which node 2>&1`
|
55 | ret=$?
|
56 | if [ $ret -eq 0 ] && [ -x "$node" ]; then
|
57 | (exit 0)
|
58 | else
|
59 | echo "npm cannot be installed without nodejs." >&2
|
60 | echo "Install node first, and then try again." >&2
|
61 | echo "" >&2
|
62 | echo "Maybe node is installed, but not in the PATH?" >&2
|
63 | echo "Note that running as sudo can change envs." >&2
|
64 | echo ""
|
65 | echo "PATH=$PATH" >&2
|
66 | exit $ret
|
67 | fi
|
68 |
|
69 |
|
70 | TMP="${TMPDIR}"
|
71 | if [ "x$TMP" = "x" ]; then
|
72 | TMP="/tmp"
|
73 | fi
|
74 | TMP="${TMP}/npm.$$"
|
75 | rm -rf "$TMP" || true
|
76 | mkdir "$TMP"
|
77 | if [ $? -ne 0 ]; then
|
78 | echo "failed to mkdir $TMP" >&2
|
79 | exit 1
|
80 | fi
|
81 |
|
82 | BACK="$PWD"
|
83 |
|
84 | ret=0
|
85 | tar="${TAR}"
|
86 | if [ -z "$tar" ]; then
|
87 | tar="${npm_config_tar}"
|
88 | fi
|
89 | if [ -z "$tar" ]; then
|
90 | tar=`which tar 2>&1`
|
91 | ret=$?
|
92 | fi
|
93 |
|
94 | if [ $ret -eq 0 ] && [ -x "$tar" ]; then
|
95 | echo "tar=$tar"
|
96 | echo "version:"
|
97 | $tar --version
|
98 | ret=$?
|
99 | fi
|
100 |
|
101 | if [ $ret -eq 0 ]; then
|
102 | (exit 0)
|
103 | else
|
104 | echo "No suitable tar program found."
|
105 | exit 1
|
106 | fi
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | MAKE=NOMAKE
|
118 |
|
119 | if [ "x$MAKE" = "x" ]; then
|
120 | make=`which gmake 2>&1`
|
121 | if [ $? -eq 0 ] && [ -x $make ]; then
|
122 | (exit 0)
|
123 | else
|
124 | make=`which make 2>&1`
|
125 | if [ $? -eq 0 ] && [ -x $make ]; then
|
126 | (exit 0)
|
127 | else
|
128 | make=NOMAKE
|
129 | fi
|
130 | fi
|
131 | else
|
132 | make="$MAKE"
|
133 | fi
|
134 |
|
135 | if [ -x "$make" ]; then
|
136 | (exit 0)
|
137 | else
|
138 |
|
139 | make=NOMAKE
|
140 | fi
|
141 |
|
142 |
|
143 | if [ -x "/bin/bash" ]; then
|
144 | (exit 0)
|
145 | else
|
146 | clean="no"
|
147 | fi
|
148 |
|
149 | node_version=`"$node" --version 2>&1`
|
150 | ret=$?
|
151 | if [ $ret -ne 0 ]; then
|
152 | echo "You need node to run this program." >&2
|
153 | echo "node --version reports: $node_version" >&2
|
154 | echo "with exit code = $ret" >&2
|
155 | echo "Please install node before continuing." >&2
|
156 | exit $ret
|
157 | fi
|
158 |
|
159 | t="${npm_install}"
|
160 | if [ -z "$t" ]; then
|
161 |
|
162 |
|
163 | case $node_version in
|
164 | 0.[012345].* | v0.[012345].*)
|
165 | echo "You are using an outdated and unsupported version of" >&2
|
166 | echo "node ($node_version). Please update node and try again." >&2
|
167 | exit 99
|
168 | ;;
|
169 | v0.[678].* | 0.[678].*)
|
170 | echo "install npm@1.1"
|
171 | t=1.1
|
172 | ;;
|
173 | *)
|
174 | echo "install npm@latest"
|
175 | t="latest"
|
176 | ;;
|
177 | esac
|
178 | fi
|
179 |
|
180 |
|
181 | cacert='
|
182 | -----BEGIN CERTIFICATE-----
|
183 | MIIChzCCAfACCQDauvz/KHp8ejANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC
|
184 | VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMQwwCgYDVQQKEwNucG0x
|
185 | IjAgBgNVBAsTGW5wbSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxDjAMBgNVBAMTBW5w
|
186 | bUNBMRcwFQYJKoZIhvcNAQkBFghpQGl6cy5tZTAeFw0xMTA5MDUwMTQ3MTdaFw0y
|
187 | MTA5MDIwMTQ3MTdaMIGHMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNV
|
188 | BAcTB09ha2xhbmQxDDAKBgNVBAoTA25wbTEiMCAGA1UECxMZbnBtIENlcnRpZmlj
|
189 | YXRlIEF1dGhvcml0eTEOMAwGA1UEAxMFbnBtQ0ExFzAVBgkqhkiG9w0BCQEWCGlA
|
190 | aXpzLm1lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLI4tIqPpRW+ACw9GE
|
191 | OgBlJZwK5f8nnKCLK629Pv5yJpQKs3DENExAyOgDcyaF0HD0zk8zTp+ZsLaNdKOz
|
192 | Gn2U181KGprGKAXP6DU6ByOJDWmTlY6+Ad1laYT0m64fERSpHw/hjD3D+iX4aMOl
|
193 | y0HdbT5m1ZGh6SJz3ZqxavhHLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAC4ySDbC
|
194 | l7W1WpLmtLGEQ/yuMLUf6Jy/vr+CRp4h+UzL+IQpCv8FfxsYE7dhf/bmWTEupBkv
|
195 | yNL18lipt2jSvR3v6oAHAReotvdjqhxddpe5Holns6EQd1/xEZ7sB1YhQKJtvUrl
|
196 | ZNufy1Jf1r0ldEGeA+0ISck7s+xSh9rQD2Op
|
197 | -----END CERTIFICATE-----
|
198 | '
|
199 |
|
200 | echo "$cacert" > "$TMP/cafile.crt"
|
201 | cacert="$TMP/cafile.crt"
|
202 |
|
203 |
|
204 |
|
205 | url=`(curl -SsL --cacert "$cacert" https://registry.npmjs.org/npm/$t; echo "") \
|
206 | | sed -e 's/^.*tarball":"//' \
|
207 | | sed -e 's/".*$//'`
|
208 |
|
209 | ret=$?
|
210 | if [ "x$url" = "x" ]; then
|
211 | ret=125
|
212 |
|
213 | url=`(curl -SsL --cacert "$cacert" https://registry.npmjs.org/npm/$t; echo "") \
|
214 | | sed 's/^.*tarball":"//' \
|
215 | | sed 's/".*$//'`
|
216 | ret=$?
|
217 | if [ "x$url" = "x" ]; then
|
218 | ret=125
|
219 | fi
|
220 | fi
|
221 | if [ $ret -ne 0 ]; then
|
222 | echo "Failed to get tarball url for npm/$t" >&2
|
223 | exit $ret
|
224 | fi
|
225 |
|
226 |
|
227 | echo "fetching: $url" >&2
|
228 |
|
229 | cd "$TMP" \
|
230 | && curl -SsL --cacert "$cacert" "$url" \
|
231 | | $tar -xzf - \
|
232 | && rm "$cacert" \
|
233 | && cd "$TMP"/* \
|
234 | && (req=`"$node" bin/read-package-json.js package.json engines.node`
|
235 | if [ -d node_modules ]; then
|
236 | "$node" node_modules/semver/bin/semver -v "$node_version" -r "$req"
|
237 | ret=$?
|
238 | else
|
239 | "$node" bin/semver.js -v "$node_version" -r "$req"
|
240 | ret=$?
|
241 | fi
|
242 | if [ $ret -ne 0 ]; then
|
243 | echo "You need node $req to run this program." >&2
|
244 | echo "node --version reports: $node_version" >&2
|
245 | echo "Please upgrade node before continuing." >&2
|
246 | exit $ret
|
247 | fi) \
|
248 | && (ver=`"$node" bin/read-package-json.js package.json version`
|
249 | isnpm10=0
|
250 | if [ $ret -eq 0 ]; then
|
251 | req=`"$node" bin/read-package-json.js package.json engines.node`
|
252 | if [ -d node_modules ]; then
|
253 | if "$node" node_modules/semver/bin/semver -v "$ver" -r "1"
|
254 | then
|
255 | isnpm10=1
|
256 | fi
|
257 | else
|
258 | if "$node" bin/semver -v "$ver" -r ">=1.0"; then
|
259 | isnpm10=1
|
260 | fi
|
261 | fi
|
262 | fi
|
263 |
|
264 | ret=0
|
265 | if [ $isnpm10 -eq 1 ] && [ -f "scripts/clean-old.sh" ]; then
|
266 | if [ "x$skipclean" = "x" ]; then
|
267 | (exit 0)
|
268 | else
|
269 | clean=no
|
270 | fi
|
271 | if [ "x$clean" = "xno" ] \
|
272 | || [ "x$clean" = "xn" ]; then
|
273 | echo "Skipping 0.x cruft clean" >&2
|
274 | ret=0
|
275 | elif [ "x$clean" = "xy" ] || [ "x$clean" = "xyes" ]; then
|
276 | NODE="$node" /bin/bash "scripts/clean-old.sh" "-y"
|
277 | ret=$?
|
278 | else
|
279 | NODE="$node" /bin/bash "scripts/clean-old.sh" </dev/tty
|
280 | ret=$?
|
281 | fi
|
282 | fi
|
283 |
|
284 | if [ $ret -ne 0 ]; then
|
285 | echo "Aborted 0.x cleanup. Exiting." >&2
|
286 | exit $ret
|
287 | fi) \
|
288 | && (if [ "x$configures" = "x" ]; then
|
289 | (exit 0)
|
290 | else
|
291 | echo "./configure "$configures
|
292 | echo "$configures" > npmrc
|
293 | fi) \
|
294 | && (if [ "$make" = "NOMAKE" ]; then
|
295 | (exit 0)
|
296 | elif "$make" uninstall install; then
|
297 | (exit 0)
|
298 | else
|
299 | make="NOMAKE"
|
300 | fi
|
301 | if [ "$make" = "NOMAKE" ]; then
|
302 | "$node" cli.js rm npm -gf
|
303 | "$node" cli.js install -gf
|
304 | fi) \
|
305 | && cd "$BACK" \
|
306 | && rm -rf "$TMP" \
|
307 | && echo "It worked"
|
308 |
|
309 | ret=$?
|
310 | if [ $ret -ne 0 ]; then
|
311 | echo "It failed" >&2
|
312 | fi
|
313 | exit $ret
|