]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/scripts/install.sh
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / scripts / install.sh
1 #!/bin/sh
2
3 # A word about this shell script:
4 #
5 # It must work everywhere, including on systems that lack
6 # a /bin/bash, map 'sh' to ksh, ksh97, bash, ash, or zsh,
7 # and potentially have either a posix shell or bourne
8 # shell living at /bin/sh.
9 #
10 # See this helpful document on writing portable shell scripts:
11 # http://www.gnu.org/s/hello/manual/autoconf/Portable-Shell.html
12 #
13 # The only shell it won't ever work on is cmd.exe.
14
15 if [ "x$0" = "xsh" ]; then
16   # run as curl | sh
17   # on some systems, you can just do cat>npm-install.sh
18   # which is a bit cuter.  But on others, &1 is already closed,
19   # so catting to another script file won't do anything.
20   # Follow Location: headers, and fail on errors
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 # See what "npm_config_*" things there are in the env,
37 # and make them permanent.
38 # If this fails, it's not such a big deal.
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 # make sure that node exists
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 node.js." >&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 # set the temp dir
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 # Try to find a suitable make
111 # If the MAKE environment var is set, use that.
112 # otherwise, try to find gmake, and then make.
113 # If no make is found, then just execute the necessary commands.
114
115 # XXX For some reason, make is building all the docs every time.  This
116 # is an annoying source of bugs. Figure out why this happens.
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   # echo "Installing without make. This may fail." >&2
139   make=NOMAKE
140 fi
141
142 # If there's no bash, then don't even try to clean
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   # switch based on node version.
162   # note that we can only use strict sh-compatible patterns here.
163   case $node_version in
164     0.[01234567].* | v0.[01234567].*)
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     *)
170       echo "install npm@latest"
171       t="latest"
172       ;;
173   esac
174 fi
175
176 # need to echo "" after, because Posix sed doesn't treat EOF
177 # as an implied end of line.
178 url=`(curl -SsL https://registry.npmjs.org/npm/$t; echo "") \
179      | sed -e 's/^.*tarball":"//' \
180      | sed -e 's/".*$//'`
181
182 ret=$?
183 if [ "x$url" = "x" ]; then
184   ret=125
185   # try without the -e arg to sed.
186   url=`(curl -SsL https://registry.npmjs.org/npm/$t; echo "") \
187        | sed 's/^.*tarball":"//' \
188        | sed 's/".*$//'`
189   ret=$?
190   if [ "x$url" = "x" ]; then
191     ret=125
192   fi
193 fi
194 if [ $ret -ne 0 ]; then
195   echo "Failed to get tarball url for npm/$t" >&2
196   exit $ret
197 fi
198
199
200 echo "fetching: $url" >&2
201
202 cd "$TMP" \
203   && curl -SsL "$url" \
204      | $tar -xzf - \
205   && cd "$TMP"/* \
206   && (ver=`"$node" bin/read-package-json.js package.json version`
207       isnpm10=0
208       if [ $ret -eq 0 ]; then
209         if [ -d node_modules ]; then
210           if "$node" node_modules/semver/bin/semver -v "$ver" -r "1"
211           then
212             isnpm10=1
213           fi
214         else
215           if "$node" bin/semver -v "$ver" -r ">=1.0"; then
216             isnpm10=1
217           fi
218         fi
219       fi
220
221       ret=0
222       if [ $isnpm10 -eq 1 ] && [ -f "scripts/clean-old.sh" ]; then
223         if [ "x$skipclean" = "x" ]; then
224           (exit 0)
225         else
226           clean=no
227         fi
228         if [ "x$clean" = "xno" ] \
229             || [ "x$clean" = "xn" ]; then
230           echo "Skipping 0.x cruft clean" >&2
231           ret=0
232         elif [ "x$clean" = "xy" ] || [ "x$clean" = "xyes" ]; then
233           NODE="$node" /bin/bash "scripts/clean-old.sh" "-y"
234           ret=$?
235         else
236           NODE="$node" /bin/bash "scripts/clean-old.sh" </dev/tty
237           ret=$?
238         fi
239       fi
240
241       if [ $ret -ne 0 ]; then
242         echo "Aborted 0.x cleanup.  Exiting." >&2
243         exit $ret
244       fi) \
245   && (if [ "x$configures" = "x" ]; then
246         (exit 0)
247       else
248         echo "./configure $configures"
249         echo "$configures" > npmrc
250       fi) \
251   && (if [ "$make" = "NOMAKE" ]; then
252         (exit 0)
253       elif "$make" uninstall install; then
254         (exit 0)
255       else
256         make="NOMAKE"
257       fi
258       if [ "$make" = "NOMAKE" ]; then
259         "$node" cli.js rm npm -gf
260         "$node" cli.js install -gf
261       fi) \
262   && cd "$BACK" \
263   && rm -rf "$TMP" \
264   && echo "It worked"
265
266 ret=$?
267 if [ $ret -ne 0 ]; then
268   echo "It failed" >&2
269 fi
270 exit $ret