-
Notifications
You must be signed in to change notification settings - Fork 33
/
node-install
executable file
·84 lines (70 loc) · 2.35 KB
/
node-install
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
while getopts fh OPT
do
case $OPT in
"f") FLAG_FORCE="TRUE" ;;
"h") FLAG_HELP="TRUE" ;;
* ) FLAG_HELP="TRUE" ;;
esac
done
shift `expr $OPTIND - 1`
TARGET_VERSION="$1"
LOCATION="$2"
ARCH="$3"
if [ "x"$FLAG_HELP != "x" -o "x$LOCATION" = "x" ]; then
echo "[usage] node-install [-f] VERSION LOCATION [arch]"
echo " ex: node-install v0.10.26 ~/local/node-v0.10"
echo " ex: node-install v0.10.26 ~/local/node-v0.10 darwin-x86"
echo " default arch is 'linux-x64' or 'linux-arm64' based on \$(arch)"
echo ""
echo " for io.js:"
echo " ex: node-install iojs-v1.2.0 ~/local/iojs-v.1.2.0"
echo " ex: node-install iojs-v1.2.0 ~/local/iojs-v.1.2.0 darwin-x64"
exit 0
fi
if [ "x$ARCH" = "x" ]; then
if [ "x$(arch)" = "xaarch64" ]; then
ARCH="linux-arm64"
else
ARCH="linux-x64"
fi
fi
cd $(dirname $0)
if [ "x"$FLAG_FORCE = "x" -a -d "$LOCATION" -a -x "$LOCATION/bin/node" ]; then
current_ver=$("$LOCATION"/bin/node -v)
if [ "x$current_ver" = "x$TARGET_VERSION" ]; then
echo "node $TARGET_VERSION already installed on $LOCATION"
echo "To do force re-install, use '-f' option"
exit 0
fi
fi
if [ "${TARGET_VERSION:0:5}" == "iojs-" ]; then
IOJS_TARGET_VERSION="${TARGET_VERSION#iojs-}"
ARCHIVE_FILENAME="iojs-$IOJS_TARGET_VERSION-$ARCH.tar.gz"
ARCHIVE_DIRNAME="iojs-$IOJS_TARGET_VERSION-$ARCH"
ARCHIVE_URL="https://iojs.org/dist/$IOJS_TARGET_VERSION/$ARCHIVE_FILENAME"
else
ARCHIVE_FILENAME="node-$TARGET_VERSION-$ARCH.tar.gz"
ARCHIVE_DIRNAME="node-$TARGET_VERSION-$ARCH"
ARCHIVE_URL="https://nodejs.org/dist/$TARGET_VERSION/$ARCHIVE_FILENAME"
fi
set -e
mkdir -p var/node-archive
cd var/node-archive
curl -s -O $ARCHIVE_URL
cd ..
tar xzf node-archive/"$ARCHIVE_FILENAME"
if [ -d "$LOCATION" ]; then
[[ -d "$LOCATION.replaced" ]] && rm -rf "$LOCATION.replaced"
mv "$LOCATION" "$LOCATION.replaced"
else
mkdir -p "$LOCATION" && rmdir "$LOCATION"
fi
mv "$ARCHIVE_DIRNAME" "$LOCATION"
PATH="$LOCATION"/bin:$PATH "$LOCATION"/bin/npm install -g node-gyp > /tmp/$USER-node-install-npm.log 2>&1
if [ $? -ne 0 ]; then
echo "npm install failed. see log /tmp/$USER-node-install-npm.log"
exit 2
fi
echo "node $TARGET_VERSION successfully installed on $LOCATION"
echo "To use this node, do 'export PATH=$LOCATION/bin:\$PATH'."