|
1 | | -#!/usr/bin/env sh |
| 1 | +#!/usr/bin/env bash |
2 | 2 |
|
3 | 3 | set -e |
4 | 4 |
|
5 | | -NODE_VERSION="${VERSION:-"24"}" |
| 5 | +NODE_VERSION="${VERSION:-"automatic"}" |
| 6 | +NODE_MAJOR_VERSION="24" |
| 7 | + |
| 8 | +pkg="nodejs" |
| 9 | + |
| 10 | +if [ "${NODE_VERSION}" != "automatic" ]; then |
| 11 | + NODE_MAJOR_VERSION="$(echo "${NODE_VERSION}" | cut -d. -f1)" |
| 12 | + pkg="${pkg}=${NODE_VERSION}-1nodesource1" |
| 13 | +fi |
6 | 14 |
|
7 | 15 | curl_installed="" |
| 16 | +gpg_installed="" |
8 | 17 |
|
9 | 18 | if ! type curl >/dev/null 2>&1; then |
10 | 19 | apt update --yes |
11 | | - apt install --no-install-recommends --yes curl ca-certificates |
| 20 | + apt install --yes curl |
12 | 21 |
|
13 | 22 | curl_installed="true" |
14 | 23 | fi |
15 | 24 |
|
16 | | -curl -fsSL https://deb.nodesource.com/setup_"${NODE_VERSION}".x | bash - |
| 25 | +if ! type gpg >/dev/null 2>&1; then |
| 26 | + apt update --yes |
| 27 | + apt install --yes gnupg |
17 | 28 |
|
18 | | -apt update --yes |
19 | | -apt install --no-install-recommends --yes nodejs |
| 29 | + gpg_installed="true" |
| 30 | +fi |
| 31 | + |
| 32 | +apt_sources_snippet="$(cat << EOF |
| 33 | +Types: deb |
| 34 | +URIs: https://deb.nodesource.com/node_${NODE_MAJOR_VERSION}.x |
| 35 | +Suites: nodistro |
| 36 | +Components: main |
| 37 | +Signed-By: /etc/apt/keyrings/nodesource.gpg |
| 38 | +EOF |
| 39 | +)" |
| 40 | + |
| 41 | +install -dm 755 /etc/apt/keyrings |
| 42 | +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 43 | +echo "${apt_sources_snippet}" | tee /etc/apt/sources.list.d/nodesource.sources |
20 | 44 |
|
21 | 45 | if [ -n "${curl_installed}" ]; then |
22 | 46 | apt purge curl --autoremove --yes |
| 47 | + rm -rf /var/lib/apt/lists/* |
| 48 | +fi |
| 49 | + |
| 50 | +if [ -n "${gpg_installed}" ]; then |
| 51 | + apt purge gnupg --autoremove --yes |
| 52 | + rm -rf /var/lib/apt/lists/* |
| 53 | +fi |
| 54 | + |
| 55 | +apt update --yes |
| 56 | +apt install --yes "${pkg}" |
| 57 | +rm -rf /var/lib/apt/lists/* |
| 58 | + |
| 59 | +node_rc_snippet="$(cat << EOF |
| 60 | +export NODE_VERSION="$(node -v | cut -c2-)" |
| 61 | +EOF |
| 62 | +)" |
| 63 | + |
| 64 | +if [[ "$(cat /etc/bash.bashrc)" != *"${node_rc_snippet}"* ]]; then |
| 65 | + echo "${node_rc_snippet}" >> /etc/bash.bashrc |
| 66 | +fi |
| 67 | + |
| 68 | +if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"${node_rc_snippet}"* ]]; then |
| 69 | + echo "${node_rc_snippet}" >> /etc/zsh/zshrc |
23 | 70 | fi |
0 commit comments