-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·90 lines (69 loc) · 2.1 KB
/
install.sh
File metadata and controls
executable file
·90 lines (69 loc) · 2.1 KB
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
#!/usr/bin/env bash
set -e
NODE_VERSION="${VERSION:-"latest"}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
# Determine the appropriate non-root user.
if [[ "${USERNAME}" = "automatic" ]]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "$(getent passwd 1000 | cut -d: -f1)")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if id -u "${CURRENT_USER}" >/dev/null 2>&1; then
USERNAME="${CURRENT_USER}"
break
fi
done
if [[ "${USERNAME}" = "" ]]; then
USERNAME="root"
fi
elif ! id -u "${USERNAME}" >/dev/null 2>&1; then
USERNAME="root"
fi
curl_installed=""
xz_installed=""
if ! type curl >/dev/null 2>&1; then
apt update --yes
apt install --yes curl
curl_installed="true"
fi
if ! type xz >/dev/null 2>&1; then
apt update --yes
apt install --yes xz-utils
xz_installed="true"
fi
# Normalize architecture
arch="$(dpkg --print-architecture)"
if [[ "${arch}" = "amd64" ]] || [[ "${arch}" = "x86_64" ]] || [[ "${arch}" = "i386" ]]; then
arch="x64"
fi
# Normalize Node.js version string
if [[ "${NODE_VERSION}" != "latest" ]] && [[ "${NODE_VERSION}" != "v"* ]]; then
NODE_VERSION="v${NODE_VERSION}"
fi
# Configure "node" group
if ! grep -e "^node:" /etc/group >/dev/null 2>&1; then
groupadd --system node
fi
usermod --append --groups node "${USERNAME}"
# Install Node.js
umask 0002
mkdir -p "${NODE_HOME:?}"
curl -fsSL "https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-${arch}.tar.xz" | tar xf - -C "${NODE_HOME}" -J --strip-components 1
chown -R "${USERNAME}:node" "${NODE_HOME}"
chmod g+rws "${NODE_HOME}"
# Configure shell
rc_snippet="export NODE_VERSION=\"$(node -v | cut -c2-)\""
if [[ -f /etc/bash.bashrc ]] && ! grep -q "${rc_snippet}" /etc/bash.bashrc; then
echo "${rc_snippet}" >>/etc/bash.bashrc
fi
if [[ -f /etc/zsh/zshrc ]] && ! grep -q "${rc_snippet}" /etc/zsh/zshrc; then
echo "${rc_snippet}" >>/etc/zsh/zshrc
fi
# Cleanup
if [[ -n "${curl_installed}" ]]; then
apt purge curl --autoremove --yes
rm -rf /var/lib/apt/lists/*
fi
if [[ -n "${xz_installed}" ]]; then
apt purge xz-utils --autoremove --yes
rm -rf /var/lib/apt/lists/*
fi