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
|
#!/bin/bash
# Load up some libraries
my_dir="$( cd "$( dirname "$0" )" && pwd )"
source "${my_dir}/functions/locker"
source "${my_dir}/functions/common"
source "${my_dir}/functions/retry"
source "${my_dir}/functions/merge_templates"
usage() {
cat <<EOM
${0##/} - Populated values in build temple.
Required:
--template Template file
--extra Extra, arbitrary addin
--serial The build serial
--out The output file
--tar Name of tar file
--tar-d Name of directory to tar up
--version The version number of the distro
--proposed Build against proposed
--docker Install Docker/Docker compose
EOM
}
short_opts="h"
long_opts="out:,template:,serial:,tar:,tar-d:,version:,proposed,docker,extra:"
getopt_out=$(getopt --name "${0##*/}" \
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
eval set -- "${getopt_out}" || { echo "BAD INVOCATION!"; usage; exit 1; }
serial=${SERIAL:-$(date +%Y%m%d)}
# Standard templates
template_f="$(readlink -f ${0%/*}/templates/img-azure.tmpl)"
template_netaddin_f="$(readlink -f ${0%/*}/templates/img-extra-nets.tmpl)"
template_extra_f="$(readlink -f ${0%/*}/templates/img-azure-extra.tmpl)"
extra_addins=()
while [ $# -ne 0 ]; do
cur=${1}; next=${2};
case "$cur" in
--template) template_f=$2; shift;;
--extra) extra_addins+=($2); shift;;
--serial) serial=$2; shift;;
--tar) tar_f=$2; shift;;
--tar-d) tar_d=$2; shift;;
--out) out_f=$2; shift;;
--version) version=$2; shift;;
--proposed) proposed="true";;
--docker) docker="1";;
--) shift; break;;
esac
shift;
done
fail() { echo "${@}" 2>&1; exit 1;}
fail_usage() { fail "Must define $@"; }
# Create the template file for image conversion
sed -e "s,%S,${serial},g" \
-e "s,%v,${version},g" \
-e "s,%P,${proposed:-false},g" \
${template_f} > ${out_f}.base ||
fail "Unable to write template file"
# Support per-suite addins
net_addin=1
# Disable the extra nets for Azure due due to the systemd changes
dist_ge ${version} vivid && net_addin=0
# Order the addins
default_addin="${template_f//.tmpl/}-${version}-addin.tmpl"
docker_addin="${template_f//.tmpl/}-${version}-docker.tmpl"
addins=(${default_addin})
[ ${net_addin:-0} -eq 1 ] && addins+=("${template_netaddin_f}")
[ ${docker:-0} -eq 1 -a -f "${docker_addin}" ] && addins+=("${docker_addin}")
addins+=("${extra_addins[@]}" "${template_extra_f}")
merge_templates ${out_f}.base ${out_f} ${addins[@]}
debug "=================================================="
debug "Content of template:"
cat ${out_f}
debug "=================================================="
if [ -n "${tar_d}" ]; then
tar -C "${tar_d}" -cf "${tar_f}" . &&
debug "TAR'd up ${tar_d}" ||
fail "Failed to tar up ${tar_d}"
fi
exit 0
|