-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvx.sh
executable file
·64 lines (52 loc) · 1.11 KB
/
nvx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh -e
SCRIPT="$(basename $0)"
log() {
echo "[$SCRIPT] $@" >&2
}
die() {
log "$@"
exit 1
}
if [ $# -lt 2 ]; then
die "Usage: $SCRIPT NODE_VERSION command..."
fi
VERSION="$1"
MIRROR="http://nodejs.org/dist"
if [ -z "$NVX_DIR" ]; then
NVX_DIR="${HOME:-/tmp}/.nvx"
fi
get_os() {
case `uname -s` in
Linux) echo 'linux' ;;
*) die "OS not supported" ;;
esac
}
get_arch() {
case `uname -m` in
x86_64)
echo 'x64' ;;
i*86)
echo 'x86' ;;
*)
die "ARCH not supported" ;;
esac
}
if [ ! -e "$NVX_DIR/$VERSION" ]; then
OS=`get_os`
ARCH=`get_arch`
DIRNAME="node-${VERSION}-${OS}-${ARCH}"
TARBALL="${DIRNAME}.tar.gz"
TARBALL_URL="$MIRROR/$VERSION/$TARBALL"
TMP=$(mktemp --tmpdir -d nvx-XXXXXX)
log "downloading $TARBALL..."
curl -sf "$TARBALL_URL" -o "$TMP/$TARBALL" || die "$TARBALL not found"
tar xzf "$TMP/$TARBALL" -C "$TMP"
log "installing $VERSION..."
mkdir -p "$NVX_DIR"
mv "$TMP/$DIRNAME" "$NVX_DIR/$VERSION"
rm -r "$TMP"
fi
shift
export PATH="$NVX_DIR/$VERSION/bin:$PATH"
export NODE_PATH="$NVX_DIR/$VERSION/lib/node_modules:$NODE_PATH"
exec "$@"