~ubuntu-on-ec2/vmbuilder/automated-ec2-builds-fginther

« back to all changes in this revision

Viewing changes to build-ec2-image

  • Committer: Ben Howard
  • Date: 2011-07-27 23:17:10 UTC
  • Revision ID: ben.howard@canonical.com-20110727231710-iv7naynricd0x5jk
Code-review for new build-lb-ec2-image changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
2
# vi: ts=4 noexpandtab
3
 
 
 
3
cmd_args=$*
4
4
base_d=$(dirname $(readlink -f "${0}"))
5
5
 
6
6
SKIP_FINISH=0
10
10
error() { echo "$@" 1>&2; }
11
11
debug() { error "$(date -R):" "$@"; }
12
12
cleanup() {
13
 
        [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
 
13
        [ "${preserve_image}" = "1" -o -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
14
14
}
15
15
cat_partfile() {
16
16
        # Note: this function may be overwritten in a config file
50
50
        eval set -- "${getopt_out}" ||
51
51
        bad_Usage
52
52
 
 
53
skip_gen_image=""
 
54
preserve_image=1
 
55
 
53
56
while [ $# -ne 0 ]; do
54
57
        cur=${1}; next=${2};
55
58
        case "$cur" in
56
59
                -h|--help) Usage; exit 0;;
57
60
                   --serial) serial=$2; shift;;
58
61
                   --skip-finish) SKIP_FINISH=1;;
 
62
           --image) skip_gen_image=$1;;
 
63
           --preserve) preserve_image=1;;
59
64
                --) shift; break;;
60
65
        esac
61
66
        shift;
68
73
 
69
74
[ -f "${conf}" ] || fail "${conf}: not a file"
70
75
 
 
76
owner=${USER}
71
77
suite=""
72
78
build_name=""
73
79
description=""
90
96
done
91
97
 
92
98
VMBUILDER=$(which vmbuilder 2>/dev/null) || fail "cannot find vmbuilder"
93
 
 
 
99
LBBUILD=${base_d}/build-lb-ec2-image
94
100
 
95
101
{ [ -d "${pub_d}" ] || mkdir -p "${pub_d}"; } ||
96
102
        fail "failed to make ${pub_d}"
127
133
        # seems more reliable
128
134
        execscript="${TEMP_D}/execscript"
129
135
        {
130
 
        spin=
131
 
        printf "#!/bin/bash\n"
132
 
        for v in serial build_name root_fs_label; do
133
 
                printf "%s='%s'\n" "$v" "${!v}"
134
 
        done
135
 
        printf "\n"
136
 
        cat "${base_d}/vmbuilder-uec-ec2-fixes"
 
136
            spin=
 
137
            printf "#!/bin/bash\n"
 
138
            for v in serial build_name root_fs_label; do
 
139
                    printf "%s='%s'\n" "$v" "${!v}"
 
140
            done
 
141
            printf "\n"
 
142
            cat "${base_d}/vmbuilder-uec-ec2-fixes"
137
143
        } > "${execscript}"
138
144
        chmod 755 "${execscript}"
139
145
 
140
146
        kinfo="${img_base}-kernel-info.txt"
141
147
        image="${img_base}.img"
142
 
        cmdline=(
143
 
                ${VMBUILDER} xen ubuntu
144
 
                "--suite=${suite}"
145
 
                "--arch=${arch}"
146
 
                "--dest=${tmpdest}"
147
 
                --ec2
148
 
                "--ec2-version=${description}"
149
 
                --components main,restricted,universe,multiverse
150
 
                --part "${partfile}"
151
 
                --ec2-landscape --lock-user
152
 
                "--manifest=${tmpdest}/${img_base}.manifest"
153
 
                "--tmp=${TMPDIR:-/tmp}"
154
 
                --execscript "${execscript}"
155
 
                --debug "${vmb_addargs[@]}" )
 
148
 
 
149
 
 
150
    # Use old scripts for Natty and older, and new for Oneiric and later
 
151
    if [ "${suite}" \< "oneiric" ]
 
152
    then
 
153
        cmdline=(
 
154
           ${VMBUILDER} xen ubuntu
 
155
           "--suite=${suite}"
 
156
           "--arch=${arch}"
 
157
           "--dest=${tmpdest}"
 
158
           --ec2
 
159
           "--ec2-version=${description}"
 
160
           --components main,restricted,universe,multiverse
 
161
           --part "${partfile}"
 
162
           --ec2-landscape --lock-user
 
163
           "--manifest=${tmpdest}/${img_base}.manifest"
 
164
           "--tmp=${TMPDIR:-/tmp}"
 
165
           --execscript "${execscript}"
 
166
           --debug "${vmb_addargs[@]}" )
 
167
    else
 
168
        cmdline=(
 
169
            ${LBBUILD}
 
170
            "--suite=${suite}"
 
171
            "--arch=${arch}"
 
172
            "--dest=${tmpdest}"
 
173
            "--image=root.img"
 
174
            "--part=${partfile}"
 
175
            "--rootlabel=${root_fs_label}"
 
176
            "--rootsize=${root_fs_size}"
 
177
            "--owner=${owner}"
 
178
            "--logscreen"
 
179
            "--manifest=${tmpdest}/${img_base}.manifest"
 
180
         )
 
181
    fi
156
182
 
157
183
        debug "invoking ${cmdline[*]}"
158
 
        sudo env "PATH=$PATH" "${cmdline[@]}" ||
159
 
                fail "vmbuilder failed: ${cmdline[*]}";
 
184
 
 
185
    if [ -z ${skip_gen_image} ]; then
 
186
        sudo env "PATH=$PATH" "${cmdline[@]}" ||
 
187
                fail "image generation command failed: ${cmdline[*]}";
 
188
    else
 
189
        sudo cp ${skip_gen_image} ${tmpdest} ||
 
190
            fail "unable to copy ${skip_gen_image} to ${tmpdest}";
 
191
    fi
160
192
 
161
193
        if [ ${copy_out_kernels} -ne 0 ]; then
162
194
                debug "${img_base}: copying out kernels"
163
195
                mp=$(mktemp -d "${tmpdest}/mnt.XXXXXX")
164
 
                sudo mount -o loop,ro "${tmpdest}/root.img" "${mp}" ||
 
196
                sudo mount --read-only -o loop "${tmpdest}/root.img" "${mp}" ||
165
197
                        fail "failed to mount image for copy out kernels"
166
198
 
167
199
                sudo env "PATH=$PATH" copy-out-kernels \
257
289
 
258
290
        rm "${unpacked_d}/${img_base}.img" ||
259
291
                fail "failed deletion of ${img_base}.img"
260
 
        rm -rf "${tmpdest}" || fail "failed to delete ${tmpdest}"
 
292
 
 
293
    if [ "${preserve_image}" = 0 ]; then
 
294
        rm -rf "${tmpdest}" || fail "failed to delete ${tmpdest}"
 
295
    fi
 
296
 
 
297
    set -x
261
298
done
262
299
 
263
300
exit 0