~ubuntu-on-ec2/vmbuilder/jenkins_kvm-philroche-eoan-python3-openstackclient

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
#!/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"

short_opts="h"
long_opts="out:,template:,serial:,tar:,tar-d:,version:,proposed"
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:
    --template      Template file
    --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
EOM
}

debug() { echo "${@}"; }
serial=$(date +%Y%m%d)
template_f="${0%/*}/templates/img-azure.tmpl"
template_r="${0%/*}/img-azure-daily.tmpl"

while [ $# -ne 0 ]; do
  cur=${1}; next=${2};
  case "$cur" in
    --template)                 template_f=$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"; shift;;
    --) 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} ||
        fail "Unable to write template file"

# Support per-suite addins
set -x
awk '/ADDIN_HERE/{n++}{print >"template" n ".txt" }' ${out_f}
addin_name="${template_f//.tmpl/}-${version}-addin.tmpl"
if [ -e "${addin_name}" ]; then
    cat template.txt ${addin_name} template[1-9].txt > ${out_f}
else
    cat template.txt template[1-9].txt > ${out_f}
fi
set +x

rm template*
sed -e "s,ADDIN_HERE,# END Addins,g" -i  ${out_f}

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