#!/bin/bash set -Eeuo pipefail if [[ $# -ne 1 ]]; then echo "Usage: $0 " exit 1 fi VM="${1}" temp_dir=$(mktemp -d) cleanup() { rm -rf "$temp_dir" } trap cleanup EXIT mkdir -p "/var/lib/libvirt/images/${VM}" cp -a "/usr/local/libvirt/images/${VM}/qcow2/disk.qcow2" "/var/lib/libvirt/images/${VM}/root.qcow2" # Inject the Flightctl configuration file (w/ enrollment certificates) into the VM image if [ -f /etc/flightctl/config.yaml ]; then yq e '.default-labels += { "type": "virtualmachine" }' /etc/flightctl/config.yaml > "$temp_dir/config.yaml" guestfish --add /var/lib/libvirt/images/${VM}/root.qcow2 -m /dev/sda4 <