/
psb
executable file
·135 lines (118 loc) · 4.24 KB
/
psb
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
#!/bin/bash
#
# Bootstrap a puppet master install on Redhat-flavour distros
# Assumes nothing more than a minimal OS install
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright © 2013 Robin Bowes <robin.bowes@yo61.com>
#
PUPPETLABS_REPO_BASE=http://yum.puppetlabs.com
REDHAT_RELEASE=/etc/redhat-release
EPEL_REPO_BASE=http://dl.fedoraproject.org/pub/epel
TEMP_DIR=${TEMP:-/tmp}
MODULE_DIR="${TEMP_DIR}/modules"
# hash defining the puppetlabs RPM release for each OS
declare -A PUPPETLABS_RELEASE=(
["fedora/f19"]="10"
["fedora/f20"]="10"
["el/5"]="10"
["el/6"]="10"
["el/7"]="10"
)
# hash defining the EPEL release for each OS
declare -A EPEL_RELEASE=(
["el/5"]="4"
["el/6"]="8"
["el/7"]="0.2"
)
# hash defining whether or not to use the beta EPEL repo
declare -A EPEL_BETA=(
["el/5"]=""
["el/6"]=""
["el/7"]="beta/"
)
function error() {
echo "ERROR: $1"
exit "$2"
}
function download(){
if ! curl --fail --location --silent "$1" -o "$2"; then
error "Error downloading $1" 101
fi
}
function rpm_installed () {
rpm -q --quiet "$1"
}
# First, make sure we are on a RH-flavour OS and get the family name and major version
if [[ -f $REDHAT_RELEASE ]] ; then
OS_FAMILY=$(awk '{print $1}' $REDHAT_RELEASE)
OS_VERSION=$(awk '{print $3}' $REDHAT_RELEASE)
OS_MAJOR_VERSION=${OS_VERSION%%.*}
else
error "$REDHAT_RELEASE not found" 101
fi
# The URL for the release RPM is different for Fedora vs RHEL/CentOS
# Special case for Fedora, otherwise treat everything else the same
if [[ ${OS_FAMILY} == "Fedora" ]] ; then
URL_FAMILY="fedora/f"
else
URL_FAMILY="el/"
fi
# Make sure we know what the release RPM release number is for this os/version
FAMILY_VERSION="${URL_FAMILY}${OS_MAJOR_VERSION}"
PUPPETLABS_RPM_RELEASE="${PUPPETLABS_RELEASE["$FAMILY_VERSION"]}"
if [[ -z $PUPPETLABS_RPM_RELEASE ]] ; then
error "puppetlabs release rpm not known for $FAMILY_VERSION" 101
fi
# retrieve the release RPM and install it
PUPPETLABS_RELEASE_NAME="puppetlabs-release-${OS_MAJOR_VERSION}-${PUPPETLABS_RPM_RELEASE}"
PUPPETLABS_RELEASE_RPM="${PUPPETLABS_RELEASE_NAME}.noarch.rpm"
if rpm_installed "${PUPPETLABS_RELEASE_NAME}" ; then
echo "${PUPPETLABS_RELEASE_NAME} installed"
else
PUPPETLABS_REPO_URL="${PUPPETLABS_REPO_BASE}/${FAMILY_VERSION}/products/x86_64/${PUPPETLABS_RELEASE_RPM}"
download "${PUPPETLABS_REPO_URL}" "${TEMP_DIR}/$PUPPETLABS_RELEASE_RPM"
yum localinstall "${TEMP_DIR}/$PUPPETLABS_RELEASE_RPM"
fi
# Now, let's do EPEL on non-Fedora platforms
if [[ ${OS_FAMILY} != "Fedora" ]] ; then
EPEL_RPM_RELEASE=${EPEL_RELEASE[$FAMILY_VERSION]}
if [[ -z $EPEL_RPM_RELEASE ]] ; then
error "epel release rpm not known for $FAMILY_VERSION" 101
fi
EPEL_RELEASE_NAME="epel-release-${OS_MAJOR_VERSION}-${EPEL_RPM_RELEASE}"
EPEL_RELEASE_RPM="${EPEL_RELEASE_NAME}.noarch.rpm"
if rpm_installed "${EPEL_RELEASE_NAME}" ; then
echo "${EPEL_RELEASE_NAME} installed"
else
EPEL_REPO_URL="${EPEL_REPO_BASE}/${EPEL_BETA[$FAMILY_VERSION]}${OS_MAJOR_VERSION}/x86_64/${EPEL_RELEASE_RPM}"
download "${EPEL_REPO_URL}" "${TEMP_DIR}/$EPEL_RELEASE_RPM"
yum -y localinstall "${TEMP_DIR}/$EPEL_RELEASE_RPM"
fi
fi
# install puppet, so we can use it to bootstrap the master
if rpm_installed puppet ; then
echo "puppet installed"
else
yum -y install puppet
fi
# create the temp module dir - this may already exist
mkdir -p "${MODULE_DIR}"
# make sure the puppet module is not present
rm -rf "${MODULE_DIR}/puppet"
# Now, checkout some modules to install the puppet master
puppet module install stephenrjohnson/puppet --modulepath="${MODULE_DIR}"
# Finally, run puppet to set up the puppetmaster
puppet apply --modulepath="${MODULE_DIR}" --execute "class{'::puppet::master': }"