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
|
#!/bin/bash
short_opts="h"
long_opts="distro:,stream:,maas-git-repo:,out:,template:,serial:,local:,base-name:,out_d:"
getopt_out=$(getopt --name "${0##*/}" \
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
eval set -- "${getopt_out}" || { echo "BAD INVOCATION!"; usage; exit 1; }
usage() {
cat <<EOM
${0##/} - Populated values in build temple.
Required:
--distro Distro code name, i.e. precise
--template Template file
--stream Stream, i.e. daily, release
--base-name The name of the file to work on
--serial The build serial
--out The output file
--out_d Where to stuff the output files
Optional:
--maas-git-repo git repo for maas image code
EOM
}
fail() { echo "${@}" 2>&1; exit 1;}
serial="${serial:-$(date +%Y%m%d)}"
maas_git_repo="${maas_git_repo:-lp:~maas-images-maintainers/maas-images}"
template_f="${PWD}/img-maas.tmpl"
while [ $# -ne 0 ]; do
cur=${1}; next=${2};
case "$cur" in
--distro) distro=$2; shift;;
--stream) stream=$2; shift;;
--local) local_d=$2; shift;;
--maas-git-repo) maas_git_repo=$2; shift;;
--base-name) base_name=$2; shift;;
--template) template_f=$2; shift;;
--out) out_f=$2; shift;;
--out_d) out_d=$2; shift;;
--) shift; break;;
esac
shift;
done
fail_usage() { fail "Must define $@"; }
[ -z "${distro}" ] && fail_usage "--distro"
[ -z "${stream}" ] && fail_usage "--stream"
[ -z "${local_d}" ] && fail_usage "--local"
[ -z "${out_f}" ] && fail_usage "--out"
[ -z "${out_d}" ] && fail_usage "--out_d"
[ -z "${base_name}" ] && fail_usage "--base-name"
case "$distro" in
trusty) arches="${ARCH_TYPE:-i386 amd64 armhf}";
[[ "$(uname -m)" =~ ppc64 ]] && arches="ppc64el";;
*) arches="${ARCH_TYPE:-i386 amd64 armhf}";;
esac
sed -e "s,%d,${distro},g" \
-e "s,%S,${stream},g" \
-e "s,%M,${maas_git_repo},g" \
-e "s,%D,${local_d},g" \
-e "s,%B,${base_name},g" \
-e "s,%s,${serial},g" \
-e "s,%O,${out_d},g" \
-e "s,%A,${arches},g" \
${template_f} > ${out_f} ||
fail "Unable to write template file"
exit 0
|