forked from rcbops/opencenter-install-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·434 lines (385 loc) · 13.5 KB
/
install.sh
File metadata and controls
executable file
·434 lines (385 loc) · 13.5 KB
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/bin/bash
# OpenCenter(TM) is Copyright 2013 by Rackspace US, Inc.
##############################################################################
#
# OpenCenter is licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. This
# version of OpenCenter includes Rackspace trademarks and logos, and in
# accordance with Section 6 of the License, the provision of commercial
# support services in conjunction with a version of OpenCenter which includes
# Rackspace trademarks and logos is prohibited. OpenCenter source code and
# details are available at: # https://github.com/rcbops/opencenter or upon
# written request.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0 and a copy, including this
# notice, is available in the LICENSE file accompanying this software.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the # specific language governing permissions and limitations
# under the License.
#
##############################################################################
#
#
# set -x
set -e
ROLE="agent"
OPENCENTER_SERVER=${OPENCENTER_SERVER:-"0.0.0.0"}
SERVER_PORT="8443"
USAGE="Usage: ./install-server.sh [server | agent | dashboard] <Server-IP> [password]"
if [ $# -ge 1 ]; then
if [ $1 != "server" ] && [ $1 != "agent" ] && [ $1 != "dashboard" ]; then
echo "Invalid Role specified - Defaulting to 'server' Role"
echo $USAGE
else
ROLE=$1
fi
if [ $# -ge 2 ]; then
if ( echo $2 | egrep -q "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" ); then
OPENCENTER_SERVER=$2
else
echo "Invalid IP specified - Defaulting to 0.0.0.0"
echo $USAGE
fi
if [[ $3 ]]; then
PASSWORD=$3
fi
fi
fi
VERSION="1.0.0"
PASSWORD=${PASSWORD:-password}
function verify_apt_package_exists() {
# $1 - name of package to test
if [[ -z $VERBOSE ]]; then
dpkg -s $1 >/dev/null 2>&1
else
dpkg -s $1
fi
if [ $? -ne 0 ];
then
return 1
else
return 0
fi
}
function install_opencenter_yum_repo() {
releasever="6"
releasedir="Fedora"
case $1 in
"Fedora") releasever="17"; releasedir="Fedora" ;;
"CentOS") releasever="6"; releasedir="RedHat" ;;
"RedHat") releasever="6"; releasedir="RedHat" ;;
esac
echo "Adding OpenCenter yum repository $releasedir/$releasever"
cat > /etc/yum.repos.d/rcb-utils.repo <<EOF
[rcb-utils]
name=RCB Utility packages for OpenCenter $1
baseurl=$uri/stable/rpm/$releasedir/$releasever/\$basearch/
enabled=1
gpgcheck=1
gpgkey=$uri/stable/rpm/RPM-GPG-RCB.key
EOF
rpm --import $uri/stable/rpm/RPM-GPG-RCB.key &>/dev/null || :
if [[ $1 = "Fedora" ]]; then
echo "skipping epel installation for Fedora"
else
if (! rpm -q epel-release 2>&1>/dev/null ); then
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
if [[ $? -ne 0 ]]; then
echo "Unable to add the EPEL repository."
exit 1
fi
fi
fi
}
function install_opencenter_apt_repo() {
local aptkey=$(which apt-key)
local keyserver="keyserver.ubuntu.com"
echo "Adding Opencenter apt repository"
if [ -e ${apt_file_path} ];
then
# TODO(shep): Need to do some sort of checking here
/bin/true
else
echo "deb ${uri}/${pkg_path} ${platform_name} ${apt_repo}" > $apt_file_path
fi
if [[ -z $VERBOSE ]]; then
${aptkey} adv --keyserver ${keyserver} --recv-keys ${apt_key} >/dev/null 2>&1
else
${aptkey} adv --keyserver ${keyserver} --recv-keys ${apt_key}
fi
if [[ $? -ne 0 ]]; then
echo "Unable to add apt-key."
exit 1
fi
}
function install_ubuntu() {
local aptget=$(which apt-get)
# Install apt repo
install_opencenter_apt_repo
# Run an apt-get update to make sure sources are up to date
echo "Refreshing package list"
if [[ -z $VERBOSE ]]; then
${aptget} -q update >/dev/null
else
${aptget} update
fi
if [[ $? -ne 0 ]];
then
echo "apt-get update failed to execute successfully."
exit 1
fi
if [ "${ROLE}" == "server" ]; then
echo "Installing Opencenter-Server"
cat <<EOF | debconf-set-selections
opencenter-agent opencenter/server string ${OPENCENTER_SERVER}
opencenter-agent opencenter/port string ${SERVER_PORT}
EOF
if [[ ${PASSWORD} ]]; then
cat <<EOF | debconf-set-selections
opencenter opencenter/password string ${PASSWORD}
EOF
fi
if ! ( ${aptget} install -y -q ${server_pkgs} ); then
echo "Failed to install opencenter"
exit 1
fi
fi
if [ "${ROLE}" != "dashboard" ]; then
echo "Installing Opencenter-Agent"
cat <<EOF | debconf-set-selections
opencenter-agent opencenter/server string ${OPENCENTER_SERVER}
opencenter-agent opencenter/port string ${SERVER_PORT}
EOF
if [[ ${PASSWORD} ]]; then
cat <<EOF | debconf-set-selections
opencenter-agent opencenter/password string ${PASSWORD}
EOF
fi
if ! ( ${aptget} install -y -q ${agent_pkgs} ); then
echo "Failed to install opencenter-agent"
exit 1
fi
echo ""
echo "Installing Agent Plugins"
if ! ( ${aptget} install -y -q ${agent_plugins} ); then
echo "Failed to install opencenter-agent"
exit 1
fi
/etc/init.d/opencenter-agent restart
fi
if [ "${ROLE}" == "dashboard" ]; then
${aptget} install -y -q debconf-utils
echo "Installing Opencenter Dashboard"
cat << EOF | debconf-set-selections
opencenter-dashboard opencenter/server_port string ${SERVER_PORT}
opencenter-dashboard opencenter/server_ip string ${OPENCENTER_SERVER}
EOF
if ! ( ${aptget} install -y -q ${dashboard_pkgs} ); then
echo "Failed to install Opencentre Dashboard"
exit 1
fi
fi
echo ""
echo "Verifying packages installed successfully"
pkg_list=( ${agent_pkgs} ${agent_plugins} )
if [ "${ROLE}" == "server" ]; then
pkg_list=( ${server_pkgs} ${agent_pkgs} ${agent_plugins} )
fi
if [ "${ROLE}" == "dashboard" ]; then
pkg_list=( ${dashboard_pkgs} )
fi
for x in ${pkg_list[@]}; do
if ! verify_apt_package_exists ${x};
then
echo "Package ${x} was not installed successfully"
echo ".. please run dpkg -i ${x} for more information"
exit 1
fi
done
}
function install_rpm() {
if [ "${ROLE}" == "server" ]; then
echo "Installing Opencenter-Server"
if ! ( yum install -y -q ${server_pkgs} ); then
echo "Failed to install opencenter"
exit 1
fi
stop opencenter || :
start opencenter
fi
if [ "${ROLE}" != "dashboard" ]; then
echo "Installing Opencenter-Agent"
if ! ( yum install -y -q ${agent_pkgs} ); then
echo "Failed to install opencenter-agent"
exit 1
fi
echo ""
echo "Installing Agent Plugins"
if ! ( yum install -y -q ${agent_plugins} ); then
echo "Failed to install opencenter-agent"
exit 1
fi
sed -i "s/admin:password/admin:${PASSWORD}/g" /etc/opencenter/agent.conf.d/opencenter-agent-endpoints.conf
stop opencenter-agent || :
start opencenter-agent
fi
if [ "${ROLE}" == "dashboard" ]; then
echo "Installing Opencenter Dashboard"
if ! ( yum install -y -q ${dashboard_pkgs} ); then
echo "Failed to install Opencentre Dashboard"
exit 1
fi
# the opencenter-dashboard package restarts httpd, so this is
# here for safety
sleep 15s
chkconfig httpd on
current_IP=$( cat /etc/httpd/conf.d/opencenter-dashboard.conf | egrep -o -m 1 "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" )
sed -i "s/${current_IP}/${OPENCENTER_SERVER}/" /etc/httpd/conf.d/opencenter-dashboard.conf
service httpd restart
fi
if [ "${ROLE}" == "agent" ]; then
current_IP=$( cat /etc/opencenter/agent.conf.d/opencenter-agent-endpoints.conf | egrep -o -m 1 "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" )
sed -i "s/${current_IP}/${OPENCENTER_SERVER}/" /etc/opencenter/agent.conf.d/opencenter-agent-endpoints.conf
stop opencenter-agent || :
start opencenter-agent
elif [ "${ROLE}" == "server" ]; then
current_IP=$( cat /etc/opencenter/agent.conf.d/opencenter-agent-endpoints.conf | egrep -o -m 1 "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" )
sed -i "s/${current_IP}/0.0.0.0/" /etc/opencenter/agent.conf.d/opencenter-agent-endpoints.conf
sed -i "s/^admin_pass = password/admin_pass = ${PASSWORD}/g" /etc/opencenter/opencenter.conf
stop opencenter-agent || :
start opencenter-agent
stop opencenter
start opencenter
fi
iptables -F
}
function usage() {
cat <<EOF
usage: $0 options
This script will install opencenter packages.
OPTIONS:
-h Show this message
-v Verbose output
EOF
}
function display_version() {
cat <<EOF
$0 (version: $VERSION)
EOF
}
################################################
# -*-*-*-*-*-*-*-*-*- MAIN -*-*-*-*-*-*-*-*-*- #
################################################
####################
# Global Variables
VERBOSE=
####################
####################
# Package Variables
uri="http://packages.opencenter.rackspace.com"
pkg_path="/stable/deb/rcb-utils/"
server_pkgs="opencenter-server python-opencenter opencenter-client opencenter-agent-output-adventurator"
agent_pkgs="opencenter-agent"
agent_plugins="opencenter-agent-input-task opencenter-agent-output-chef opencenter-agent-output-service opencenter-agent-output-packages opencenter-agent-output-openstack opencenter-agent-output-update-actions"
dashboard_pkgs="opencenter-dashboard"
####################
####################
# APT Specific variables
apt_repo="rcb-utils"
apt_key="765C5E49F87CBDE0"
apt_file_name="${apt_repo}.list"
apt_file_path="/etc/apt/sources.list.d/${apt_file_name}"
####################
# Parse options
while getopts "hvV" option
do
case $option in
h)
usage
exit 1
;;
v) VERBOSE=1 ;;
V)
display_version
exit 1
;;
?)
usage
exit 1
;;
esac
done
arch=$(uname -m)
if [ -f "/etc/lsb-release" ];
then
platform=$(grep "DISTRIB_ID" /etc/lsb-release | cut -d"=" -f2 | tr "[:upper:]" "[:lower:]")
platform_version=$(grep DISTRIB_RELEASE /etc/lsb-release | cut -d"=" -f2)
elif [ -f "/etc/system-release-cpe" ];
then
platform=$(cat /etc/system-release-cpe | cut -d ":" -f 3)
platform_version=$(cat /etc/system-release-cpe | cut -d ":" -f 5)
else
echo "Your platform is not supported. Please email RPCFeedback@rackspace.com and let us know."
exit 1
fi
# On ubuntu the version number needs to be mapped to a name
case $platform_version in
"12.04") platform_name="precise" ;;
esac
# echo "Arch: ${arch}"
# echo "Platform: ${platform}"
# echo "Version: ${platform_version}"
# Run os dependent install functions
case $platform in
"ubuntu") install_ubuntu ;;
"redhat") install_opencenter_yum_repo "RedHat"
install_rpm
;;
"centos") install_opencenter_yum_repo "CentOS"
install_rpm
;;
"fedoraproject") install_opencenter_yum_repo "Fedora"
install_rpm
;;
esac
echo ""
echo "
OpenCenter(TM) is Copyright 2013 by Rackspace US, Inc.
OpenCenter is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. This version of OpenCenter includes Rackspace trademarks and logos, and in accordance with Section 6 of the License, the provision of commercial support services in conjunction with a version of OpenCenter which includes Rackspace trademarks and logos is prohibited. OpenCenter source code and details are available at: https://github.com/rcbops/opencenter/ or upon written request.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 and a copy, including this notice, is available in the LICENSE.TXT file accompanying this software.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
"
echo "You have installed Opencenter. WooHoo!!"
if [[ "${ROLE}" = "dashboard" ]]; then
my_ip=$(ip a show dev `ip route | grep default | awk '{print $5}'` | grep "inet " | awk '{print $2}' | cut -d "/" -f 1)
cat <<EOF
Your OpenCenter dashboard is available at https://${my_ip}
EOF
fi
if [[ "${ROLE}" = "agent" ]]; then
echo ""
echo "Agent username and password configurations are stored in"
echo "/etc/opencenter/agent.conf.d/opencenter-agent-endpoints.conf"
echo " root = https://<username>:<password>@<opencenter-server-ip>:8443"
echo " admin = https://<username>:<password>@<opencenter-server-ip>:8443/admin"
echo ""
echo "If you change this you must also update the agent endpoint"
echo "configurations."
echo ""
fi
if [[ "${ROLE}" = "server" ]]; then
echo ""
echo "Server username and password configurations are stored in"
echo "/etc/opencenter/opencenter.conf"
echo " admin_user = <admin username>"
echo " admin_pass = <admin password>"
echo ""
echo "If you change this you must also update the agent endpoint"
echo "configurations."
echo ""
fi
exit