blob: fe0234ae5aaa8405e311f299fcaffe8248ca07ae [file] [log] [blame]
Dmitri Shuralyoveaf31712021-07-30 17:28:51 -04001#!/bin/bash
2
3# Discussion, issues and change requests at:
4# https://github.com/nodesource/distributions
5#
6# Script to install the NodeSource Node.js 14.x repo onto a
7# Debian or Ubuntu system.
8#
9# Run as root or insert `sudo -E` before `bash`:
10#
11# curl -sL https://deb.nodesource.com/setup_14.x | bash -
12# or
13# wget -qO- https://deb.nodesource.com/setup_14.x | bash -
14#
15# CONTRIBUTIONS TO THIS SCRIPT
16#
17# This script is built from a template in
18# https://github.com/nodesource/distributions/tree/master/deb/src
19# please don't submit pull requests against the built scripts.
20#
21
22
23export DEBIAN_FRONTEND=noninteractive
24SCRSUFFIX="_14.x"
25NODENAME="Node.js 14.x"
26NODEREPO="node_14.x"
27NODEPKG="nodejs"
28
29print_status() {
30 echo
31 echo "## $1"
32 echo
33}
34
35if test -t 1; then # if terminal
36 ncolors=$(which tput > /dev/null && tput colors) # supports color
37 if test -n "$ncolors" && test $ncolors -ge 8; then
38 termcols=$(tput cols)
39 bold="$(tput bold)"
40 underline="$(tput smul)"
41 standout="$(tput smso)"
42 normal="$(tput sgr0)"
43 black="$(tput setaf 0)"
44 red="$(tput setaf 1)"
45 green="$(tput setaf 2)"
46 yellow="$(tput setaf 3)"
47 blue="$(tput setaf 4)"
48 magenta="$(tput setaf 5)"
49 cyan="$(tput setaf 6)"
50 white="$(tput setaf 7)"
51 fi
52fi
53
54print_bold() {
55 title="$1"
56 text="$2"
57
58 echo
59 echo "${red}================================================================================${normal}"
60 echo "${red}================================================================================${normal}"
61 echo
62 echo -e " ${bold}${yellow}${title}${normal}"
63 echo
64 echo -en " ${text}"
65 echo
66 echo "${red}================================================================================${normal}"
67 echo "${red}================================================================================${normal}"
68}
69
70bail() {
71 echo 'Error executing command, exiting'
72 exit 1
73}
74
75exec_cmd_nobail() {
76 echo "+ $1"
77 bash -c "$1"
78}
79
80exec_cmd() {
81 exec_cmd_nobail "$1" || bail
82}
83
84node_deprecation_warning() {
85 if [[ "X${NODENAME}" == "Xio.js 1.x" ||
86 "X${NODENAME}" == "Xio.js 2.x" ||
87 "X${NODENAME}" == "Xio.js 3.x" ||
88 "X${NODENAME}" == "XNode.js 0.10" ||
89 "X${NODENAME}" == "XNode.js 0.12" ||
90 "X${NODENAME}" == "XNode.js 4.x LTS Argon" ||
91 "X${NODENAME}" == "XNode.js 5.x" ||
92 "X${NODENAME}" == "XNode.js 6.x LTS Boron" ||
93 "X${NODENAME}" == "XNode.js 7.x" ||
94 "X${NODENAME}" == "XNode.js 8.x LTS Carbon" ||
95 "X${NODENAME}" == "XNode.js 9.x" ||
96 "X${NODENAME}" == "XNode.js 10.x" ||
97 "X${NODENAME}" == "XNode.js 11.x" ||
98 "X${NODENAME}" == "XNode.js 13.x" ||
99 "X${NODENAME}" == "XNode.js 15.x" ]]; then
100
101 print_bold \
102" DEPRECATION WARNING " "\
103${bold}${NODENAME} is no longer actively supported!${normal}
104
105 ${bold}You will not receive security or critical stability updates${normal} for this version.
106
107 You should migrate to a supported version of Node.js as soon as possible.
108 Use the installation script that corresponds to the version of Node.js you
109 wish to install. e.g.
110
111 * ${green}https://deb.nodesource.com/setup_12.x — Node.js 12 LTS \"Erbium\"${normal}
112 * ${green}https://deb.nodesource.com/setup_14.x — Node.js 14 LTS \"Fermium\"${normal} (recommended)
113 * ${green}https://deb.nodesource.com/setup_16.x — Node.js 16 \"Gallium\"${normal}
114
115 Please see ${bold}https://github.com/nodejs/Release${normal} for details about which
116 version may be appropriate for you.
117
118 The ${bold}NodeSource${normal} Node.js distributions repository contains
119 information both about supported versions of Node.js and supported Linux
120 distributions. To learn more about usage, see the repository:
121 ${bold}https://github.com/nodesource/distributions${normal}
122"
123 echo
124 echo "Continuing in 20 seconds ..."
125 echo
126 sleep 20
127 fi
128}
129
130script_deprecation_warning() {
131 if [ "X${SCRSUFFIX}" == "X" ]; then
132 print_bold \
133" SCRIPT DEPRECATION WARNING " "\
134This script, located at ${bold}https://deb.nodesource.com/setup${normal}, used to
135 install Node.js 0.10, is deprecated and will eventually be made inactive.
136
137 You should use the script that corresponds to the version of Node.js you
138 wish to install. e.g.
139
140 * ${green}https://deb.nodesource.com/setup_12.x — Node.js 12 LTS \"Erbium\"${normal}
141 * ${green}https://deb.nodesource.com/setup_14.x — Node.js 14 LTS \"Fermium\"${normal} (recommended)
142 * ${green}https://deb.nodesource.com/setup_16.x — Node.js 16 \"Gallium\"${normal}
143
144 Please see ${bold}https://github.com/nodejs/Release${normal} for details about which
145 version may be appropriate for you.
146
147 The ${bold}NodeSource${normal} Node.js Linux distributions GitHub repository contains
148 information about which versions of Node.js and which Linux distributions
149 are supported and how to use the install scripts.
150 ${bold}https://github.com/nodesource/distributions${normal}
151"
152
153 echo
154 echo "Continuing in 20 seconds (press Ctrl-C to abort) ..."
155 echo
156 sleep 20
157 fi
158}
159
160setup() {
161
162script_deprecation_warning
163node_deprecation_warning
164
165print_status "Installing the NodeSource ${NODENAME} repo..."
166
167if $(uname -m | grep -Eq ^armv6); then
168 print_status "You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the 'linux-armv6l' binary tarballs available directly from nodejs.org for Node.js 4 and later."
169 exit 1
170fi
171
172PRE_INSTALL_PKGS=""
173
174# Check that HTTPS transport is available to APT
175# (Check snaked from: https://get.docker.io/ubuntu/)
176
177if [ ! -e /usr/lib/apt/methods/https ]; then
178 PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} apt-transport-https"
179fi
180
181if [ ! -x /usr/bin/lsb_release ]; then
182 PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} lsb-release"
183fi
184
185if [ ! -x /usr/bin/curl ] && [ ! -x /usr/bin/wget ]; then
186 PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} curl"
187fi
188
189# Used by apt-key to add new keys
190
191if [ ! -x /usr/bin/gpg ]; then
192 PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} gnupg"
193fi
194
195# Populating Cache
196print_status "Populating apt-get cache..."
197exec_cmd 'apt-get update'
198
199if [ "X${PRE_INSTALL_PKGS}" != "X" ]; then
200 print_status "Installing packages required for setup:${PRE_INSTALL_PKGS}..."
201 # This next command needs to be redirected to /dev/null or the script will bork
202 # in some environments
203 exec_cmd "apt-get install -y${PRE_INSTALL_PKGS} > /dev/null 2>&1"
204fi
205
206IS_PRERELEASE=$(lsb_release -d | grep 'Ubuntu .*development' >& /dev/null; echo $?)
207if [[ $IS_PRERELEASE -eq 0 ]]; then
208 print_status "Your distribution, identified as \"$(lsb_release -d -s)\", is a pre-release version of Ubuntu. NodeSource does not maintain official support for Ubuntu versions until they are formally released. You can try using the manual installation instructions available at https://github.com/nodesource/distributions and use the latest supported Ubuntu version name as the distribution identifier, although this is not guaranteed to work."
209 exit 1
210fi
211
212DISTRO=$(lsb_release -c -s)
213
214check_alt() {
215 if [ "X${DISTRO}" == "X${2}" ]; then
216 echo
217 echo "## You seem to be using ${1} version ${DISTRO}."
218 echo "## This maps to ${3} \"${4}\"... Adjusting for you..."
219 DISTRO="${4}"
220 fi
221}
222
223check_alt "SolydXK" "solydxk-9" "Debian" "stretch"
224check_alt "Kali" "sana" "Debian" "jessie"
225check_alt "Kali" "kali-rolling" "Debian" "bullseye"
226check_alt "Sparky Linux" "Tyche" "Debian" "stretch"
227check_alt "Sparky Linux" "Nibiru" "Debian" "buster"
228check_alt "MX Linux 17" "Horizon" "Debian" "stretch"
229check_alt "MX Linux 18" "Continuum" "Debian" "stretch"
230check_alt "MX Linux 19" "patito feo" "Debian" "buster"
231check_alt "Linux Mint" "maya" "Ubuntu" "precise"
232check_alt "Linux Mint" "qiana" "Ubuntu" "trusty"
233check_alt "Linux Mint" "rafaela" "Ubuntu" "trusty"
234check_alt "Linux Mint" "rebecca" "Ubuntu" "trusty"
235check_alt "Linux Mint" "rosa" "Ubuntu" "trusty"
236check_alt "Linux Mint" "sarah" "Ubuntu" "xenial"
237check_alt "Linux Mint" "serena" "Ubuntu" "xenial"
238check_alt "Linux Mint" "sonya" "Ubuntu" "xenial"
239check_alt "Linux Mint" "sylvia" "Ubuntu" "xenial"
240check_alt "Linux Mint" "tara" "Ubuntu" "bionic"
241check_alt "Linux Mint" "tessa" "Ubuntu" "bionic"
242check_alt "Linux Mint" "tina" "Ubuntu" "bionic"
243check_alt "Linux Mint" "tricia" "Ubuntu" "bionic"
244check_alt "Linux Mint" "ulyana" "Ubuntu" "focal"
245check_alt "Linux Mint" "ulyssa" "Ubuntu" "focal"
246check_alt "Linux Mint" "uma" "Ubuntu" "focal"
247check_alt "LMDE" "betsy" "Debian" "jessie"
248check_alt "LMDE" "cindy" "Debian" "stretch"
249check_alt "LMDE" "debbie" "Debian" "buster"
250check_alt "elementaryOS" "luna" "Ubuntu" "precise"
251check_alt "elementaryOS" "freya" "Ubuntu" "trusty"
252check_alt "elementaryOS" "loki" "Ubuntu" "xenial"
253check_alt "elementaryOS" "juno" "Ubuntu" "bionic"
254check_alt "elementaryOS" "hera" "Ubuntu" "bionic"
255check_alt "elementaryOS" "odin" "Ubuntu" "focal"
256check_alt "Trisquel" "toutatis" "Ubuntu" "precise"
257check_alt "Trisquel" "belenos" "Ubuntu" "trusty"
258check_alt "Trisquel" "flidas" "Ubuntu" "xenial"
259check_alt "Trisquel" "etiona" "Ubuntu" "bionic"
260check_alt "Uruk GNU/Linux" "lugalbanda" "Ubuntu" "xenial"
261check_alt "BOSS" "anokha" "Debian" "wheezy"
262check_alt "BOSS" "anoop" "Debian" "jessie"
263check_alt "BOSS" "drishti" "Debian" "stretch"
264check_alt "BOSS" "unnati" "Debian" "buster"
265check_alt "bunsenlabs" "bunsen-hydrogen" "Debian" "jessie"
266check_alt "bunsenlabs" "helium" "Debian" "stretch"
267check_alt "bunsenlabs" "lithium" "Debian" "buster"
268check_alt "Tanglu" "chromodoris" "Debian" "jessie"
269check_alt "PureOS" "green" "Debian" "sid"
270check_alt "PureOS" "amber" "Debian" "buster"
271check_alt "Devuan" "jessie" "Debian" "jessie"
272check_alt "Devuan" "ascii" "Debian" "stretch"
273check_alt "Devuan" "beowulf" "Debian" "buster"
274check_alt "Devuan" "ceres" "Debian" "sid"
275check_alt "Deepin" "panda" "Debian" "sid"
276check_alt "Deepin" "unstable" "Debian" "sid"
277check_alt "Deepin" "stable" "Debian" "buster"
278check_alt "Pardus" "onyedi" "Debian" "stretch"
279check_alt "Liquid Lemur" "lemur-3" "Debian" "stretch"
280check_alt "Astra Linux" "orel" "Debian" "stretch"
281check_alt "Ubilinux" "dolcetto" "Debian" "stretch"
282
283if [ "X${DISTRO}" == "Xdebian" ]; then
284 print_status "Unknown Debian-based distribution, checking /etc/debian_version..."
285 NEWDISTRO=$([ -e /etc/debian_version ] && cut -d/ -f1 < /etc/debian_version)
286 if [ "X${NEWDISTRO}" == "X" ]; then
287 print_status "Could not determine distribution from /etc/debian_version..."
288 else
289 DISTRO=$NEWDISTRO
290 print_status "Found \"${DISTRO}\" in /etc/debian_version..."
291 fi
292fi
293
294print_status "Confirming \"${DISTRO}\" is supported..."
295
296if [ -x /usr/bin/curl ]; then
297 exec_cmd_nobail "curl -sLf -o /dev/null 'https://deb.nodesource.com/${NODEREPO}/dists/${DISTRO}/Release'"
298 RC=$?
299else
300 exec_cmd_nobail "wget -qO /dev/null -o /dev/null 'https://deb.nodesource.com/${NODEREPO}/dists/${DISTRO}/Release'"
301 RC=$?
302fi
303
304if [[ $RC != 0 ]]; then
305 print_status "Your distribution, identified as \"${DISTRO}\", is not currently supported, please contact NodeSource at https://github.com/nodesource/distributions/issues if you think this is incorrect or would like your distribution to be considered for support"
306 exit 1
307fi
308
309if [ -f "/etc/apt/sources.list.d/chris-lea-node_js-$DISTRO.list" ]; then
310 print_status 'Removing Launchpad PPA Repository for NodeJS...'
311
312 exec_cmd_nobail 'add-apt-repository -y -r ppa:chris-lea/node.js'
313 exec_cmd "rm -f /etc/apt/sources.list.d/chris-lea-node_js-${DISTRO}.list"
314fi
315
316print_status 'Adding the NodeSource signing key to your keyring...'
317keyring='/usr/share/keyrings'
318node_key_url="https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
319local_node_key="$keyring/nodesource.gpg"
320
321if [ -x /usr/bin/curl ]; then
322 exec_cmd "curl -s $node_key_url | gpg --dearmor | tee $local_node_key >/dev/null"
323else
324 exec_cmd "wget -q -O - $node_key_url | gpg --dearmor | tee $local_node_key >/dev/null"
325fi
326
327print_status "Creating apt sources list file for the NodeSource ${NODENAME} repo..."
328
329exec_cmd "echo 'deb [signed-by=$local_node_key] https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' > /etc/apt/sources.list.d/nodesource.list"
330exec_cmd "echo 'deb-src [signed-by=$local_node_key] https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' >> /etc/apt/sources.list.d/nodesource.list"
331
332print_status 'Running `apt-get update` for you...'
333
334exec_cmd 'apt-get update'
335
336yarn_site='https://dl.yarnpkg.com/debian'
337yarn_key_url="$yarn_site/pubkey.gpg"
338local_yarn_key="$keyring/yarnkey.gpg"
339
340print_status """Run \`${bold}sudo apt-get install -y ${NODEPKG}${normal}\` to install ${NODENAME} and npm
341## You may also need development tools to build native addons:
342 sudo apt-get install gcc g++ make
343## To install the Yarn package manager, run:
344 curl -sL $yarn_key_url | gpg --dearmor | sudo tee $local_yarn_key >/dev/null
345 echo \"deb [signed-by=$local_yarn_key] $yarn_site stable main\" | sudo tee /etc/apt/sources.list.d/yarn.list
346 sudo apt-get update && sudo apt-get install yarn
347"""
348
349}
350
351## Defer setup until we have the complete script
352setup