diff --git a/live-build/ubuntu-cpc/hooks/042-vagrant.binary b/live-build/ubuntu-cpc/hooks/042-vagrant.binary new file mode 100755 index 00000000..6c185881 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/042-vagrant.binary @@ -0,0 +1,185 @@ +#!/bin/bash -eux +# vi: ts=4 noexpandtab +# +# Generate a generic Vagrant Box. +# +# Vagrant images are essentially nothing more than OVA's with extra-metadata. +# +# We can't use the OVA's for Vagrant since Vagrant uses SSH to modify the instance. +# This build step creates a cloud-config ISO so that Cloud-Init will configure +# the initial user, creates meta-data that tells Vagrant how to interact with +# the cloud-init created users, and finally create the OVA. +# +# For this step, we re-use the VMDK's made in 040-vmdk-image.binary + +cur_d=${PWD} +my_d=$(dirname $(readlink -f ${0})) + +architecture=$(chroot chroot dpkg --print-architecture) +base_vmdk="livecd.ubuntu-cpc.disk1.vmdk" +case ${architecture} in + amd64) base_vmdk="livecd.ubuntu-cpc.uefi.vmdk";; + *) echo "OVA images are not supported for ${architecture} yet."; + exit 0;; +esac + +if [ ! -e ${base_vmdk} ]; then + find . | grep vmdk + exit 0 +fi + +# Virtualbox is needed for making a small VMDK +apt-get -qqy install genisoimage qemu-utils + +# Lets be safe about this +box_d=$(mktemp -d) +seed_d=$(mktemp -d) +trap "rm -rf ${box_d} ${seed_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:]) + +# Get the VMDK in place +prefix="${distro}-${suite}-${version}-cloudimg" +vmdk_f="${box_d}/${prefix}.vmdk" +cp ${base_vmdk} ${vmdk_f} + +# Vagrant needs a base user. We either inject the well-known SSH key +# or use password authentication. Both are ugly. So we'll use a password +# and make it random. This obviously is insecure...but at least its +# better than the alternatives. +ubuntu_user_pass=$(openssl rand -hex 12) + +#################################### +# Create the ConfigDrive +# This is a cloud-init piece that instructs cloud-init to configure +# a default user at first boot. + +cdrom_vmdk_f="${box_d}/${prefix}-configdrive.vmdk" + +# Create the user-data. This is totally insecure, but so is Vagrant. To +# mitigate this insecurity, the vagrant instance is not accessible +# except via local host. +cat > ${seed_d}/user-data < ${seed_d}/meta-data < ${box_d}/Vagrantfile < ${box_d}/metadata.json < "${manifest}" <