Advertisement
fhumayun

setup13.sh

Mar 13th, 2020
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.66 KB | None | 0 0
  1. #!/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 13.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_13.x | bash -
  12. #   or
  13. # wget -qO- https://deb.nodesource.com/setup_13.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.  
  23. export DEBIAN_FRONTEND=noninteractive
  24. SCRSUFFIX="_13.x"
  25. NODENAME="Node.js 13.x"
  26. NODEREPO="node_13.x"
  27. NODEPKG="nodejs"
  28.  
  29. print_status() {
  30.     echo
  31.     echo "## $1"
  32.     echo
  33. }
  34.  
  35. if 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
  52. fi
  53.  
  54. print_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.  
  70. bail() {
  71.     echo 'Error executing command, exiting'
  72.     exit 1
  73. }
  74.  
  75. exec_cmd_nobail() {
  76.     echo "+ $1"
  77.     bash -c "$1"
  78. }
  79.  
  80. exec_cmd() {
  81.     exec_cmd_nobail "$1" || bail
  82. }
  83.  
  84. node_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 11.x" ]]; then
  97.  
  98.         print_bold \
  99. "                            DEPRECATION WARNING                            " "\
  100. ${bold}${NODENAME} is no longer actively supported!${normal}
  101.  
  102.  ${bold}You will not receive security or critical stability updates${normal} for this version.
  103.  
  104.  You should migrate to a supported version of Node.js as soon as possible.
  105.  Use the installation script that corresponds to the version of Node.js you
  106.  wish to install. e.g.
  107.  
  108.   * ${green}https://deb.nodesource.com/setup_10.x — Node.js 10 LTS \"Dubnium\"${normal} (recommended)
  109.   * ${green}https://deb.nodesource.com/setup_12.x — Node.js 12 LTS \"Erbium\"${normal}
  110.  
  111.  Please see ${bold}https://github.com/nodejs/Release${normal} for details about which
  112.  version may be appropriate for you.
  113.  
  114.  The ${bold}NodeSource${normal} Node.js distributions repository contains
  115.  information both about supported versions of Node.js and supported Linux
  116.  distributions. To learn more about usage, see the repository:
  117.    ${bold}https://github.com/nodesource/distributions${normal}
  118. "
  119.         echo
  120.         echo "Continuing in 20 seconds ..."
  121.         echo
  122.         sleep 20
  123.     fi
  124. }
  125.  
  126. script_deprecation_warning() {
  127.     if [ "X${SCRSUFFIX}" == "X" ]; then
  128.         print_bold \
  129. "                         SCRIPT DEPRECATION WARNING                         " "\
  130. This script, located at ${bold}https://deb.nodesource.com/setup${normal}, used to
  131.  install Node.js 0.10, is deprecated and will eventually be made inactive.
  132.  
  133.  You should use the script that corresponds to the version of Node.js you
  134.  wish to install. e.g.
  135.  
  136.   * ${green}https://deb.nodesource.com/setup_10.x — Node.js 10 LTS \"Dubnium\"${normal} (recommended)
  137.   * ${green}https://deb.nodesource.com/setup_12.x — Node.js 12 LTS \"Erbium\"${normal}
  138.  Please see ${bold}https://github.com/nodejs/Release${normal} for details about which
  139.  version may be appropriate for you.
  140.  
  141.  The ${bold}NodeSource${normal} Node.js Linux distributions GitHub repository contains
  142.  information about which versions of Node.js and which Linux distributions
  143.  are supported and how to use the install scripts.
  144.    ${bold}https://github.com/nodesource/distributions${normal}
  145. "
  146.  
  147.         echo
  148.         echo "Continuing in 20 seconds (press Ctrl-C to abort) ..."
  149.         echo
  150.         sleep 20
  151.     fi
  152. }
  153.  
  154. setup() {
  155.  
  156. script_deprecation_warning
  157. node_deprecation_warning
  158.  
  159. print_status "Installing the NodeSource ${NODENAME} repo..."
  160.  
  161. if $(uname -m | grep -Eq ^armv6); then
  162.     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."
  163.     exit 1
  164. fi
  165.  
  166. PRE_INSTALL_PKGS=""
  167.  
  168. # Check that HTTPS transport is available to APT
  169. # (Check snaked from: https://get.docker.io/ubuntu/)
  170.  
  171. if [ ! -e /usr/lib/apt/methods/https ]; then
  172.     PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} apt-transport-https"
  173. fi
  174.  
  175. if [ ! -x /usr/bin/lsb_release ]; then
  176.     PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} lsb-release"
  177. fi
  178.  
  179. if [ ! -x /usr/bin/curl ] && [ ! -x /usr/bin/wget ]; then
  180.     PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} curl"
  181. fi
  182.  
  183. # Used by apt-key to add new keys
  184.  
  185. if [ ! -x /usr/bin/gpg ]; then
  186.     PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} gnupg"
  187. fi
  188.  
  189. # Populating Cache
  190. print_status "Populating apt-get cache..."
  191. exec_cmd 'apt-get update'
  192.  
  193. if [ "X${PRE_INSTALL_PKGS}" != "X" ]; then
  194.     print_status "Installing packages required for setup:${PRE_INSTALL_PKGS}..."
  195.     # This next command needs to be redirected to /dev/null or the script will bork
  196.     # in some environments
  197.     exec_cmd "sudo apt-get install -y${PRE_INSTALL_PKGS} > /dev/null 2>&1"
  198. fi
  199.  
  200. IS_PRERELEASE=$(lsb_release -d | grep 'Ubuntu .*development' >& /dev/null; echo $?)
  201. if [[ $IS_PRERELEASE -eq 0 ]]; then
  202.     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."
  203.     exit 1
  204. fi
  205.  
  206. DISTRO=$(lsb_release -c -s)
  207.  
  208. check_alt() {
  209.     if [ "X${DISTRO}" == "X${2}" ]; then
  210.         echo
  211.         echo "## You seem to be using ${1} version ${DISTRO}."
  212.         echo "## This maps to ${3} \"${4}\"... Adjusting for you..."
  213.         DISTRO="${4}"
  214.     fi
  215. }
  216.  
  217. check_alt "SolydXK"       "solydxk-9" "Debian" "stretch"
  218. check_alt "Kali"          "sana"     "Debian" "jessie"
  219. check_alt "Kali"          "kali-rolling" "Debian" "jessie"
  220. check_alt "Sparky Linux"  "Tyche"    "Debian" "stretch"
  221. check_alt "Sparky Linux"  "Nibiru"   "Debian" "buster"
  222. check_alt "MX Linux 17"   "Horizon"  "Debian" "stretch"
  223. check_alt "MX Linux 18"   "Continuum" "Debian" "stretch"
  224. check_alt "MX Linux 19"   "patito feo" "Debian" "buster"
  225. check_alt "Linux Mint"    "maya"     "Ubuntu" "precise"
  226. check_alt "Linux Mint"    "qiana"    "Ubuntu" "trusty"
  227. check_alt "Linux Mint"    "rafaela"  "Ubuntu" "trusty"
  228. check_alt "Linux Mint"    "rebecca"  "Ubuntu" "trusty"
  229. check_alt "Linux Mint"    "rosa"     "Ubuntu" "trusty"
  230. check_alt "Linux Mint"    "sarah"    "Ubuntu" "xenial"
  231. check_alt "Linux Mint"    "serena"   "Ubuntu" "xenial"
  232. check_alt "Linux Mint"    "sonya"    "Ubuntu" "xenial"
  233. check_alt "Linux Mint"    "sylvia"   "Ubuntu" "xenial"
  234. check_alt "Linux Mint"    "tara"     "Ubuntu" "bionic"
  235. check_alt "Linux Mint"    "tessa"    "Ubuntu" "bionic"
  236. check_alt "Linux Mint"    "tina"     "Ubuntu" "bionic"
  237. check_alt "Linux Mint"    "tricia"   "Ubuntu" "bionic"
  238. check_alt "LMDE"          "betsy"    "Debian" "jessie"
  239. check_alt "LMDE"          "cindy"    "Debian" "stretch"
  240. check_alt "elementaryOS"  "luna"     "Ubuntu" "precise"
  241. check_alt "elementaryOS"  "freya"    "Ubuntu" "trusty"
  242. check_alt "elementaryOS"  "loki"     "Ubuntu" "xenial"
  243. check_alt "elementaryOS"  "juno"     "Ubuntu" "bionic"
  244. check_alt "elementaryOS"  "hera"     "Ubuntu" "bionic"
  245. check_alt "Trisquel"      "toutatis" "Ubuntu" "precise"
  246. check_alt "Trisquel"      "belenos"  "Ubuntu" "trusty"
  247. check_alt "Trisquel"      "flidas"   "Ubuntu" "xenial"
  248. check_alt "Uruk GNU/Linux" "lugalbanda" "Ubuntu" "xenial"
  249. check_alt "BOSS"          "anokha"   "Debian" "wheezy"
  250. check_alt "BOSS"          "anoop"    "Debian" "jessie"
  251. check_alt "BOSS"          "drishti"  "Debian" "stretch"
  252. check_alt "bunsenlabs"    "bunsen-hydrogen" "Debian" "jessie"
  253. check_alt "bunsenlabs"    "helium"   "Debian" "stretch"
  254. check_alt "Tanglu"        "chromodoris" "Debian" "jessie"
  255. check_alt "PureOS"        "green"    "Debian" "sid"
  256. check_alt "PureOS"        "amber"    "Debian" "buster"
  257. check_alt "Devuan"        "jessie"   "Debian" "jessie"
  258. check_alt "Devuan"        "ascii"    "Debian" "stretch"
  259. check_alt "Devuan"        "beowulf"  "Debian" "buster"
  260. check_alt "Devuan"        "ceres"    "Debian" "sid"
  261. check_alt "Deepin"        "panda"    "Debian" "sid"
  262. check_alt "Deepin"        "unstable" "Debian" "sid"
  263. check_alt "Deepin"        "stable"   "Debian" "buster"
  264. check_alt "Pardus"        "onyedi"   "Debian" "stretch"
  265. check_alt "Liquid Lemur"  "lemur-3"  "Debian" "stretch"
  266.  
  267. if [ "X${DISTRO}" == "Xdebian" ]; then
  268.   print_status "Unknown Debian-based distribution, checking /etc/debian_version..."
  269.   NEWDISTRO=$([ -e /etc/debian_version ] && cut -d/ -f1 < /etc/debian_version)
  270.   if [ "X${NEWDISTRO}" == "X" ]; then
  271.     print_status "Could not determine distribution from /etc/debian_version..."
  272.   else
  273.     DISTRO=$NEWDISTRO
  274.     print_status "Found \"${DISTRO}\" in /etc/debian_version..."
  275.   fi
  276. fi
  277.  
  278. print_status "Confirming \"${DISTRO}\" is supported..."
  279.  
  280. if [ -x /usr/bin/curl ]; then
  281.     exec_cmd_nobail "curl -sLf -o /dev/null 'https://deb.nodesource.com/${NODEREPO}/dists/${DISTRO}/Release'"
  282.     RC=$?
  283. else
  284.     exec_cmd_nobail "wget -qO /dev/null -o /dev/null 'https://deb.nodesource.com/${NODEREPO}/dists/${DISTRO}/Release'"
  285.     RC=$?
  286. fi
  287.  
  288. if [[ $RC != 0 ]]; then
  289.     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"
  290.     exit 1
  291. fi
  292.  
  293. if [ -f "/etc/apt/sources.list.d/chris-lea-node_js-$DISTRO.list" ]; then
  294.     print_status 'Removing Launchpad PPA Repository for NodeJS...'
  295.  
  296.     exec_cmd_nobail 'sudo add-apt-repository -y -r ppa:chris-lea/node.js'
  297.     exec_cmd "sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-${DISTRO}.list"
  298. fi
  299.  
  300. print_status 'Adding the NodeSource signing key to your keyring...'
  301.  
  302. if [ -x /usr/bin/curl ]; then
  303.     exec_cmd 'curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -'
  304. else
  305.     exec_cmd 'wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -'
  306. fi
  307.  
  308. print_status "Creating apt sources list file for the NodeSource ${NODENAME} repo..."
  309.  
  310. exec_cmd "echo 'deb https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' > /etc/apt/sources.list.d/nodesource.list"
  311. exec_cmd "echo 'deb-src https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' >> /etc/apt/sources.list.d/nodesource.list"
  312.  
  313. print_status 'Running `apt-get update` for you...'
  314.  
  315. exec_cmd 'sudo apt-get update'
  316.  
  317. print_status """Run \`${bold}sudo apt-get install -y ${NODEPKG}${normal}\` to install ${NODENAME} and npm
  318. ## You may also need development tools to build native addons:
  319.     sudo apt-get install gcc g++ make
  320. ## To install the Yarn package manager, run:
  321.     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  322.     echo \"deb https://dl.yarnpkg.com/debian/ stable main\" | sudo tee /etc/apt/sources.list.d/yarn.list
  323.     sudo apt-get update && sudo apt-get install yarn
  324. """
  325.  
  326. }
  327.  
  328. ## Defer setup until we have the complete script
  329. setup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement