forked from AppScale/gts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
189 lines (172 loc) · 6.13 KB
/
bootstrap.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
#!/bin/bash
#
# Simple script to install AppScale and tools from the master branch
# Author: AppScale Team <[email protected]>
set -e
# Defaults values for repositories and branches.
APPSCALE_REPO="git://github.com/AppScale/appscale.git"
APPSCALE_TOOLS_REPO="git://github.com/AppScale/appscale-tools.git"
APPSCALE_BRANCH="master"
APPSCALE_TOOLS_BRANCH="master"
FORCE_UPGRADE="N"
UNIT_TEST="n"
usage() {
echo "Usage: ${0} [--repo <repo>][--tools-repo <repo>][-t]"
echo
echo "Options:"
echo " --repo <repo> Specify appscale repo (default $APPSCALE_REPO)"
echo " --branch <branch> Specify appscale branch (default $APPSCALE_BRANCH)"
echo " --tools-repo <repo> Specify appscale-tools repo (default $APPSCALE_TOOLS_REPO"
echo " --tools-branch <branch> Specify appscale-tools branch (default $APPSCALE_TOOLS_BRANCH)"
echo " --force-upgrade Force upgrade even if some check fails."
echo " -t Run unit tests"
exit 1
}
echo -n "Checking to make sure you are root..."
if [ "$(id -u)" != "0" ]; then
echo "Failed" 1>&2
exit 1
fi
echo "Success"
set -e
# Let's get the command line arguments.
while [ $# -gt 0 ]; do
if [ "${1}" = "--repo" ]; then
shift
if [ -z "${1}" ]; then
usage
fi
APPSCALE_REPO="${1}"
shift
continue
fi
if [ "${1}" = "--branch" ]; then
shift
if [ -z "${1}" ]; then
usage
fi
APPSCALE_BRANCH="${1}"
shift
continue
fi
if [ "${1}" = "--tools-repo" ]; then
shift
if [ -z "${1}" ]; then
usage
fi
APPSCALE_TOOLS_REPO="${1}"
shift
continue
fi
if [ "${1}" = "--tools-branch" ]; then
shift
if [ -z "${1}" ]; then
usage
fi
APPSCALE_TOOLS_BRANCH="${1}"
shift
continue
fi
if [ "${1}" = "--force-upgrade" ]; then
FORCE_UPGRADE="Y"
shift
continue
fi
if [ "${1}" = "-t" ]; then
UNIT_TEST="Y"
shift
continue
fi
usage
done
# At this time we expect to be installed in $HOME.
cd $HOME
# Let's pull the github repositories.
echo
echo "Will be using the following github repo:"
echo "git clone ${APPSCALE_REPO} --branch ${APPSCALE_BRANCH}"
echo "git clone ${APPSCALE_TOOLS_REPO} --branch ${APPSCALE_TOOLS_BRANCH}"
echo "Exit now (ctrl-c) if this is incorrect"
echo
sleep 5
apt-get update
apt-get install -y git
if [ ! -d appscale ]; then
git clone ${APPSCALE_REPO} --branch ${APPSCALE_BRANCH}
git clone ${APPSCALE_TOOLS_REPO} --branch ${APPSCALE_TOOLS_BRANCH}
fi
# Since the last step in appscale_build.sh is to create the certs directory,
# its existence indicates that appscale has already been installed.
if [ -d appscale/.appscale/certs ]; then
APPSCALE_MAJOR="$(sed -n 's/.*\([0-9]\)\+\.\([0-9]\)\+\.[0-9]/\1/gp' appscale/VERSION)"
APPSCALE_MINOR="$(sed -n 's/.*\([0-9]\)\+\.\([0-9]\)\+\.[0-9]/\2/gp' appscale/VERSION)"
if [ -z "$APPSCALE_MAJOR" -o -z "$APPSCALE_MINOR" ]; then
echo "Cannot determine version of AppScale!"
exit 1
fi
echo
echo "Found AppScale version $APPSCALE_MAJOR.$APPSCALE_MINOR: upgrading it."
# Make sure AppScale is not running.
MONIT=$(which monit)
if $MONIT summary |grep controller > /dev/null ; then
echo "AppScale is still running: please stop it"
[ "$FORCE_UPGRADE" = "Y" ] || exit 1
elif echo $MONIT |grep local > /dev/null ; then
# AppScale is not running but there is a monit
# leftover from the custom install.
$MONIT quit
fi
# This sleep is to allow the user to Ctrl-C in case an upgrade is
# not wanted.
sleep 5
# Let's keep a copy of the old config: we need to move it to avoid
# questions from dpkg.
if [ -e /etc/haproxy/haproxy.cfg ]; then
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.appscale.old
fi
# Remove control files we added before 1.14, and re-add the
# default ones.
if [ $APPSCALE_MAJOR -le 1 -a $APPSCALE_MINOR -le 14 ]; then
rm -f /etc/default/haproxy /etc/init.d/haproxy /etc/default/monit /etc/monitrc
if dpkg-query -l haproxy > /dev/null 2> /dev/null ; then
apt-get -o DPkg::Options::="--force-confmiss" --reinstall install haproxy
fi
if dpkg-query -l monit > /dev/null 2> /dev/null ; then
apt-get -o DPkg::Options::="--force-confmiss" --reinstall install monit
fi
fi
(cd appscale; git pull)
(cd appscale-tools; git pull)
fi
echo -n "Building AppScale..."
if ! (cd appscale/debian; bash appscale_build.sh) ; then
echo "failed!"
exit 1
fi
echo -n "Building AppScale Tools..."
if ! (cd appscale-tools/debian; bash appscale_build.sh) ; then
echo "failed!"
exit 1
fi
# Run unit tests if asked.
if [ "$UNIT_TEST" = "Y" ]; then
echo "Running Unit tests"
(cd appscale; rake)
if [ $? -gt 0 ]; then
echo "Unit tests failed for appscale!"
exit 1
fi
(cd appscale-tools; rake)
if [ $? -gt 0 ]; then
echo "Unit tests failed for appscale-tools!"
exit 1
fi
echo "Unit tests complete"
fi
# Let's source the profles so this image can be used right away.
. /etc/profile.d/appscale.sh
. /etc/profile.d/appscale-tools.sh
echo "*****************************************"
echo "AppScale and AppScale tools are installed"
echo "*****************************************"
exit 0