Advertisement
Guest User

Untitled

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