-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
230 lines (209 loc) · 9.53 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#! /bin/bash
set -u
set -e
# Some utility functions.
fail() { echo >&2 "$@"; exit 1; }
cmd() { hash "$1" >&/dev/null; } # portable 'which'
mktempfile() {
if cmd mktemp; then
if [ "osx" = "${PLATFORM_NAME}" ]; then
mktemp -t installer
else
mktemp
fi
else
echo "/tmp/puppet-enterprise-installer.XXX-${RANDOM}"
fi
}
##############################################################################
# We need to know what the PE platform tag is for this node, which requires
# digging through a bunch of data to extract it. This is currently the best
# mechanism available to do this, which is copied from the PE
# installer itself.
if [ -z "${PLATFORM_NAME:-""}" -o -z "${PLATFORM_RELEASE:-""}" ]; then
# First try identifying using lsb_release. This takes care of Ubuntu
# (lsb-release is part of ubuntu-minimal).
if type lsb_release > /dev/null 2>&1; then
t_prepare_platform=`lsb_release -icr 2>&1`
PLATFORM_NAME="$(printf "${t_prepare_platform?}" | grep -E '^Distributor ID:' | cut -s -d: -f2 | sed 's/[[:space:]]//' | tr '[[:upper:]]' '[[:lower:]]')"
# Sanitize name for unusual platforms
case "${PLATFORM_NAME?}" in
redhatenterpriseserver | redhatenterpriseclient | redhatenterpriseas | redhatenterprisees | enterpriseenterpriseserver | redhatenterpriseworkstation | redhatenterprisecomputenode | oracleserver)
PLATFORM_NAME=rhel
;;
enterprise* )
PLATFORM_NAME=centos
;;
scientific | scientifics | scientificsl )
PLATFORM_NAME=rhel
;;
'suse linux' )
PLATFORM_NAME=sles
;;
amazonami )
PLATFORM_NAME=amazon
;;
esac
# Release
PLATFORM_RELEASE="$(printf "${t_prepare_platform?}" | grep -E '^Release:' | cut -s -d: -f2 | sed 's/[[:space:]]//g')"
# Sanitize release for unusual platforms
case "${PLATFORM_NAME?}" in
centos | rhel )
# Platform uses only number before period as the release,
# e.g. "CentOS 5.5" is release "5"
PLATFORM_RELEASE="$(printf "${PLATFORM_RELEASE?}" | cut -d. -f1)"
;;
debian )
# Platform uses only number before period as the release,
# e.g. "Debian 6.0.1" is release "6"
PLATFORM_RELEASE="$(printf "${PLATFORM_RELEASE?}" | cut -d. -f1)"
if [ ${PLATFORM_RELEASE} = "testing" ] ; then
PLATFORM_RELEASE=7
fi
;;
esac
elif [ "x$(uname -s)" = "xDarwin" ]; then
PLATFORM_NAME="osx"
# sw_vers returns something like 10.9.2, but we only want 10.9 so chop off the end
t_platform_release="$(/usr/bin/sw_vers -productVersion)"
PLATFORM_RELEASE="${t_platform_release%.*}"
# Test for Solaris.
elif [ "x$(uname -s)" = "xSunOS" ]; then
PLATFORM_NAME="solaris"
t_platform_release="$(uname -r)"
# JJM We get back 5.10 but we only care about the right side of the decimal.
PLATFORM_RELEASE="${t_platform_release##*.}"
elif [ "x$(uname -s)" = "xAIX" ] ; then
PLATFORM_NAME="aix"
t_platform_release="$(oslevel | cut -d'.' -f1,2)"
PLATFORM_RELEASE="${t_platform_release}"
# Test for RHEL variant. RHEL, CentOS, OEL
elif [ -f /etc/redhat-release -a -r /etc/redhat-release -a -s /etc/redhat-release ]; then
# Oracle Enterprise Linux 5.3 and higher identify the same as RHEL
if grep -qi 'red hat enterprise' /etc/redhat-release; then
PLATFORM_NAME=rhel
elif grep -qi 'centos' /etc/redhat-release; then
PLATFORM_NAME=centos
elif grep -qi 'scientific' /etc/redhat-release; then
PLATFORM_NAME=rhel
fi
# Release - take first digit after ' release ' only.
PLATFORM_RELEASE="$(sed 's/.*\ release\ \([[:digit:]]\).*/\1/g;q' /etc/redhat-release)"
# Test for Cumulus releases
elif [ -r "/etc/os-release" ] && grep -E "Cumulus Linux" "/etc/os-release" &> /dev/null ; then
PLATFORM_NAME=cumulus
PLATFORM_RELEASE=`grep -E "VERSION_ID" "/etc/os-release" | cut -d'=' -f2 | cut -d'.' -f'1,2'`
# Test for Debian releases
elif [ -f /etc/debian_version -a -r /etc/debian_version -a -s /etc/debian_version ]; then
t_prepare_platform__debian_version_file="/etc/debian_version"
t_prepare_platform__debian_version=`cat /etc/debian_version`
if cat "${t_prepare_platform__debian_version_file?}" | grep -E '^[[:digit:]]' > /dev/null; then
PLATFORM_NAME=debian
PLATFORM_RELEASE="$(printf "${t_prepare_platform__debian_version?}" | sed 's/\..*//')"
elif cat "${t_prepare_platform__debian_version_file?}" | grep -E '^wheezy' > /dev/null; then
PLATFORM_NAME=debian
PLATFORM_RELEASE="7"
fi
elif [ -f /etc/SuSE-release -a -r /etc/SuSE-release ]; then
t_prepare_platform__suse_version=`cat /etc/SuSE-release`
if printf "${t_prepare_platform__suse_version?}" | grep -E 'Enterprise Server'; then
PLATFORM_NAME=sles
t_version=`/bin/cat /etc/SuSE-release | grep VERSION | sed 's/^VERSION = \(\d*\)/\1/' `
t_patchlevel=`cat /etc/SuSE-release | grep PATCHLEVEL | sed 's/^PATCHLEVEL = \(\d*\)/\1/' `
PLATFORM_RELEASE="${t_version}"
fi
elif [ -f /etc/system-release ]; then
if grep -qi 'amazon linux' /etc/system-release; then
PLATFORM_NAME=amazon
PLATFORM_RELEASE=6
else
fail "$(cat /etc/system-release) is not a supported platform for Puppet Enterprise v3.3.0
Please visit http://links.puppetlabs.com/puppet_enterprise_${PE_LINK_VER?}_platform_support to request support for this platform."
fi
elif [ -z "${PLATFORM_NAME:-""}" ]; then
fail "$(uname -s) is not a supported platform for Puppet Enterprise v3.3.0
Please visit http://links.puppetlabs.com/puppet_enterprise_${PE_LINK_VER?}_platform_support to request support for this platform."
fi
fi
if [ -z "${PLATFORM_NAME:-""}" -o -z "${PLATFORM_RELEASE:-""}" ]; then
fail "Unknown platform"
fi
# Architecture
if [ -z "${PLATFORM_ARCHITECTURE:-""}" ]; then
case "${PLATFORM_NAME?}" in
solaris | aix )
PLATFORM_ARCHITECTURE="$(uname -p)"
if [ "${PLATFORM_ARCHITECTURE}" = "powerpc" ] ; then
PLATFORM_ARCHITECTURE='power'
fi
;;
*)
PLATFORM_ARCHITECTURE="`uname -m`"
;;
esac
case "${PLATFORM_ARCHITECTURE?}" in
x86_64)
case "${PLATFORM_NAME?}" in
ubuntu | debian )
PLATFORM_ARCHITECTURE=amd64
;;
esac
;;
i686)
PLATFORM_ARCHITECTURE=i386
;;
ppc)
PLATFORM_ARCHITECTURE=powerpc
;;
esac
fi
# Tag
if [ -z "${PLATFORM_TAG:-""}" ]; then
case "${PLATFORM_NAME?}" in
# Enterprise linux (centos & rhel) share the same packaging
# Amazon linux is similar enough for our packages
rhel | centos | amazon )
PLATFORM_TAG="el-${PLATFORM_RELEASE?}-${PLATFORM_ARCHITECTURE?}"
;;
*)
PLATFORM_TAG="${PLATFORM_NAME?}-${PLATFORM_RELEASE?}-${PLATFORM_ARCHITECTURE?}"
;;
esac
fi
# This is the end of the code copied from the upstream installer.
##############################################################################
url="https://master.puppetlabs.vm:8140/packages/3.3.0/${PLATFORM_TAG}.bash"
install_file=$(mktempfile)
if cmd curl; then
# curl on AIX doesn't support -k, but it's the default behavior
if [ "$PLATFORM_NAME" = "aix" ]; then
CURL="curl"
else
CURL="curl -k"
fi
t_http_code="$($CURL -sLo "${install_file?}" "${url}" --write-out %{http_code} || fail "curl failed to get ${url}")"
elif cmd wget; then
# wget on AIX doesn't support SSL
[ "$PLATFORM_NAME" = "aix" ] && fail "Unable to download installation materials without curl"
# Run wget and use awk to figure out the HTTP status.
t_http_code="$(wget -O "${install_file?}" --no-check-certificate -S "${url}" 2>&1 | awk '/HTTP\/1.1/ { printf $2 }')"
if [ -z "${t_http_code?}" ]; then
fail "wget failed to get ${url}"
fi
else
fail "Unable to download installation materials without curl or wget"
fi
if [ "${t_http_code?}" != '200' ]; then
t_supported_platforms="(el-(4|5|6|7)-(i386|x86_64))|(debian-(6|7)-(i386|amd64))|(ubuntu-(10\.04|12\.04|14\.04)-(i386|amd64))|(sles-11-(i386|x86_64))|(solaris-(10|11)-(i386|sparc))|(aix-(5\.3|6\.1|7\.1)-power)|(osx-10\.9-x86_64)"
if [[ "${PLATFORM_TAG?}" =~ ${t_supported_platforms?} ]]; then
fail "The agent packages needed to support ${PLATFORM_TAG} are not present on your master. \
To add them, apply the pe_repo::platform::$(echo "${PLATFORM_TAG?}" | tr - _ | tr -dc '[:alnum:]_') class to your master node and then run Puppet. \
The required agent packages should be retrieved when puppet runs on the master, after which you can run the install.bash script again."
else
fail "This method of agent installation is not supported for ${PLATFORM_TAG?} in Puppet Enterprise v3.3.0
Please install using the puppet-enterprise-installer from the Puppet Enterprise v3.3.0 tarball"
fi
fi
bash "${install_file?}" || fail "Error running install script ${install_file?}"
# ...and we should be good.
exit 0