forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboxer.sh
More file actions
executable file
·184 lines (163 loc) · 4.86 KB
/
boxer.sh
File metadata and controls
executable file
·184 lines (163 loc) · 4.86 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
#! /bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
fi
BASEDIR=$PWD/boxes
DEVCLOUD_BASEBUILD_DIR=$BASEDIR/basebox-build
echo $DEVCLOUD_BASEBUILD_DIR
DEVCLOUD_XEN_BASEBUILD_DIR=$BASEDIR/xenbox-build
DEVCLOUD_BASE_NAME='devcloudbase'
DEVCLOUD_XEN_BASE_NAME='devcloudbase-xen'
OS='ubuntu-12.04.1-server-i386'
basebox() {
set +x
rvm rvmrc trust $DEVCLOUD_BASEBUILD_DIR/
case "$1" in
build)
cd $DEVCLOUD_BASEBUILD_DIR/
set -ex
vagrant basebox define $DEVCLOUD_BASE_NAME $OS
cp definition.rb postinstall.sh preseed.cfg definitions/$DEVCLOUD_BASE_NAME/
vagrant basebox build $DEVCLOUD_BASE_NAME -f -a -n -r
vagrant basebox export $DEVCLOUD_BASE_NAME -f
set +ex
cd $DEVCLOUD_XEN_BASEBUILD_DIR
set -ex
vagrant box add $DEVCLOUD_BASE_NAME $DEVCLOUD_BASEBUILD_DIR/${DEVCLOUD_BASE_NAME}.box -f
;;
clean)
cd $DEVCLOUD_BASEBUILD_DIR/
set -x
rm -f iso/*.iso
vagrant -f basebox destroy $DEVCLOUD_BASE_NAME #-f
vagrant basebox undefine $DEVCLOUD_BASE_NAME
#hackery to inherit the proper rvmrc for the hacked vagrant
set +x
cd $BAS$DEVCLOUD_XEN_BASEBUILD_DIR
set -x
vagrant -f box remove $DEVCLOUD_BASE_NAME virtualbox
set +x
cd $DEVCLOUD_BASEBUILD_DIR
set -x
rm -f ${DEVCLOUD_BASE_NAME}.box
set +x
cd $BASEDIR
#rvm --force gemset delete vagrant-release-cloudstack
;;
esac
}
xenbox() {
set +x
rvm rvmrc trust $DEVCLOUD_XEN_BASEBUILD_DIR/
case "$1" in
build)
cd $DEVCLOUD_XEN_BASEBUILD_DIR
#adding it here because it needs to be added into the $VAGRANT_HOME of
#the hacked vagrant
set -ex
vagrant up
vagrant halt
vagrant package default --output ${DEVCLOUD_XEN_BASE_NAME}.box
vagrant box add $DEVCLOUD_XEN_BASE_NAME ${DEVCLOUD_XEN_BASE_NAME}.box -f
;;
clean)
cd $DEVCLOUD_XEN_BASEBUILD_DIR
set -x
vagrant -f box remove $DEVCLOUD_XEN_BASE_NAME virtualbox
vagrant destroy -f
rm -f ${DEVCLOUD_XEN_BASE_NAME}.box
set +x
#rvm --force gemset delete vagrant-xen-cloudstack
set -x
;;
esac
}
usage() {
cat <<EOF
$(basename $0) [-h] [-b] [c] (basebox|xenbox) | all
Builds / cleans boxes used to build the devcloud box
where:
-h show this help text
-b builds the box(es)
-c cleans the box(es)
EOF
}
while getopts 'hbc' option; do
case "$option" in
h) usage
exit
;;
b) action="build"
;;
c) action="clean"
;;
?) printf "illegal option: '%s'\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
posargs=$@
#removes duplicate positionals
posargs=$(echo "$posargs" | tr ' ' '\n' | nl | sort -u -k2 | sort -n | cut -f2-)
for arg in $posargs; do
case "$arg" in
basebox)
true
;;
xenbox)
true
;;
all)
true
;;
*)
usage
exit 1
;;
esac
done
cd $BASEDIR
for arg in $posargs; do
case "$1" in
"all")
case "$action" in
clean)
xenbox $action
basebox $action
;;
build)
basebox $action
xenbox $action
;;
esac
;;
$arg)
$arg $action
;;
esac
done