-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-spacewalk-2.8.sh
executable file
·248 lines (217 loc) · 7.96 KB
/
install-spacewalk-2.8.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
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
# Sync channels?
SYNC=0
# Temporary directory for downloads
TEMPDIR="/tmp"
# curl options
CURLOPTS="-s -m 5"
# Identify CentOS Version
CENTOSVERSION=$(rpm -q centos-release --qf '%{VERSION}' 2>/dev/null)
# Check minimum CentOS Version
if [ ${CENTOSVERSION} -lt 6 ]; then
echo "ERROR: Sorry, CentOS Version ${CENTOSVERSION} is not supported"
exit 1
fi
# Install Spacewalk repo
if [ ! -f /etc/yum.repos.d/spacewalk.repo ]; then
echo
echo "#####################################"
echo "## Installing Spacewalk Repository ##"
echo "#####################################"
(cd ${TEMPDIR} && curl ${CURLOPTS} -O https://copr-be.cloud.fedoraproject.org/results/%40spacewalkproject/spacewalk-2.8/epel-${CENTOSVERSION}-x86_64/00736372-spacewalk-repo/spacewalk-repo-2.8-11.el${CENTOSVERSION}.centos.noarch.rpm)
rpm -Uvh ${TEMPDIR}/spacewalk-repo-*.noarch.rpm || exit 1
rm -f ${TEMPDIR}/spacewalk-repo-*.noarch.rpm
fi
# Install EPEL (for dependencies)
if [ ! -f /etc/yum.repos.d/epel.repo ]; then
echo
echo "################################"
echo "## Installing EPEL Repository ##"
echo "################################"
(cd ${TEMPDIR} && curl ${CURLOPTS} -O https://dl.fedoraproject.org/pub/epel/epel-release-latest-${CENTOSVERSION}.noarch.rpm)
rpm -Uvh ${TEMPDIR}/epel-release-*.noarch.rpm || exit 1
rm -f ${TEMPDIR}/epel-release-*.noarch.rpm
fi
# Spacewalk Client Tools (for dependencies, too)
if [ ! -f /etc/yum.repos.d/spacewalk-client.repo ]; then
echo
echo "############################################"
echo "## Installing Spacewalk-Client Repository ##"
echo "############################################"
(cd ${TEMPDIR} && curl ${CURLOPTS} -O https://copr-be.cloud.fedoraproject.org/results/%40spacewalkproject/spacewalk-2.8/epel-${CENTOSVERSION}-x86_64/00736372-spacewalk-repo/spacewalk-client-repo-2.8-11.el${CENTOSVERSION}.centos.noarch.rpm)
rpm -ihv ${TEMPDIR}/spacewalk-client-repo-*.noarch.rpm || exit 1
rm -f ${TEMPDIR}/spacewalk-client-repo-*.noarch.rpm
fi
# Install Spacewalk
rpm -qi spacewalk-common 2>&1 >/dev/null
if [ $? -eq 1 ]; then
echo
echo "##########################"
echo "## Installing Spacewalk ##"
echo "##########################"
yum --nogpgcheck -y install spacewalk-postgresql spacewalk-setup-postgresql spacewalk-utils spacecmd
fi
# Create answer file
ANSWERFILE=`mktemp`
cat > $ANSWERFILE <<EOF
admin-email = root@localhost
ssl-set-org = .
ssl-set-org-unit = .
ssl-set-city = .
ssl-set-state = .
ssl-set-country = DE
ssl-password = spacewalk
ssl-set-email = root@localhost
ssl-set-cnames = .
ssl-config-sslvhost = Y
db-backend=postgresql
db-name=spaceschema
db-user=spaceuser
db-password=supersecret
db-host=localhost
db-port=5432
enable-tftp=Y
EOF
# Add firewall rules
if [ ${CENTOSVERSION} -eq 7 ]; then
if [ -x /usr/bin/firewall-cmd ]; then
echo "#################################"
echo "## Opening firewall for HTTP/S ##"
echo "#################################"
firewall-cmd -q --permanent --add-service=http
firewall-cmd -q --permanent --add-service=https
firewall-cmd -q --reload
fi
fi
# Setup database first to work around this bug:
# https://bugzilla.redhat.com/show_bug.cgi?id=1524221
if [ -d /var/lib/pgsql ]; then
echo
echo "###########################"
echo "## Initializing database ##"
echo "###########################"
rm -rf /var/lib/pgsql/data
/usr/bin/postgresql-setup initdb
fi
# Run setup
grep db_password /etc/rhn/rhn.conf > /dev/null
if [ $? -eq 1 ]; then
echo
echo "##########################"
echo "## Setting up Spacewalk ##"
echo "##########################"
/usr/bin/spacewalk-setup --answer-file=${ANSWERFILE}
fi
rm -f ${ANSWERFILE}
# Run pgtune
echo
echo "####################"
echo "## Running pgtune ##"
echo "####################"
yum -y install pgtune
pgtune --type=web -c 600 -i /var/lib/pgsql/data/postgresql.conf > /var/lib/pgsql/data/postgresql.conf.pgtune
mv /var/lib/pgsql/data/postgresql.conf /var/lib/pgsql/data/postgresql.conf.orig
cd /var/lib/pgsql/data/
ln -s postgresql.conf.pgtune postgresql.conf
service postgresql restart
# Get ISOs for CentOS 6 and 7
echo
echo "#############################"
echo "## Downloading CentOS ISOs ##"
echo "#############################"
mkdir -p /var/iso-images/
mkdir -p /var/distro-trees/CentOS-6-x86_64
mkdir -p /var/distro-trees/CentOS-7-x86_64
cd /var/iso-images
if [ ! -f CentOS-6.9-x86_64-netinstall.iso ]; then
curl ${CURLOPTS} -O http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.9-x86_64-netinstall.iso
fi
if [ ! -f CentOS-7-x86_64-NetInstall-1708.iso ]; then
curl ${CURLOPTS} -O http://mirror.rackspace.com/CentOS/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1708.iso
fi
grep CentOS-6.9-x86_64-netinstall.iso /etc/fstab > /dev/null
if [ $? -ne 0 ]; then
cat >> /etc/fstab <<EOF
/var/iso-images/CentOS-6.9-x86_64-netinstall.iso /var/distro-trees/CentOS-6-x86_64 iso9660 loop,ro 0 0
EOF
fi
grep CentOS-7-x86_64-NetInstall-1708.iso /etc/fstab > /dev/null
if [ $? -ne 0 ]; then
cat >> /etc/fstab <<EOF
/var/iso-images/CentOS-7-x86_64-NetInstall-1708.iso /var/distro-trees/CentOS-7-x86_64 iso9660 loop,ro 0 0
EOF
fi
echo
echo "##########################"
echo "## Mounting CentOS ISOs ##"
echo "##########################"
grep /var/distro-trees/CentOS-6-x86_64 /etc/mtab > /dev/null
if [ $? -ne 0 ]; then
mount /var/distro-trees/CentOS-6-x86_64
fi
grep /var/distro-trees/CentOS-7-x86_64 /etc/mtab > /dev/null
if [ $? -ne 0 ]; then
mount /var/distro-trees/CentOS-7-x86_64
fi
echo
echo "============================="
echo "=== INSTALLATION COMPLETE ==="
echo "============================="
echo
echo
echo "###########################"
echo "## Setting up admin user ##"
echo "###########################"
echo
SWUSER=admin
SWPASS=admin1
TEMPFILE=$(mktemp)
# from https://gist.github.com/vinzent/4bba600573bc9eeb33c4#gistcomment-1810454
if [ "$(satwho | wc -l)" = "0" ]; then
curl --silent https://localhost/rhn/newlogin/CreateFirstUser.do --insecure -D - >${TEMPFILE}
cookie=$(egrep -o 'JSESSIONID=[^ ]+' ${TEMPFILE})
csrf=$(egrep csrf_token ${TEMPFILE} | egrep -o 'value=[^ ]+' | egrep -o '[0-9]+')
curl --noproxy '*' \
--cookie "$cookie" \
--insecure \
--data "csrf_token=-${csrf}&submitted=true&orgName=DefaultOrganization&login=${SWUSER}&desiredpassword=${SWPASS}&desiredpasswordConfirm=${SWPASS}&email=root%40localhost&prefix=Mr.&firstNames=Administrator&lastName=Spacewalk&" \
https://localhost/rhn/newlogin/CreateFirstUser.do
if [ "$(satwho | wc -l)" = "0" ]; then
echo "Error: user creation failed" >&2
fi
fi
rm -f ${TEMPFILE}
echo
echo "#########################"
echo "## Setting up channels ##"
echo "#########################"
echo
/usr/bin/spacewalk-common-channels -v -u ${SWUSER} -p ${SWPASS} -a i386,x86_64 'centos6*'
/usr/bin/spacewalk-common-channels -v -u ${SWUSER} -p ${SWPASS} -a x86_64 'centos7*'
if [ ${SYNC} -gt 0 ]; then
echo
echo "#######################################"
echo "## Starting Sync for Update channels ##"
echo "#######################################"
echo
/usr/bin/spacecmd -u ${SWUSER} -p ${SWPASS} softwarechannel_syncrepos centos6-i386-updates
/usr/bin/spacecmd -u ${SWUSER} -p ${SWPASS} softwarechannel_syncrepos centos6-x86_64-updates
/usr/bin/spacecmd -u ${SWUSER} -p ${SWPASS} softwarechannel_syncrepos centos7-x86_64-updates
# spacewalk-repo-sync -e 'xorg*,libreoffice*,thunderbird*,firefox*,autocorr*,java*,kernel-debug*' --channel centos6-i386-updates
# spacewalk-repo-sync --channel centos6-x86_64-updates
# spacewalk-repo-sync --channel centos7-x86_64-updates
# spacewalk-repo-sync --channel centos6-i386
# spacewalk-repo-sync --channel centos6-x86_64
# spacewalk-repo-sync --channel centos7-x86_64
fi
echo
echo "################################"
echo "## Installing useful packages ##"
echo "################################"
echo
yum -y install wget perl-Frontier-RPC perl-Text-Unidecode
cd
wget http://cefs.steve-meier.de/errata.latest.xml
wget http://cefs.steve-meier.de/errata-import.tar
tar xf errata-import.tar
exit