-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.sh
executable file
·238 lines (180 loc) · 5.23 KB
/
setup.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
231
232
233
234
235
236
237
238
#!/bin/bash
prepostinstall_checks()
{
if [ "${FACT_OSFAMILY}" == "RedHat" ];
then
PKG_INSTALL="yum install"
PKG_INSTALL_UNATTENDED="-y"
WHICH_PACKAGE="which"
fi
if [ "${FACT_OSFAMILY}" == "Debian" ];
then
PKG_INSTALL="apt-get install"
PKG_INSTALL_UNATTENDED="-y"
WHICH_PACKAGE="debianutils"
export DEBIAN_FRONTEND=noninteractive
$PKG_INSTALL update
fi
if [ "${FACT_OSFAMILY}" == "Suse" ];
then
PKG_INSTALL="zypper --non-interactive install"
PKG_INSTALL_UNATTENDED=""
WHICH_PACKAGE="which"
fi
$PKG_INSTALL $PKG_INSTALL_UNATTENDED $WHICH_PACKAGE
GITBIN=$(which git 2>/dev/null)
if [ -z "$GITBIN" ];
then
$PKG_INSTALL $PKG_INSTALL_UNATTENDED git
GITBIN=$(which git 2>/dev/null)
if [ -z "$GITBIN" ];
then
echo "please, install git"
exit 1
fi
fi
RUBYBIN=$(which ruby 2>/dev/null)
if [ -z "$GITBIN" ];
then
$PKG_INSTALL $PKG_INSTALL_UNATTENDED git
RUBYBIN=$(which ruby 2>/dev/null)
if [ -z "$RUBYBIN" ];
then
echo "please, install ruby"
exit 1
fi
fi
echo "ruby: ${RUBYBIN}"
echo "git: ${GITBIN}"
}
puppet_check()
{
PUPPET_FULL_VERSION=$(puppet --version 2>/dev/null)
if [ "$?" -ne 0 ];
then
echo "unexpected puppet error"
fi
PUPPET_MAJOR_VERSION=$(puppet --version | grep -Eo "^[0-9]")
if [ "$PUPPET_MAJOR_VERSION" -lt "3" ];
then
echo "unsupported version, please install at least 3.8"
exit 1
fi
PUPPET_MINOR_VERSION=$(puppet --version | grep -Eo "\.[0-9]*\." | cut -f2 -d.)
if [ "$PUPPET_MAJOR_VERSION" -eq "3" ] && [ "$PUPPET_MINOR_VERSION" -lt "8" ];
then
echo "unsupported version, please install at least 3.8"
exit 1
fi
}
gather_facts()
{
FACTERBIN=$(which facter 2>/dev/null)
if [ -z "$FACTERBIN" ] || [ -z "$(facter -p operatingsystemmajrelease 2>/dev/null)" ];
then
if [ -e "/etc/redhat-release" ];
then
FACT_OSFAMILY="RedHat"
FACT_OPERATINGSYSTEM="RedHat"
FACT_OPERATINGSYSTEMRELEASE=$(grep -Eo "[0-9]*\.[0-9]*" /etc/redhat-release)
FACT_OPERATINGSYSTEMMAJRELEASE=$(grep -Eo "[0-9]*\.[0-9]*" /etc/redhat-release | cut -f1 -d.)
elif [ -e "/etc/SuSE-release" ];
then
FACT_OSFAMILY="Suse"
FACT_OPERATINGSYSTEM="SLES"
FACT_OPERATINGSYSTEMRELEASE="$(grep VERSION /etc/SuSE-release | awk '{ print $NF }').$(grep PATCHLEVEL /etc/SuSE-release | awk '{ print $NF }')"
FACT_OPERATINGSYSTEMMAJRELEASE="$(grep VERSION /etc/SuSE-release | awk '{ print $NF }')"
elif [ -e "/etc/lsb-release" ];
then
FACT_OPERATINGSYSTEM=$(grep DISTRIB_ID /etc/lsb-release | cut -f2 -d=)
if [ "${FACT_OPERATINGSYSTEM}" == "Ubuntu" ];
then
FACT_OSFAMILY="Debian"
FACT_OPERATINGSYSTEMRELEASE="$(grep DISTRIB_RELEASE /etc/lsb-release | cut -f2 -d=)"
FACT_OPERATINGSYSTEMMAJRELEASE="$(grep DISTRIB_RELEASE /etc/lsb-release | cut -f2 -d=)"
FACT_LSBDISTCODENAME="$(grep DISTRIB_CODENAME /etc/lsb-release | cut -f2 -d=)"
fi
fi
else
FACT_OSFAMILY=$(facter -p osfamily)
FACT_OPERATINGSYSTEM=$(facter -p operatingsystem)
FACT_OPERATINGSYSTEMRELEASE=$(facter -p operatingsystemrelease)
FACT_OPERATINGSYSTEMMAJRELEASE=$(facter -p operatingsystemmajrelease)
FACT_LSBDISTCODENAME=$(facter -p lsbdistcodename)
fi
}
puppet_install()
{
if [ "${FACT_OSFAMILY}" == "RedHat" ];
then
rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-el-${FACT_OPERATINGSYSTEMMAJRELEASE}.noarch.rpm
$PKG_INSTALL $PKG_INSTALL_UNATTENDED puppet-agent
elif [ "${FACT_OSFAMILY}" == "Debian" ];
then
if [ "${FACT_OPERATINGSYSTEMMAJRELEASE}" == "18.04" ] || [ "${FACT_OPERATINGSYSTEMMAJRELEASE}" == "20.04" ] ;
then
apt-get update
$PKG_INSTALL $PKG_INSTALL_UNATTENDED puppet
else
wget https://apt.puppetlabs.com/puppet5-release-${FACT_LSBDISTCODENAME}.deb
dpkg -i puppet5-release-${FACT_LSBDISTCODENAME}.deb
apt-get update
$PKG_INSTALL $PKG_INSTALL_UNATTENDED puppet-agent
fi
elif [ "${FACT_OSFAMILY}" == "Suse" ];
then
echo "SuSE unsupported"
exit 1
fi
if [ -f /etc/profile.d/puppet-agent.sh ];
then
source /etc/profile.d/puppet-agent.sh
fi
puppet --version >/dev/null 2>&1
if [ "$?" -ne 0 ];
then
echo "error installing puppet"
exit 0
fi
echo "PUPPET VERSION: $(puppet --version)"
gem list | grep deep_merge >/dev/null 2>&1
if [ "$?" -ne 0 ];
then
gem install deep_merge
fi
gem list | grep r10k >/dev/null 2>&1
if [ "$?" -ne 0 ];
then
gem install r10k
fi
/opt/puppetlabs/puppet/bin/gem list | grep r10k >/dev/null 2>&1
if [ "$?" -ne 0 ];
then
/opt/puppetlabs/puppet/bin/gem install r10k
fi
}
gather_facts
prepostinstall_checks
puppet_install
puppet_check
mkdir -p /opt
if [ ! -d "/opt/puppet-masterless/.git" ];
then
cd "/opt"
rm -fr puppet-masterless
git clone https://github.com/jordiprats/puppet-masterless
else
cd "/opt/puppet-masterless"
git pull origin master
fi
cd -
if [ ! -f "/etc/profile.d/puppet-masterless.sh" ];
then
cat <<"EOF" > /etc/profile.d/puppet-masterless.sh
# masterless
if ! echo $PATH | grep -q /opt/puppet-masterless ; then
export PATH=$PATH:/opt/puppet-masterless
fi
EOF
. /etc/profile.d/puppet-masterless.sh
fi