blob: 6832c1444ddba18ec3974417e5b96e0f185c79f2 [file] [log] [blame]
Monty Taylor4a781a72017-07-25 07:28:04 -04001#!/bin/bash
2
3# Copyright (c) 2016 NodeSource LLC
4#
5# Permission is hereby granted, free of charge, to any person obtaining a
6# copy of this software and associated documentation files (the "Software"),
7# to deal in the Software without restriction, including without limitation
8# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9# and/or sell copies of the Software, and to permit persons to whom the
10# Software is furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22
23# The above license is inferred from the
24# https://github.com/nodesource/distributions source repository.
25
26# Discussion, issues and change requests at:
27# https://github.com/nodesource/distributions
28#
29# Script to install the NodeSource Node.js 8.x repo onto an
30# Enterprise Linux or Fedora Core based system.
31#
32# Run as root or insert `sudo -E` before `bash`:
33#
34# This was downloaded from https://rpm.nodesource.com/setup_8.x
35# A few modifications have been made.
36
37print_status() {
38 local outp=$(echo "$1" | sed -r 's/\\n/\\n## /mg')
39 echo
40 echo -e "## ${outp}"
41 echo
42}
43
44bail() {
45 echo 'Error executing command, exiting'
46 exit 1
47}
48
49exec_cmd_nobail() {
50 echo "+ $1"
51 bash -c "$1"
52}
53
54exec_cmd() {
55 exec_cmd_nobail "$1" || bail
56}
57
58print_status "Installing the NodeSource Node.js 8.x repo..."
59
60print_status "Inspecting system..."
61
62if [ ! -x /bin/rpm ]; then
63 print_status "\
64You don't appear to be running an Enterprise Linux based \
65system, please contact NodeSource at \
66https://github.com/nodesource/distributions/issues if you think this \
67is incorrect or would like your distribution to be considered for \
68support.\
69"
70 exit 1
71fi
72
73## Annotated section for auto extraction in test.sh
74#-check-distro-#
75
76## Check distro and arch
77echo "+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release"
78DISTRO_PKG=$(rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release)
79echo "+ uname -m"
80UNAME_ARCH=$(uname -m)
81
82
83if [ "X${UNAME_ARCH}" == "Xi686" ]; then
84 DIST_ARCH=i386
85elif [ "X${UNAME_ARCH}" == "Xx86_64" ]; then
86 DIST_ARCH=x86_64
87else
88
89 print_status "\
90You don't appear to be running a supported machine architecture: ${UNAME_ARCH}. \
91Please contact NodeSource at \
92https://github.com/nodesource/distributions/issues if you think this is \
93incorrect or would like your architecture to be considered for support. \
94"
95 exit 1
96
97fi
98
99if [[ $DISTRO_PKG =~ ^(redhat|centos|cloudlinux|sl)- ]]; then
100 DIST_TYPE=el
101elif [[ $DISTRO_PKG =~ ^system-release- ]]; then # Amazon Linux
102 DIST_TYPE=el
103elif [[ $DISTRO_PKG =~ ^(fedora|korora)- ]]; then
104 DIST_TYPE=fc
105else
106
107 print_status "\
108You don't appear to be running a supported version of Enterprise Linux. \
109Please contact NodeSource at \
110https://github.com/nodesource/distributions/issues if you think this is \
111incorrect or would like your architecture to be considered for support. \
112Include your 'distribution package' name: ${DISTRO_PKG}. \
113"
114 exit 1
115
116fi
117
118if [[ $DISTRO_PKG =~ ^system-release-201[4-9]\. ]]; then #NOTE: not really future-proof
119
120 # Amazon Linux, for 2014.* use el7, older versions are unknown, perhaps el6
121 DIST_VERSION=7
122
123else
124
125 ## Using the redhat-release-server-X, centos-release-X, etc. pattern
126 ## extract the major version number of the distro
127 DIST_VERSION=$(echo $DISTRO_PKG | sed -r 's/^[[:alpha:]]+-release(-server|-workstation)?-([0-9]+).*$/\2/')
128
129 if ! [[ $DIST_VERSION =~ ^[0-9][0-9]?$ ]]; then
130
131 print_status "\
132Could not determine your distribution version, you may not be running a \
133supported version of Enterprise Linux. \
134Please contact NodeSource at \
135https://github.com/nodesource/distributions/issues if you think this is \
136incorrect. Include your 'distribution package' name: ${DISTRO_PKG}. \
137"
138 exit 1
139
140 fi
141
142fi
143
144
145## Given the distro, version and arch, construct the url for
146## the appropriate nodesource-release package (it's noarch but
147## we include the arch in the directory tree anyway)
148RELEASE_URL_VERSION_STRING="${DIST_TYPE}${DIST_VERSION}"
149RELEASE_URL="\
150https://rpm.nodesource.com/pub_8.x/\
151${DIST_TYPE}/\
152${DIST_VERSION}/\
153${DIST_ARCH}/\
154nodesource-release-${RELEASE_URL_VERSION_STRING}-1.noarch.rpm"
155
156#-check-distro-#
157
158print_status "Confirming \"${DIST_TYPE}${DIST_VERSION}-${DIST_ARCH}\" is supported..."
159
160## Simple fetch & fast-fail to see if the nodesource-release
161## file exists for this distro/version/arch
162exec_cmd_nobail "curl -sLf -o /dev/null '${RELEASE_URL}'"
163RC=$?
164
165if [[ $RC != 0 ]]; then
166 print_status "\
167Your distribution, identified as \"${DISTRO_PKG}\", \
168is not currently supported, please contact NodeSource at \
169https://github.com/nodesource/distributions/issues \
170if you think this is incorrect or would like your distribution to be considered for support"
171 exit 1
172fi
173
174## EPEL is needed for EL5, we don't install it if it's missing but
175## we can give guidance
176if [ "$DIST_TYPE" == "el" ] && [ "$DIST_VERSION" == "5" ]; then
177
178 print_status "Checking if EPEL is enabled..."
179
180 echo "+ yum repolist enabled 2> /dev/null | grep epel"
181 repolist=$(yum repolist enabled 2> /dev/null | grep epel)
182
183 if [ "X${repolist}" == "X" ]; then
184 print_status "Finding current EPEL release RPM..."
185
186 ## We can scrape the html to find the latest epel-release (likely 5.4)
187 epel_url="http://dl.fedoraproject.org/pub/epel/5/${DIST_ARCH}/"
188 epel_release_view="${epel_url}repoview/epel-release.html"
189 echo "+ curl -s $epel_release_view | grep -oE 'epel-release-[0-9\-]+\.noarch\.rpm'"
190 epel=$(curl -s $epel_release_view | grep -oE 'epel-release-[0-9\-]+\.noarch\.rpm')
191 if [ "X${epel}" = "X" ]; then
192 print_status "Error: Could not find current EPEL release RPM!"
193 exit 1
194 fi
195
196 print_status "\
197The EPEL (Extra Packages for Enterprise Linux) repository is a\n\
198prerequisite for installing Node.js on your operating system. Please\n\
199add it and re-run this setup script.\n\
200\n\
201The EPEL repository RPM is available at:\n\
202 ${epel_url}${epel}\n\
203You can try installing with: \`rpm -ivh <url>\`\
204"
205
206 exit 1
207 fi
208
209fi
210
211print_status "Downloading release setup RPM..."
212
213## Two-step process to install the nodesource-release RPM,
214## Download to a tmp file then install it directly with `rpm`.
215## We don't rely on RPM's ability to fetch from HTTPS directly
216echo "+ mktemp"
217RPM_TMP=$(mktemp || bail)
218
219exec_cmd "curl -sL -o '${RPM_TMP}' '${RELEASE_URL}'"
220
221print_status "Installing release setup RPM..."
222
223## --nosignature because nodesource-release contains the signature!
224exec_cmd "rpm -i --nosignature --force '${RPM_TMP}'"
225
226print_status "Cleaning up..."
227
228exec_cmd "rm -f '${RPM_TMP}'"
229
230print_status "Checking for existing installations..."
231
232## Nasty consequences if you have an existing Node or npm package
233## installed, need to inform if they are there
234echo "+ rpm -qa 'node|npm' | grep -v nodesource"
235EXISTING_NODE=$(rpm -qa 'node|npm|iojs' | grep -v nodesource)
236
237if [ "X${EXISTING_NODE}" != "X" ]; then
238
239 # NOTE(mordred) Removed -y from the yum command below.
240 print_status "\
241Your system appears to already have Node.js installed from an alternative source.\n\
242Run \`\033[1myum remove nodejs npm\033[22m\` (as root) to remove these first.\
243"
244
245fi
246
247# NOTE(mordred) Removed -y from the yum commands below.
248print_status "\
249Run \`\033[1myum install nodejs\033[22m\` (as root) to install Node.js 8.x and npm.\n\
250You may also need development tools to build native addons:\n\
251 \`yum install gcc-c++ make\`\
252"
253
254## Alternative to install dev tools: `yum groupinstall 'Development Tools'
255
256exit 0