-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall_node
executable file
·123 lines (105 loc) · 3.56 KB
/
install_node
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
set -eu
bin_only="false"
if [ -n "${INSTALL_NODE_URL+1}" ]; then
INSTALL_NODE_URL=$INSTALL_NODE_URL
else
INSTALL_NODE_URL="https://s3.amazonaws.com/mapbox/vendor/nodejs"
fi
if [ -z "${NV+1}" -o -z "${NP+1}" -o -z "${OD+1}" ]; then
node_version=$1
platformarch=$2
output_dir=$3
if [ -n "${4+1}" ]; then
bin_only=$4
fi
else
node_version=$NV
platformarch=$NP
output_dir=$OD
if [ -n "${BO+1}" ]; then
bin_only=$BO
fi
fi
# Enforce default arch for legacy arch-free args.
case $platformarch in
"linux")
platformarch="linux-x64"
;;
"darwin")
platformarch="darwin-x64"
;;
"win32")
platformarch="win32-ia32"
;;
esac
# Output info about requested range and resolved node version
echo "Requested node version: $node_version"
echo "Requested node platform+arch: $platformarch"
if [ "$bin_only" = "true" ]; then
echo "Requested bin only: $bin_only"
fi
case $platformarch in
"linux-x64")
url="$INSTALL_NODE_URL/v$node_version/node-v$node_version-linux-x64.tar.gz"
;;
"darwin-x64")
url="$INSTALL_NODE_URL/v$node_version/node-v$node_version-darwin-x64.tar.gz"
;;
"win32-ia32")
url="$INSTALL_NODE_URL/v$node_version/node.exe"
;;
"win32-x64")
url="$INSTALL_NODE_URL/v$node_version/x64/node.exe"
;;
*)
echo "Not a valid platform+arch. Specify one of linux-x64|darwin-x64|win32-ia32|win32-x64"
exit 1
;;
esac
tmp="$(mktemp -d -t install-node.XXXXXX)"
trap "rm -rf $tmp" EXIT
cd "$tmp"
# Download node
curl -Lsfo $(basename $url) "$url"
# Only verify SHASUMS.txt.asc if found.
if curl -sf "$INSTALL_NODE_URL/v$node_version/SHASUMS.txt.asc" > /dev/null; then
curl -Lsfo izs.asc "https://s3.amazonaws.com/mapbox/apps/install-node/cache/izs.asc"
curl -Lsfo tjfontaine.asc "https://s3.amazonaws.com/mapbox/apps/install-node/cache/tjfontaine.asc"
curl -Lsfo SHASUMS.txt.asc "$INSTALL_NODE_URL/v$node_version/SHASUMS.txt.asc"
if which gpg > /dev/null; then
# Add trusted gpg keys for verifying nodejs downloads
gpg --import izs.asc
gpg --import tjfontaine.asc
# Verify signed SHASUMS file to ensure it can be trusted
echo "Verifying signature of nodejs SHASUMS.txt.asc"
gpg --verify < "SHASUMS.txt.asc"
else
echo "WARNING: gpg not found. Installing node without verifying SHASUMS.txt.asc" >&2
fi
# RHEL/centos7 does not ship with a parent shasum function.
# Fallback to sha1sum if not found.
shasum=""
if which shasum > /dev/null; then
shasum=$(which shasum)
elif which sha1sum > /dev/null; then
shasum=$(which sha1sum)
fi
# Check that shasum of tarball is present
echo "Verifying nodejs shasum"
node_shasum="$($shasum $(basename $url) | grep -oE '^[0-9a-f]+')"
grep "$node_shasum" "SHASUMS.txt.asc"
fi
# Install node
if [ "$platformarch" != "win32-ia32" ] && [ "$platformarch" != "win32-x64" ]; then
if [ "$bin_only" = "true" ]; then
tar --strip 2 -xzf "node-v$node_version-$platformarch.tar.gz" --directory "$output_dir" "node-v$node_version-$platformarch/bin/node"
else
tar --strip-components 1 -xzf "node-v$node_version-$platformarch.tar.gz" --directory "$output_dir"
# Change the location of the npm cache so different versions of node don't interfere with each other
mkdir -p "$output_dir/.npm"
"$output_dir/lib/node_modules/npm/configure" --cache="$output_dir/.npm"
fi
else
cp node.exe "$output_dir/"
fi