You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
livecd-rootfs/live-build/ubuntu-cpc/hooks.d/base/vmdk-ova-image.binary

111 lines
3.0 KiB

#!/bin/bash -eux
# vi: ts=4 expandtab
#
# Generate OVA images
#
# OVA images are, by defintiion a tarball consisting of a disk image, OVF file
# and checksums. This step produces an OVA that is suitable for use with
# Cloud's that support the OVF specification.
#
# For this step, we re-use the VMDK's made in 040-vmdk-image.binary
case ${SUBPROJECT:-} in
minimized)
echo "Skipping minimized $0 build as images won't boot with linux-kvm"
exit 0
;;
*)
;;
esac
# Switch on $ARCH to determine which ID and description to use in the produced
# OVF. We have fancy Ubuntu-specific IDs in the OVF specification, we might as
# well use them.
Import patches-unapplied version 2.376 to ubuntu/xenial-proposed Imported using git-ubuntu import. Changelog parent: 80fddc56a2b4d6ed82dcce3ef56028b37e40705a New changelog entries: [ Michael Terry ] * Change real name for phablet user to "Ubuntu" in ubuntu-touch. [ Steve Langasek ] * Drop BuildLiveCD from the examples; we now use launchpad-buildd to drive livefs builds, so BuildLiveCD is obsolete and misleading. * Add hooks to ubuntu-cpc to divert /bin/sync in the chroot and undivert it at the end. This is a general-purpose change that should be applied to all flavors and archs, but at the moment it's only needed on armhf+raspi2 to work around the raspberrypi2-firmware postinst calling sync, which is actually warranted in the normal case. * If a subarch is specified for a cloud image build, don't build rootfs artifacts; these should come from the 'generic' build. * Fix architecture handling in hooks. We know we're always being invoked from a launchpad-buildd-like setup, which passes ARCH and SUBARCH in the environment, because auto/config and auto/build both rely on this. So don't scatter dpkg --print-architecture calls throughout, especially when many of these are not cross-build-aware. * Refactor ubuntu-cpc hooks to allow us to handle images where the root partition should not be partition 1. [ Ben Howard ] * ubuntu-cpc: fix hooks/032-disk-image.binary call to create_empty_partition, which requires five args due to "-u" * ubuntu-cpc: in hooks/030-root-tarball.binary create /lib/modules to fix (LP: 1543204). [ Dimitri John Ledkov ] * Do not remove linux-base, when purging all the linux-*, in the tarball build. Otherwise ubuntu-minimal is removed, and things get crazy. * Correct initrd.img symlink, kernel/hooks should actually produce the right thing here, but meh. * Chroot to execute zipl, because it's nice. * Use the right loop device to install zipl onto. [ Steve Langasek ] * Refactor ubuntu-cpc hooks to always produce a 'plain' rootfs via live-build and reuse this for the tarball, instead of lb_binary_rootfs creating some artifact that we ignore / throw away. * Initial support for raspi2 subarch. * Import live-build/ubuntu-cpc/hooks/raspi2/mkknlimg from https://github.com/raspberrypi/linux/blob/rpi-4.1.y/scripts/mkknlimg and use it to install a bootable uboot.bin.
9 years ago
case $ARCH in
amd64)
ovf_id=94
ovf_os_type="ubuntu64Guest"
ovf_desc_bits=64 ;;
*)
echo "OVA images are not supported for $ARCH yet.";
exit 0;;
esac
cur_d=${PWD}
my_d=$(dirname $(readlink -f ${0}))
base_vmdk="livecd.ubuntu-cpc.vmdk"
Import patches-unapplied version 2.376 to ubuntu/xenial-proposed Imported using git-ubuntu import. Changelog parent: 80fddc56a2b4d6ed82dcce3ef56028b37e40705a New changelog entries: [ Michael Terry ] * Change real name for phablet user to "Ubuntu" in ubuntu-touch. [ Steve Langasek ] * Drop BuildLiveCD from the examples; we now use launchpad-buildd to drive livefs builds, so BuildLiveCD is obsolete and misleading. * Add hooks to ubuntu-cpc to divert /bin/sync in the chroot and undivert it at the end. This is a general-purpose change that should be applied to all flavors and archs, but at the moment it's only needed on armhf+raspi2 to work around the raspberrypi2-firmware postinst calling sync, which is actually warranted in the normal case. * If a subarch is specified for a cloud image build, don't build rootfs artifacts; these should come from the 'generic' build. * Fix architecture handling in hooks. We know we're always being invoked from a launchpad-buildd-like setup, which passes ARCH and SUBARCH in the environment, because auto/config and auto/build both rely on this. So don't scatter dpkg --print-architecture calls throughout, especially when many of these are not cross-build-aware. * Refactor ubuntu-cpc hooks to allow us to handle images where the root partition should not be partition 1. [ Ben Howard ] * ubuntu-cpc: fix hooks/032-disk-image.binary call to create_empty_partition, which requires five args due to "-u" * ubuntu-cpc: in hooks/030-root-tarball.binary create /lib/modules to fix (LP: 1543204). [ Dimitri John Ledkov ] * Do not remove linux-base, when purging all the linux-*, in the tarball build. Otherwise ubuntu-minimal is removed, and things get crazy. * Correct initrd.img symlink, kernel/hooks should actually produce the right thing here, but meh. * Chroot to execute zipl, because it's nice. * Use the right loop device to install zipl onto. [ Steve Langasek ] * Refactor ubuntu-cpc hooks to always produce a 'plain' rootfs via live-build and reuse this for the tarball, instead of lb_binary_rootfs creating some artifact that we ignore / throw away. * Initial support for raspi2 subarch. * Import live-build/ubuntu-cpc/hooks/raspi2/mkknlimg from https://github.com/raspberrypi/linux/blob/rpi-4.1.y/scripts/mkknlimg and use it to install a bootable uboot.bin.
9 years ago
if [ "$ARCH" = "amd64" ]; then
base_vmdk="livecd.ubuntu-cpc.vmdk"
fi
if [ ! -e ${base_vmdk} ]; then
find . | grep vmdk
exit 1
fi
# Lets be safe about this
scratch_d=$(mktemp -d)
trap "rm -rf ${scratch_d}" EXIT
# Used to identify bits
suite=$(chroot chroot lsb_release -c -s)
version=$(chroot chroot lsb_release --release --short)
distro=$(chroot chroot lsb_release --id --short | tr [:upper:] [:lower:])
# Put our vmdk in place for OVA conversion
prefix="${distro}-${suite}-${version}-cloudimg"
vmdk_f="${scratch_d}/${prefix}.vmdk"
cp ${base_vmdk} ${vmdk_f}
# Get information about the VMDK
vmdk_size=$(du -b "${vmdk_f}" | cut -f1)
vmdk_capacity=$(qemu-img info "${vmdk_f}" | awk '-F[\( ]' '$1 ~ /virtual/ && $NF ~ /bytes.*/ {print$(NF-1)}')
# Populate the OVF template
ovf="${scratch_d}/${prefix}.ovf"
cp ${my_d}/ovf/ubuntu-ova-v1-vmdk.tmpl ${ovf}
serial_stamp=$(date +%Y%m%d)
sed -i "${ovf}" \
-e "s/@@NAME@@/${prefix}-${serial_stamp}/g" \
-e "s/@@FILENAME@@/${vmdk_f##*/}/g" \
-e "s/@@VMDK_FILE_SIZE@@/${vmdk_size}/g" \
-e "s/@@VMDK_CAPACITY@@/${vmdk_capacity}/g" \
-e "s/@@NUM_CPUS@@/2/g" \
-e "s/@@VERSION@@/${version}/g" \
-e "s/@@DATE@@/${serial_stamp}/g" \
-e "s/@@MEM_SIZE@@/1024/g" \
-e "s/@@OVF_ID@@/${ovf_id}/g" \
-e "s/@@OVF_OS_TYPE@@/${ovf_os_type}/g" \
-e "s/@@OVF_DESC_BITS@@/${ovf_desc_bits}/g"
# Get the checksums
vmdk_sha256=$(sha256sum ${vmdk_f} | cut -d' ' -f1)
ovf_sha256=$(sha256sum ${ovf} | cut -d' ' -f1)
# Generate the manifest
manifest="${scratch_d}/${prefix}.mf"
cat > "${manifest}" <<EOF
SHA256(${vmdk_f##*/})= ${vmdk_sha256}
SHA256(${ovf##*/})= ${ovf_sha256}
EOF
# Now create the OVA
echo "Creating OVA with the following attributes:"
cat <<EOM
OVA information:
Name: ${prefix}
Size: ${vmdk_size}
Capacity: ${vmdk_capacity}
VMDK Name: ${vmdk_f##*/}
VMDK SHA256: ${vmdk_sha256}
OVF SHA256: ${ovf_sha256}
EOM
tar -C ${scratch_d} \
-cf ${cur_d}/livecd.ubuntu-cpc.ova \
${prefix}.ovf \
${prefix}.mf \
${vmdk_f##*/}