|
| 1 | +#!/bin/bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +function cleanup() { |
| 20 | + rm -f /etc/yum.repos.d/cloud-temp.repo || true |
| 21 | +} |
| 22 | + |
| 23 | +function setuprepo() { |
| 24 | + pathtorepo=`pwd` |
| 25 | + echo "Setting up the temporary repository..." >&2 |
| 26 | + echo \ |
| 27 | +"[cloud-temp] |
| 28 | +baseurl=file://$pathtorepo |
| 29 | +gpgcheck=0 |
| 30 | +enabled=1 |
| 31 | +name=CloudStack temporary repository |
| 32 | +" > /etc/yum.repos.d/cloud-temp.repo |
| 33 | + |
| 34 | + echo "Cleaning Yum cache..." >&2 |
| 35 | + rm /var/cache/yum/cloud-temp/ -rf |
| 36 | + yum clean expire-cache || true |
| 37 | +} |
| 38 | + |
| 39 | +function installed() { |
| 40 | + rpm -q "$@" > /dev/null 2>&1 || return $? |
| 41 | +} |
| 42 | + |
| 43 | +function doinstall() { |
| 44 | + yum install "$@" || return $? |
| 45 | +} |
| 46 | + |
| 47 | +function doupdate() { |
| 48 | + yum update --enablerepo='cloud-temp' 'cloud-*' || return $? |
| 49 | +} |
| 50 | + |
| 51 | +function doremove() { |
| 52 | + yum remove "$@" || return $? |
| 53 | +} |
| 54 | + |
| 55 | +[ `whoami` != 'root' ] && echo "This script must run as root" && exit 1 |
| 56 | + |
| 57 | +trap "cleanup" INT TERM EXIT |
| 58 | + |
| 59 | +cd `dirname "$0"` |
| 60 | +setuprepo |
| 61 | + |
| 62 | +installms=" M) Install the Management Server |
| 63 | +" |
| 64 | +installag=" A) Install the Agent |
| 65 | +" |
| 66 | +installbm=" B) Install BareMetal Agent |
| 67 | +" |
| 68 | +installus=" S) Install the Usage Monitor |
| 69 | +" |
| 70 | +installdb=" D) Install the database server |
| 71 | +" |
| 72 | +quitoptio=" Q) Quit |
| 73 | +" |
| 74 | +unset removedb |
| 75 | +unset upgrade |
| 76 | +unset remove |
| 77 | + |
| 78 | +if installed cloud-client || installed cloud-agent || installed cloud-usage || installed cloud-baremetal-agent; then |
| 79 | + upgrade=" U) Upgrade the CloudStack packages installed on this computer |
| 80 | +" |
| 81 | + remove=" R) Stop any running CloudStack services and remove the CloudStack packages from this computer |
| 82 | +" |
| 83 | +fi |
| 84 | +if installed cloud-client ; then |
| 85 | + unset installms |
| 86 | +fi |
| 87 | +if installed cloud-agent ; then |
| 88 | + unset installag |
| 89 | +fi |
| 90 | +if installed cloud-baremetal-agent ; then |
| 91 | + unset installbm |
| 92 | +fi |
| 93 | +if installed cloud-usage ; then |
| 94 | + unset installus |
| 95 | +fi |
| 96 | +if installed mysql-server ; then |
| 97 | + unset installdb |
| 98 | + removedb=" E) Remove the MySQL server (will not remove the MySQL databases) |
| 99 | +" |
| 100 | +fi |
| 101 | + |
| 102 | +read -p "Welcome to the Cloud.com CloudStack Installer. What would you like to do? |
| 103 | +
|
| 104 | +$installms$installag$installbm$installus$installdb$upgrade$remove$removedb$quitoptio |
| 105 | + > " installtype |
| 106 | + |
| 107 | +if [ "$installtype" == "q" -o "$installtype" == "Q" ] ; then |
| 108 | + |
| 109 | + true |
| 110 | + |
| 111 | +elif [ "$installtype" == "m" -o "$installtype" == "M" ] ; then |
| 112 | + |
| 113 | + echo "Installing the Management Server..." >&2 |
| 114 | + doinstall cloud-client cloud-premium |
| 115 | + true |
| 116 | + |
| 117 | +elif [ "$installtype" == "a" -o "$installtype" == "A" ] ; then |
| 118 | + |
| 119 | + echo "Installing the Agent..." >&2 |
| 120 | + if doinstall cloud-agent cloud-premium ; then |
| 121 | + echo "Agent installation is completed, please add the host from management server" >&2 |
| 122 | + else |
| 123 | + true |
| 124 | + fi |
| 125 | +elif [ "$installtype" == "b" -o "$installtype" == "B" ] ; then |
| 126 | + echo "Installing the BareMetal Agent..." >&2 |
| 127 | + doinstall cloud-baremetal-agent |
| 128 | + true |
| 129 | + |
| 130 | +elif [ "$installtype" == "s" -o "$installtype" == "S" ] ; then |
| 131 | + |
| 132 | + echo "Installing the Usage Server..." >&2 |
| 133 | + doinstall cloud-usage cloud-premium |
| 134 | + true |
| 135 | + |
| 136 | +elif [ "$installtype" == "d" -o "$installtype" == "D" ] ; then |
| 137 | + |
| 138 | + echo "Installing the MySQL server..." >&2 |
| 139 | + if doinstall mysql-server ; then |
| 140 | + /sbin/chkconfig --add mysqld |
| 141 | + /sbin/chkconfig --level 345 mysqld on |
| 142 | + if /sbin/service mysqld status > /dev/null 2>&1 ; then |
| 143 | + echo "Restarting the MySQL server..." >&2 |
| 144 | + /sbin/service mysqld restart # mysqld running already, we restart it |
| 145 | + else |
| 146 | + echo "Starting the MySQL server..." >&2 |
| 147 | + /sbin/service mysqld start # we start mysqld for the first time |
| 148 | + fi |
| 149 | + else |
| 150 | + true |
| 151 | + fi |
| 152 | + |
| 153 | +elif [ "$installtype" == "u" -o "$installtype" == "U" ] ; then |
| 154 | + |
| 155 | + echo "Updating the CloudStack and its dependencies..." >&2 |
| 156 | + doupdate |
| 157 | + |
| 158 | +elif [ "$installtype" == "r" -o "$installtype" == "R" ] ; then |
| 159 | + |
| 160 | + echo "Removing all CloudStack packages on this computer..." >&2 |
| 161 | + doremove 'cloud-*' |
| 162 | + |
| 163 | +elif [ "$installtype" == "e" -o "$installtype" == "E" ] ; then |
| 164 | + |
| 165 | + echo "Removing the MySQL server on this computer..." >&2 |
| 166 | + doremove 'mysql-server' |
| 167 | +else |
| 168 | + |
| 169 | + echo "Incorrect choice. Nothing to do." >&2 |
| 170 | + exit 8 |
| 171 | + |
| 172 | +fi |
| 173 | + |
| 174 | + |
| 175 | +echo "Done" >&2 |
| 176 | +cleanup |
0 commit comments