~ubuntu-on-ec2/vmbuilder/jenkins_kvm-add-azure-cc

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
#!/bin/bash
short_opts="h"
long_opts="distro:,arch:,build-type:,bzr-automated-builds:,bzr-pubscripts:,bzr-livebuild:,bzr-vmbuilder:,out:,template:,serial:,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:
    --distro        Distro code name, i.e. precise
    --arch          Arch, i.e. amd64, i386, armel, armhf
    --template      Template file
    --serial        The build serial
    --out           The output file
    --proposed      Build against -proposed

    Optional:
    --bzr-automated-builds  bzr branch for automated ec2 builds
    --bzr-pubscripts        bzr branch of EC2 Publishing Scripts
    --bzr-livebuild         bzr branch of live-builder
    --bzr-vmbuilder         bzr branch of vmbuilder
EOM
}


fail() { echo "${@}" 2>&1; exit 1;}

serial=$(date +%Y%m%d)
bzr_automated_builds="http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds"
bzr_pubscripts="http://bazaar.launchpad.net/~ubuntu-on-ec2/ubuntu-on-ec2/ec2-publishing-scripts"
bzr_livebuild="http://bazaar.launchpad.net/~ubuntu-on-ec2/live-build/cloud-images"
bzr_vmbuilder="http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/0.11a"
template_f="${PWD}/img-build.tmpl"
proposed=0

while [ $# -ne 0 ]; do
  cur=${1}; next=${2};
  case "$cur" in
    --distro)                   distro=$2;  shift;;
    --arch)                     arch=$2;    shift;;
    --build-type)               build_type=$2;  shift;;
    --bzr-automated-builds)     bzr_automated_builds=$2; shift;;
    --bzr-pubscripts)           bzr_pubscripts=$2; shift;;
    --bzr-livebuild)            bzr_livebuild=$2; shift;;
    --bzr-vmbuilder)            bzr_vmbuilder=$2; shift;;
    --template)                 template_f=$2; shift;;
    --serial)                   serial=$2; shift;;
    --out)                      out_f=$2; shift;;
    --proposed)                 proposed=1;;
    --) shift; break;;
  esac
  shift;
done

fail_usage() { fail "Must define $@"; }

[ -z "${distro}" ] && fail_usage "--distro"
[ -z "${arch}" ] && fail_usage "--arch"
[ -z "${build_type}" ] && fail_usage "--build-type"
[ -z "${out_f}" ] && fail_usage "--out"

sed -e "s,%d,${distro},g" \
    -e "s,%a,${arch},g" \
    -e "s,%b,${build_type},g" \
    -e "s,%A,${bzr_automated_builds},g" \
    -e "s,%P,${bzr_pubscripts},g" \
    -e "s,%L,${bzr_livebuild},g" \
    -e "s,%V,${bzr_vmbuilder},g" \
    -e "s,%S,${serial},g" \
    -e "s,%p,${proposed:-0},g" \
    -e "s,%C,$(awk 1 ORS='\\n' < "${HOME}/.lp_creds")," \
    ${template_f} > ${out_f} ||
        fail "Unable to write template file"

exit 0