Skip to content

Commit cc92a4c

Browse files
committed
add deb/rpm install.sh
1 parent 93c84c8 commit cc92a4c

2 files changed

Lines changed: 339 additions & 0 deletions

File tree

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
20+
function cleanup() {
21+
test -f /etc/apt/sources.list.vmops.bak && mv -f /etc/apt/sources.list.vmops.bak /etc/apt/sources.list || true
22+
}
23+
24+
function setuprepo() {
25+
pathtorepo=`pwd`
26+
echo "Setting up the temporary repository..." >&2
27+
cp /etc/apt/sources.list /etc/apt/sources.list.vmops.bak
28+
echo "
29+
deb file://$pathtorepo ./" >> /etc/apt/sources.list
30+
31+
echo "Fetching updated listings..." >&2
32+
aptitude update
33+
}
34+
35+
function installed() {
36+
dpkg -l "$@" 2> /dev/null | grep '^i' > /dev/null || return $?
37+
}
38+
39+
function doinstall() {
40+
aptitude install "$@" || return $?
41+
}
42+
43+
function doupdate() {
44+
service cloud-management stop
45+
apt-get --force-yes -y -u install "cloud-*"
46+
service cloud-management restart
47+
}
48+
49+
function doremove() {
50+
apt-get remove "$@" || return $?
51+
}
52+
53+
[ `whoami` != 'root' ] && echo "This script must run as root" && exit 1
54+
55+
trap "cleanup" INT TERM EXIT
56+
57+
cd `dirname "$0"`
58+
setuprepo
59+
60+
installms=" M) Install the Management Server
61+
"
62+
installag=" A) Install the Agent
63+
"
64+
installus=" S) Install the Usage Monitor
65+
"
66+
installdb=" D) Install the database server
67+
"
68+
quitoptio=" Q) Quit
69+
"
70+
unset removedb
71+
unset upgrade
72+
unset remove
73+
74+
if installed cloud-client || installed cloud-agent || installed cloud-usage; then
75+
upgrade=" U) Upgrade the CloudStack packages installed on this computer
76+
"
77+
remove=" R) Stop any running CloudStack services and remove the CloudStack packages from this computer
78+
"
79+
fi
80+
if installed cloud-client ; then
81+
unset installms
82+
fi
83+
if installed cloud-agent ; then
84+
unset installag
85+
fi
86+
if installed cloud-usage ; then
87+
unset installus
88+
fi
89+
if installed mysql-server ; then
90+
unset installdb
91+
removedb=" E) Remove the MySQL server (will not remove the MySQL databases)
92+
"
93+
fi
94+
95+
read -p "Welcome to the Cloud.com CloudStack Installer. What would you like to do?
96+
97+
$installms$installag$installbm$installus$installdb$upgrade$remove$removedb$quitoptio
98+
> " installtype
99+
100+
if [ "$installtype" == "q" -o "$installtype" == "Q" ] ; then
101+
102+
true
103+
104+
elif [ "$installtype" == "m" -o "$installtype" == "M" ] ; then
105+
106+
echo "Installing the Management Server..." >&2
107+
doinstall cloud-client
108+
true
109+
110+
elif [ "$installtype" == "a" -o "$installtype" == "A" ] ; then
111+
112+
echo "Installing the Agent..." >&2
113+
if doinstall cloud-agent cloud-system-iso ; then
114+
echo "Agent installation is completed, please add the host from management server" >&2
115+
else
116+
true
117+
fi
118+
elif [ "$installtype" == "s" -o "$installtype" == "S" ] ; then
119+
120+
echo "Installing the Usage Server..." >&2
121+
doinstall cloud-usage
122+
true
123+
124+
elif [ "$installtype" == "d" -o "$installtype" == "D" ] ; then
125+
126+
echo "Installing the MySQL server..." >&2
127+
if doinstall mysql-server ; then
128+
if /usr/sbin/service mysql status > /dev/null 2>&1 ; then
129+
echo "Restarting the MySQL server..." >&2
130+
/usr/sbin/service mysql restart # mysqld running already, we restart it
131+
else
132+
echo "Starting the MySQL server..." >&2
133+
/usr/sbin/service mysql start # we start mysqld for the first time
134+
fi
135+
else
136+
true
137+
fi
138+
139+
elif [ "$installtype" == "u" -o "$installtype" == "U" ] ; then
140+
141+
echo "Updating the CloudStack and its dependencies..." >&2
142+
doupdate
143+
144+
elif [ "$installtype" == "r" -o "$installtype" == "R" ] ; then
145+
146+
echo "Removing all CloudStack packages on this computer..." >&2
147+
doremove 'cloud-*'
148+
149+
elif [ "$installtype" == "e" -o "$installtype" == "E" ] ; then
150+
151+
echo "Removing the MySQL server on this computer..." >&2
152+
doremove 'mysql-server'
153+
154+
else
155+
156+
echo "Incorrect choice. Nothing to do." >&2
157+
exit 8
158+
159+
fi
160+
161+
162+
echo "Done" >&2
163+
cleanup
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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

Comments
 (0)