-
Notifications
You must be signed in to change notification settings - Fork 474
/
Copy pathinstall.sh
executable file
·71 lines (60 loc) · 2.25 KB
/
install.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
65
66
67
68
69
70
71
#!/usr/bin/env bash
# Define Node.js version and base URL
NODE_VERSION="v18.20.5"
NODE_BASE_URL="https://nodejs.org/download/release/${NODE_VERSION}"
NODE_INSTALL_DIR="./node"
cd "$(dirname "$0")/app"
# Function to determine the appropriate Node.js binary
get_node_binary_url() {
OS_TYPE=$(uname | tr '[:upper:]' '[:lower:]')
MACHINE_TYPE=$(uname -m)
case "${OS_TYPE}" in
linux)
case "${MACHINE_TYPE}" in
x86_64) echo "${NODE_BASE_URL}/node-${NODE_VERSION}-linux-x64.tar.gz" ;;
*64)
# If the machine type ends with '64' and is not x86_64, assume it's ARM64
echo "${NODE_BASE_URL}/node-${NODE_VERSION}-linux-arm64.tar.gz" ;;
armv7l) echo "${NODE_BASE_URL}/node-${NODE_VERSION}-linux-armv7l.tar.gz" ;;
ppc64le) echo "${NODE_BASE_URL}/node-${NODE_VERSION}-linux-ppc64le.tar.gz" ;;
s390x) echo "${NODE_BASE_URL}/node-${NODE_VERSION}-linux-s390x.tar.gz" ;;
*) echo "Unsupported architecture: ${MACHINE_TYPE}" >&2; exit 1 ;;
esac
;;
darwin)
case "${MACHINE_TYPE}" in
x86_64) echo "${NODE_BASE_URL}/node-${NODE_VERSION}-darwin-x64.tar.gz" ;;
arm64) echo "${NODE_BASE_URL}/node-${NODE_VERSION}-darwin-arm64.tar.gz" ;;
*) echo "Unsupported architecture: ${MACHINE_TYPE}" >&2; exit 1 ;;
esac
;;
*)
echo "Unsupported OS: ${OS_TYPE}" >&2
exit 1
;;
esac
}
# Check if Node.js is globally installed
which node >/dev/null 2>&1
IS_NODE_GLOBAL=$?
if [ $IS_NODE_GLOBAL -eq 0 ]; then
node -e "process.exit(Number(process.version.substr(1).split('.')[0]) > 5 ? 0 : 1)"
IS_NODE_GLOBAL=$?
fi
if [ $IS_NODE_GLOBAL -eq 0 ]; then
echo "Installer is using your system NodeJS."
echo
node install.js "$(which node)" "$1"
else
echo "Node.js not found or version is less than 6. Downloading Node.js..."
mkdir -p "${NODE_INSTALL_DIR}"
NODE_URL=$(get_node_binary_url)
NODE_ARCHIVE="${NODE_INSTALL_DIR}/node.tar.gz"
echo "Downloading ${NODE_URL}..."
curl -o "${NODE_ARCHIVE}" "${NODE_URL}"
echo "Extracting Node.js..."
tar -xzf "${NODE_ARCHIVE}" -C "${NODE_INSTALL_DIR}" --strip-components=1
rm "${NODE_ARCHIVE}"
echo "Running installer with embedded Node.js..."
"${NODE_INSTALL_DIR}/bin/node" install.js --add_node "$1"
fi