Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 539 lines (467 sloc) 12.798 kb
1137c97 @isaacs more stuff
authored
1 #!/bin/bash
2
3 # This program contains parts of narwhal's "sea" program,
4 # as well as bits borrowed from Tim Caswell's "nvm"
5
6 # nave install <version>
7 # Fetch the version of node and install it in nave's folder.
8
9 # nave use <version>
10 # Install the <version> if it isn't already, and then start
11 # a subshell with that version's folder at the start of the
12 # $PATH
13
bce616a @isaacs Add NAVE_DEBUG, and use ~/.nave instead of the nave dir
authored
14 # nave use <version> program.js
1137c97 @isaacs more stuff
authored
15 # Like "nave use", but have the subshell start the program.js
16 # immediately.
17
18 # When told to use a version:
19 # Ensure that the version exists, install it, and
20 # then add its prefix to the PATH, and start a subshell.
21
bce616a @isaacs Add NAVE_DEBUG, and use ~/.nave instead of the nave dir
authored
22 if [ "$NAVE_DEBUG" != "" ]; then
23 set -x
24 fi
25
daefc95 @isaacs Be more correct about handling version families.
authored
26 # Use fancy pants globs
27 shopt -s extglob
28
d1115b0 @isaacs Respect the TAR env, if set
authored
29 tar=${TAR-tar}
30
1137c97 @isaacs more stuff
authored
31 main () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
32 local SELF_PATH DIR SYM
1137c97 @isaacs more stuff
authored
33 # get the absolute path of the executable
eeb9654 @isaacs Get the SELF_PATH better when run without the ./ on teh relative path
authored
34 SELF_PATH="$0"
35 if [ "${SELF_PATH:0:1}" != "." ] && [ "${SELF_PATH:0:1}" != "/" ]; then
36 SELF_PATH=./"$SELF_PATH"
37 fi
38 SELF_PATH=$( cd -P -- "$(dirname -- "$SELF_PATH")" \
1137c97 @isaacs more stuff
authored
39 && pwd -P \
40 ) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
41
42 # resolve symlinks
43 while [ -h "$SELF_PATH" ]; do
44 DIR=$(dirname -- "$SELF_PATH")
45 SYM=$(readlink -- "$SELF_PATH")
46 SELF_PATH=$( cd -- "$DIR" \
47 && cd -- $(dirname -- "$SYM") \
48 && pwd \
49 )/$(basename -- "$SYM")
50 done
51
bce616a @isaacs Add NAVE_DEBUG, and use ~/.nave instead of the nave dir
authored
52 if ! [ -d "$NAVE_DIR" ]; then
53 if [ -d "$HOME" ]; then
54 NAVE_DIR="$HOME"/.nave
55 else
4e689f6 @isaacs Don't put stuff directly in /usr/local.
authored
56 NAVE_DIR=/usr/local/lib/nave
bce616a @isaacs Add NAVE_DEBUG, and use ~/.nave instead of the nave dir
authored
57 fi
58 fi
59 if ! [ -d "$NAVE_DIR" ] && ! mkdir -p -- "$NAVE_DIR"; then
60 NAVE_DIR="$(dirname -- "$SELF_PATH")"
61 fi
62
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
63 # set up the naverc init file.
81b3b04 @isaacs Only execute .bashrc if not a login shell
authored
64 # Important! Update this number any time the init content is changed.
65 local rcversion="#2"
66 if ! [ -f "$NAVE_DIR/naverc" ] \
67 || [ "$(head -n1 "$NAVE_DIR/naverc")" != "$rcversion" ]; then
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
68 cat > "$NAVE_DIR/naverc" <<RC
81b3b04 @isaacs Only execute .bashrc if not a login shell
authored
69 $rcversion
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
70 [ "\$NAVE_DEBUG" != "" ] && set -x || true
71 if [ "\$NAVE_LOGIN" != "" ]; then
72 [ -f ~/.bash_profile ] && . ~/.bash_profile || true
73 [ -f ~/.bash_login ] && . ~/.bash_login || true
74 [ -f ~/.profile ] && . ~/.profile || true
81b3b04 @isaacs Only execute .bashrc if not a login shell
authored
75 else
76 [ -f ~/.bashrc ] && . ~/.bashrc || true
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
77 fi
78 export PATH=\$NAVEPATH:\$PATH
79 [ -f ~/.naverc ] && . ~/.naverc || true
80 RC
81 fi
82
83 # couldn't write file
81b3b04 @isaacs Only execute .bashrc if not a login shell
authored
84 if ! [ -f "$NAVE_DIR/naverc" ] \
85 || [ "$(head -n1 "$NAVE_DIR/naverc")" != "$rcversion" ]; then
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
86 fail "Nave dir $NAVE_DIR is not writable."
87 fi
88
bce616a @isaacs Add NAVE_DEBUG, and use ~/.nave instead of the nave dir
authored
89 export NAVE_DIR
90 export NAVE_SRC="$NAVE_DIR/src"
91 export NAVE_ROOT="$NAVE_DIR/installed"
1137c97 @isaacs more stuff
authored
92 ensure_dir "$NAVE_SRC"
93 ensure_dir "$NAVE_ROOT"
0d79e42 @isaacs whitespace
authored
94
1137c97 @isaacs more stuff
authored
95 local cmd="$1"
96 shift
97 case $cmd in
3d645fc @isaacs Refactor ls-* functions to all use the same sort, and to sort and pretti...
authored
98 ls-remote | ls-all)
99 cmd="nave_${cmd/-/_}"
1f67500 @tj Added ls-remote
tj authored
100 ;;
e850ed1 @isaacs rough sketch of named envs
authored
101 # use)
102 # cmd="nave_named"
103 # ;;
104 install | fetch | use | clean | test | named | \
fd89663 @welwood08 Expose nave_has and nave_installed functions as commands for easier scri...
welwood08 authored
105 ls | uninstall | usemain | latest | stable | has | installed )
1137c97 @isaacs more stuff
authored
106 cmd="nave_$cmd"
107 ;;
108 * )
109 cmd="nave_help"
110 ;;
111 esac
3d645fc @isaacs Refactor ls-* functions to all use the same sort, and to sort and pretti...
authored
112 $cmd "$@" && exit 0 || fail "failed somehow"
1137c97 @isaacs more stuff
authored
113 }
114
115 function enquote_all () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
116 local ARG ARGS
1137c97 @isaacs more stuff
authored
117 ARGS=""
118 for ARG in "$@"; do
119 [ -n "$ARGS" ] && ARGS="$ARGS "
120 ARGS="$ARGS'""$( echo " $ARG" \
121 | cut -c 2- \
122 | sed 's/'"'"'/'"'"'"'"'"'"'"'"'/g' \
123 )""'"
124 done
125 echo "$ARGS"
126 }
127
128 ensure_dir () {
129 if ! [ -d "$1" ]; then
130 mkdir -p -- "$1" || fail "couldn't create $1"
131 fi
132 }
c160e5e @isaacs Spacing
authored
133
1137c97 @isaacs more stuff
authored
134 remove_dir () {
135 if [ -d "$1" ]; then
136 rm -rf -- "$1" || fail "Could not remove $1"
137 fi
138 }
139
140 fail () {
141 echo "$@" >&2
142 exit 1
143 }
144
145 nave_fetch () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
146 local version=$(ver "$1")
8a02f53 @isaacs Handle HEAD as a version. Use 8 jobs. Clean up messes.
authored
147 if nave_has "$version"; then
1137c97 @isaacs more stuff
authored
148 echo "already fetched $version" >&2
149 return 0
150 fi
151
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
152 local src="$NAVE_SRC/$version"
1137c97 @isaacs more stuff
authored
153 remove_dir "$src"
154 ensure_dir "$src"
923c16f @isaacs Close #19 new url scheme for 0.5
authored
155
6c9e612 @welwood08 Abstract out build() method
welwood08 authored
156 local url
157 local urls=(
158 "http://nodejs.org/dist/v$version/node-v$version.tar.gz"
159 "http://nodejs.org/dist/node-v$version.tar.gz"
160 "http://nodejs.org/dist/node-$version.tar.gz"
161 )
162 for url in "${urls[@]}"; do
52c1451 @isaacs Handle curl failures properly
authored
163 curl -#Lf "$url" > "$src".tgz
6c9e612 @welwood08 Abstract out build() method
welwood08 authored
164 if [ $? -eq 0 ]; then
52c1451 @isaacs Handle curl failures properly
authored
165 $tar xzf "$src".tgz -C "$src" --strip-components=1
166 if [ $? -eq 0 ]; then
530e86f @isaacs Fix #32 Print informational stuff to stderr
authored
167 echo "fetched from $url" >&2
52c1451 @isaacs Handle curl failures properly
authored
168 return 0
169 fi
6c9e612 @welwood08 Abstract out build() method
welwood08 authored
170 fi
171 done
172
173 remove_dir "$src"
174 fail "Couldn't fetch $version"
1137c97 @isaacs more stuff
authored
175 }
176
218dfd4 @welwood08 Re-use build code across install and usemain functions.
welwood08 authored
177 build () {
178 local version="$1"
179 nave_fetch "$version"
180 local src="$NAVE_SRC/$version"
181
182 ( cd -- "$src"
d0af355 @isaacs Read NAVE_CONFIG array from env when building
authored
183 [ -f ~/.naverc ] && . ~/.naverc || true
184 if [ "$NAVE_CONFIG" == "" ]; then
185 NAVE_CONFIG=("--debug")
186 fi
187 JOBS=${JOBS:-2} ./configure "${NAVE_CONFIG[@]}" --prefix="$2" \
218dfd4 @welwood08 Re-use build code across install and usemain functions.
welwood08 authored
188 || fail "Failed to configure $version"
189 JOBS=${JOBS:-2} make \
190 || fail "Failed to make $version"
191 make install || fail "Failed to install $version"
192 ) || fail "fail"
193 }
194
20740ec @isaacs Add usemain, since TJ asked so nice, and it actually is quite handy.
authored
195 nave_usemain () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
196 if [ ${NAVELVL-0} -gt 0 ]; then
197 fail "Can't usemain inside a nave subshell. Exit to main shell."
198 fi
199 local version=$(ver "$1")
20740ec @isaacs Add usemain, since TJ asked so nice, and it actually is quite handy.
authored
200 local current=$(node -v || true)
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
201 local wn=$(which node || true)
202 local prefix="/usr/local"
203 if [ "x$wn" != "x" ]; then
204 prefix="${wn/\/bin\/node/}"
205 if [ "x$prefix" == "x" ]; then
206 prefix="/usr/local"
207 fi
2e69cc0 @isaacs Add support for 'latest' as a version string
authored
208 fi
20740ec @isaacs Add usemain, since TJ asked so nice, and it actually is quite handy.
authored
209 current="${current/v/}"
210 if [ "$current" == "$version" ]; then
530e86f @isaacs Fix #32 Print informational stuff to stderr
authored
211 echo "$version already installed" >&2
20740ec @isaacs Add usemain, since TJ asked so nice, and it actually is quite handy.
authored
212 return 0
213 fi
8d709bb @isaacs Liberal use of hash -r whenever the PATH changes, and respect JOBS env
authored
214
6c9e612 @welwood08 Abstract out build() method
welwood08 authored
215 build "$version" "$prefix"
20740ec @isaacs Add usemain, since TJ asked so nice, and it actually is quite handy.
authored
216 }
217
1137c97 @isaacs more stuff
authored
218 nave_install () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
219 local version=$(ver "$1")
8a02f53 @isaacs Handle HEAD as a version. Use 8 jobs. Clean up messes.
authored
220 if nave_installed "$version"; then
1137c97 @isaacs more stuff
authored
221 echo "Already installed: $version" >&2
222 return 0
223 fi
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
224 local install="$NAVE_ROOT/$version"
1137c97 @isaacs more stuff
authored
225 remove_dir "$install"
226 ensure_dir "$install"
218dfd4 @welwood08 Re-use build code across install and usemain functions.
welwood08 authored
227
228 build "$version" "$install"
1137c97 @isaacs more stuff
authored
229 }
c160e5e @isaacs Spacing
authored
230
1137c97 @isaacs more stuff
authored
231 nave_test () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
232 local version=$(ver "$1")
1137c97 @isaacs more stuff
authored
233 nave_fetch "$version"
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
234 local src="$NAVE_SRC/$version"
1137c97 @isaacs more stuff
authored
235 ( cd -- "$src"
d0af355 @isaacs Read NAVE_CONFIG array from env when building
authored
236 [ -f ~/.naverc ] && . ~/.naverc || true
237 if [ "$NAVE_CONFIG" == "" ]; then
238 NAVE_CONFIG=("--debug")
239 fi
240 ./configure "${NAVE_CONFIG[@]}" || fail "failed to ./configure --debug"
1137c97 @isaacs more stuff
authored
241 make test-all || fail "Failed tests"
242 ) || fail "failed"
243 }
244
245 nave_ls () {
8b86b4a @kaichen fix the path issue
kaichen authored
246 ls -- $NAVE_SRC | version_list "src" \
247 && ls -- $NAVE_ROOT | version_list "installed" \
3d4ff49 @isaacs Support for named envs
authored
248 && nave_ls_named \
3d645fc @isaacs Refactor ls-* functions to all use the same sort, and to sort and pretti...
authored
249 || return 1
250 }
c160e5e @isaacs Spacing
authored
251
3d645fc @isaacs Refactor ls-* functions to all use the same sort, and to sort and pretti...
authored
252 nave_ls_remote () {
253 curl -s http://nodejs.org/dist/ \
254 | version_list "remote" \
255 || return 1
256 }
c160e5e @isaacs Spacing
authored
257
3d4ff49 @isaacs Support for named envs
authored
258 nave_ls_named () {
259 echo "named:"
260 ls -- "$NAVE_ROOT" \
261 | egrep -v '[0-9]+\.[0-9]+\.[0-9]+' \
262 | sort \
263 | while read name; do
264 echo "$name: $(ver $($NAVE_ROOT/$name/bin/node -v 2>/dev/null))"
265 done
266 }
267
3d645fc @isaacs Refactor ls-* functions to all use the same sort, and to sort and pretti...
authored
268 nave_ls_all () {
269 nave_ls \
270 && nave_ls_remote \
271 || return 1
272 }
c160e5e @isaacs Spacing
authored
273
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
274 ver () {
275 local version="$1"
3d4ff49 @isaacs Support for named envs
authored
276 local nonames="$2"
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
277 version="${version/v/}"
278 case $version in
279 latest | stable) nave_$version ;;
daefc95 @isaacs Be more correct about handling version families.
authored
280 +([0-9])\.+([0-9])) nave_version_family "$version" ;;
3d4ff49 @isaacs Support for named envs
authored
281 +([0-9])\.+([0-9])\.+([0-9])) echo $version ;;
282 *) [ "$nonames" = "" ] && echo $version ;;
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
283 esac
284 }
7d5ac87 @isaacs Support x.y version family as a version
authored
285
286 nave_version_family () {
287 local family="$1"
288 family="${family/v/}"
289 curl -s http://nodejs.org/dist/ \
290 | egrep -o $family'\.[0-9]+' \
291 | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \
292 | tail -n1
293 }
294
2e69cc0 @isaacs Add support for 'latest' as a version string
authored
295 nave_latest () {
296 curl -s http://nodejs.org/dist/ \
297 | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
298 | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \
299 | tail -n1
300 }
c160e5e @isaacs Spacing
authored
301
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
302 nave_stable () {
303 curl -s http://nodejs.org/dist/ \
304 | egrep -o '[0-9]+\.[2468]\.[0-9]+' \
305 | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \
306 | tail -n1
307 }
308
3d4ff49 @isaacs Support for named envs
authored
309 version_list_named () {
310 egrep -v '[0-9]+\.[0-9]+\.[0-9]+' \
311 | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \
312 | organize_version_list \
313 || return 1
314 }
315
3d645fc @isaacs Refactor ls-* functions to all use the same sort, and to sort and pretti...
authored
316 version_list () {
317 echo "$1:"
318 egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
319 | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \
320 | organize_version_list \
321 || return 1
1137c97 @isaacs more stuff
authored
322 }
323
3d645fc @isaacs Refactor ls-* functions to all use the same sort, and to sort and pretti...
authored
324 organize_version_list () {
325 local i=0
326 local v
327 while read v; do
328 if [ $i -eq 8 ]; then
329 i=0
330 echo "$v"
331 else
332 let 'i = i + 1'
333 echo -ne "$v\t"
334 fi
335 done
336 echo ""
337 [ $i -ne 0 ] && echo ""
338 return 0
339 }
340
1137c97 @isaacs more stuff
authored
341 nave_has () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
342 local version=$(ver "$1")
1137c97 @isaacs more stuff
authored
343 [ -d "$NAVE_SRC/$version" ] || return 1
344 }
c160e5e @isaacs Spacing
authored
345
1137c97 @isaacs more stuff
authored
346 nave_installed () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
347 local version=$(ver "$1")
1137c97 @isaacs more stuff
authored
348 [ -d "$NAVE_ROOT/$version/bin" ] || return 1
0d79e42 @isaacs whitespace
authored
349 }
1137c97 @isaacs more stuff
authored
350
351 nave_use () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
352 local version=$(ver "$1")
3d4ff49 @isaacs Support for named envs
authored
353
354 # if it's not a version number, then treat as a name.
355 case "$version" in
356 +([0-9])\.+([0-9])\.+([0-9])) ;;
357 *)
358 nave_named "$@"
359 return $?
360 ;;
361 esac
362
0e1b749 @isaacs add a check when 'nave use' is called with no args
authored
363 if [ -z "$version" ]; then
364 fail "Must supply a version"
365 fi
3d4ff49 @isaacs Support for named envs
authored
366
367 if [ "$version" == "$NAVENAME" ]; then
530e86f @isaacs Fix #32 Print informational stuff to stderr
authored
368 echo "already using $version" >&2
1137c97 @isaacs more stuff
authored
369 if [ $# -gt 1 ]; then
370 shift
2123dda @isaacs Don't run programs as node. Just run them.
authored
371 "$@"
1137c97 @isaacs more stuff
authored
372 fi
e850ed1 @isaacs rough sketch of named envs
authored
373 return $?
1137c97 @isaacs more stuff
authored
374 fi
3d4ff49 @isaacs Support for named envs
authored
375
376 nave_install "$version" || fail "failed to install $version"
e94d80f @isaacs Set global prefix, as well as binroot/etc.
authored
377 local prefix="$NAVE_ROOT/$version"
378 local bin="$prefix/bin"
379 local lib="$prefix/lib/node"
380 local man="$prefix/share/man"
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
381 local lvl=$[ ${NAVELVL-0} + 1 ]
530e86f @isaacs Fix #32 Print informational stuff to stderr
authored
382 echo "using $version" >&2
1137c97 @isaacs more stuff
authored
383 if [ $# -gt 1 ]; then
384 shift
8d709bb @isaacs Liberal use of hash -r whenever the PATH changes, and respect JOBS env
authored
385 hash -r
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
386 NAVELVL=$lvl NAVE="$version" \
387 NAVEPATH="$bin" \
e850ed1 @isaacs rough sketch of named envs
authored
388 NAVEVERSION="$version" \
3d4ff49 @isaacs Support for named envs
authored
389 NAVENAME="$version" \
0e1b749 @isaacs add a check when 'nave use' is called with no args
authored
390 npm_config_binroot="$bin" npm_config_root="$lib" \
e850ed1 @isaacs rough sketch of named envs
authored
391 npm_config_manroot="$man" \
e94d80f @isaacs Set global prefix, as well as binroot/etc.
authored
392 npm_config_prefix="$prefix" \
33367eb @isaacs Set npm configs and NODE_PATH in the env.
authored
393 NODE_PATH="$lib" \
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
394 NAVE_LOGIN="" \
d5942a7 @isaacs Properly source rcfile when running a command directly
authored
395 "$SHELL" -c ". $(enquote_all $NAVE_DIR/naverc); $(enquote_all "$@")"
8d709bb @isaacs Liberal use of hash -r whenever the PATH changes, and respect JOBS env
authored
396 hash -r
1137c97 @isaacs more stuff
authored
397 else
8d709bb @isaacs Liberal use of hash -r whenever the PATH changes, and respect JOBS env
authored
398 hash -r
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
399 NAVELVL=$lvl NAVE="$version" \
400 NAVEPATH="$bin" \
e850ed1 @isaacs rough sketch of named envs
authored
401 NAVEVERSION="$version" \
3d4ff49 @isaacs Support for named envs
authored
402 NAVENAME="$version" \
0e1b749 @isaacs add a check when 'nave use' is called with no args
authored
403 npm_config_binroot="$bin" npm_config_root="$lib" \
e850ed1 @isaacs rough sketch of named envs
authored
404 npm_config_manroot="$man" \
e94d80f @isaacs Set global prefix, as well as binroot/etc.
authored
405 npm_config_prefix="$prefix" \
33367eb @isaacs Set npm configs and NODE_PATH in the env.
authored
406 NODE_PATH="$lib" \
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
407 NAVE_LOGIN="1" \
408 "$SHELL" --rcfile "$NAVE_DIR/naverc"
8d709bb @isaacs Liberal use of hash -r whenever the PATH changes, and respect JOBS env
authored
409 hash -r
1137c97 @isaacs more stuff
authored
410 fi
e850ed1 @isaacs rough sketch of named envs
authored
411 return $?
1137c97 @isaacs more stuff
authored
412 }
413
e850ed1 @isaacs rough sketch of named envs
authored
414 nave_named () {
415 local name="$1"
416 shift
3d4ff49 @isaacs Support for named envs
authored
417
418 local version=$(ver "$1" NONAMES)
419 if [ "$version" != "" ]; then
420 shift
421 fi
422
423 add_named_env "$name" "$version" || fail "failed to create $name env"
424
425 if [ "$name" == "$NAVENAME" ] && [ "$version" == "$NAVEVERSION" ]; then
530e86f @isaacs Fix #32 Print informational stuff to stderr
authored
426 echo "already using $name" >&2
e850ed1 @isaacs rough sketch of named envs
authored
427 if [ $# -gt 0 ]; then
2123dda @isaacs Don't run programs as node. Just run them.
authored
428 "$@"
e850ed1 @isaacs rough sketch of named envs
authored
429 fi
430 return $?
431 fi
3d4ff49 @isaacs Support for named envs
authored
432
433 if [ "$version" = "" ]; then
434 version="$(ver "$("$NAVE_ROOT/$name/bin/node" -v 2>/dev/null)")"
e850ed1 @isaacs rough sketch of named envs
authored
435 fi
3d4ff49 @isaacs Support for named envs
authored
436
e850ed1 @isaacs rough sketch of named envs
authored
437 local bin="$NAVE_ROOT/$name/bin"
438 local lib="$NAVE_ROOT/$name/lib/node"
439 local man="$NAVE_ROOT/$name/share/man"
440 ensure_dir bin
441 ensure_dir lib
442 ensure_dir man
3d4ff49 @isaacs Support for named envs
authored
443
e850ed1 @isaacs rough sketch of named envs
authored
444 local lvl=$[ ${NAVELVL-0} + 1 ]
445 # get the version
446 if [ $# -gt 0 ]; then
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
447 NAVEPATH="$bin" \
e850ed1 @isaacs rough sketch of named envs
authored
448 NAVELVL=$lvl \
3d4ff49 @isaacs Support for named envs
authored
449 NAVE="$version-$name" \
e850ed1 @isaacs rough sketch of named envs
authored
450 NAVEVERSION="$version" \
451 NAVENAME="$name" \
452 NODE_PATH="$lib" \
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
453 NAVE_LOGIN="" \
d5942a7 @isaacs Properly source rcfile when running a command directly
authored
454 "$SHELL" -c ". $(enquote_all $NAVE_DIR/naverc); $(enquote_all "$@")"
e850ed1 @isaacs rough sketch of named envs
authored
455 else
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
456 NAVEPATH="$bin" \
e850ed1 @isaacs rough sketch of named envs
authored
457 NAVELVL=$lvl \
3d4ff49 @isaacs Support for named envs
authored
458 NAVE="$version-$name" \
e850ed1 @isaacs rough sketch of named envs
authored
459 NAVEVERSION="$version" \
460 NAVENAME="$name" \
461 NODE_PATH="$lib" \
7666933 @isaacs Work around cases where PATH is set explicitly in .bashrc
authored
462 NAVE_LOGIN="1" \
463 "$SHELL" --rcfile "$NAVE_DIR/naverc"
e850ed1 @isaacs rough sketch of named envs
authored
464 fi
465 return $?
466 }
467
468 add_named_env () {
469 local name="$1"
3d4ff49 @isaacs Support for named envs
authored
470 local version="$2"
471 local cur="$(ver "$($NAVE_ROOT/$name/bin/node -v 2>/dev/null)" "NONAMES")"
472
473 if [ "$version" != "" ]; then
474 version="$(ver "$version" "NONAMES")"
475 else
476 version="$cur"
477 fi
478
479 if [ "$version" = "" ]; then
480 echo "What version of node?"
481 read -p "stable, latest, x.y, or x.y.z > " version
482 version=$(ver "$version")
483 fi
484
485 # if that version is already there, then nothing to do.
486 if [ "$cur" = "$version" ]; then
487 return 0
488 fi
489
530e86f @isaacs Fix #32 Print informational stuff to stderr
authored
490 echo "Creating new env named '$name' using node $version" >&2
3d4ff49 @isaacs Support for named envs
authored
491
e850ed1 @isaacs rough sketch of named envs
authored
492 nave_install "$version" || fail "failed to install $version"
3d4ff49 @isaacs Support for named envs
authored
493 ensure_dir "$NAVE_ROOT/$name/bin"
494 ensure_dir "$NAVE_ROOT/$name/lib/node"
495 ensure_dir "$NAVE_ROOT/$name/lib/node_modules"
496 ensure_dir "$NAVE_ROOT/$name/share/man"
e850ed1 @isaacs rough sketch of named envs
authored
497
3d4ff49 @isaacs Support for named envs
authored
498 ln -sf -- "$NAVE_ROOT/$version/bin/node" "$NAVE_ROOT/$name/bin/node"
499 ln -sf -- "$NAVE_ROOT/$version/bin/node-waf" "$NAVE_ROOT/$name/bin/node-waf"
500 }
e850ed1 @isaacs rough sketch of named envs
authored
501
1137c97 @isaacs more stuff
authored
502 nave_clean () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
503 remove_dir "$NAVE_SRC/$(ver "$1")"
1137c97 @isaacs more stuff
authored
504 }
3d4ff49 @isaacs Support for named envs
authored
505
1137c97 @isaacs more stuff
authored
506 nave_uninstall () {
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
507 remove_dir "$NAVE_ROOT/$(ver "$1")"
1137c97 @isaacs more stuff
authored
508 }
509
510 nave_help () {
2da1027 @tj Populated help
tj authored
511 cat <<EOF
512
513 Usage: nave <cmd>
514
515 Commands:
516
3d4ff49 @isaacs Support for named envs
authored
517 install <version> Install the version passed (ex: 0.1.103)
518 use <version> Enter a subshell where <version> is being used
2123dda @isaacs Don't run programs as node. Just run them.
authored
519 use <ver> <program> Enter a subshell, and run "<program>", then exit
3d4ff49 @isaacs Support for named envs
authored
520 use <name> <ver> Create a named env, using the specified version.
521 If the name already exists, but the version differs,
522 then it will update the link.
523 usemain <version> Install in /usr/local/bin (ie, use as your main nodejs)
524 clean <version> Delete the source code for <version>
525 uninstall <version> Delete the install for <version>
526 ls List versions currently installed
527 ls-remote List remote node versions
528 ls-all List remote and local node versions
529 latest Show the most recent dist version
530 help Output help information
2da1027 @tj Populated help
tj authored
531
ada82fa @isaacs Support "stable" as a shorthand for "latest 0.2.x"
authored
532 <version> can be the string "latest" to get the latest distribution.
533 <version> can be the string "stable" to get the latest stable version.
2e69cc0 @isaacs Add support for 'latest' as a version string
authored
534
2da1027 @tj Populated help
tj authored
535 EOF
1137c97 @isaacs more stuff
authored
536 }
537
538 main "$@"
Something went wrong with that request. Please try again.