-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake.sh
executable file
·145 lines (117 loc) · 3.2 KB
/
make.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
#!/usr/bin/env bash
# Copyright (c) 2014 Hooklift. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
set -o pipefail
# Uncomment for debugging
# set -x
list() {
echo "Available templates: "
for t in $(ls **/*.json)
do
echo ✱ $t
done
}
build() {
local path=${1}
if [[ -z ${path} || ! -f ${path} ]]; then
echo "$0: An existing packer template is required" >&2
exit 1
fi
#vmware-iso, virtualbox-iso, etc
local builder=${2}
if [[ -n "${builder}" ]]; then
local onlyOpt="-only ${builder}"
local provider=`expr "${builder}" : '\(.*\)-.*'`
fi
# Split path by /
# path has the following form: coreos/coreos-324.1.0.json
local parts=''
OIFS=$IFS
IFS='/' read -a parts <<< "${path}"
IFS=$OIFS
local os=${parts[0]}
local tmpl=${parts[1]}
local version=`expr "${tmpl}" : '.*-\(.*\).json'`
# Packer templates use this variable to download the correct ISO for the given version
export OS_VERSION="${version}"
local box="$os-$version"
rm -rf output/"${provider}*/${box}"
local cwd=$(pwd)
cd $os && packer build ${onlyOpt} ${tmpl}
cd ${cwd}
#Packaging one box
echo "Packaging box..."
if [[ -z "${provider}" ]]; then
local providers=$(ls output)
else
local providers="${provider}"
fi
for p in "${providers}"
do
cd output/"${p}"
tar cvzf "${box}-${p}.box" "${box}"
rm -rf "${box}"
cd ${cwd}
done
echo "Success!"
}
cfgdrv() {
local path=${1}
local workspace="./new-drive/openstack/latest"
mkdir -p ${workspace}
trap "{ rm -rf './new-drive' ; exit 0; }" EXIT
cp ${path} ${workspace}/user_data
if ! mkisofs -R -V config-2 -o cfgdrv.iso new-drive; then
echo "$0: Error making ISO image" >&2
exit 1
fi
}
usage() {
echo "
NAME:
Make.sh - Builds Hooklift boxes
USAGE:
./make.sh <target> <template> <provider> Available providers are the same seen for builders in Packer.
TARGETS:
list List available Packer templates
build Builds a box for a given provider. By default, it builds all boxes for all providers
cfgdrv Creates ISO image with user-data configuration for config-drive
EXAMPLES:
$ ./make.sh list
Available templates:
✱ coreos/coreos-324.1.0.json
✱ coreos/coreos-alpha.json
✱ coreos/coreos-beta.json
# While working on templates you will find yourself running this often
$ ./make.sh build coreos/coreos-324.1.0.json vmware-iso
$ ./make.sh cfgdrv oem/config.yml
"
exit 0
}
case $1 in
list)
list
;;
build)
if [[ -z "${2}" ]]; then
for t in $(ls **/*.json)
do
build "${t}" "${3}"
done
exit 0
fi
build "${2}" "${3}"
;;
cfgdrv)
if [[ -z "${2}" || ! -f "${2}" ]]; then
echo "$0: A path to an existing cloudinit file is required" >&2
exit 1
fi
cfgdrv "${2}"
;;
*)
usage
;;
esac