Files
incus-os/scripts/spawn-image
Stéphane Graber 8cf96c93e3 scripts: Add scripts to consume the Github builds
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2024-12-06 22:19:16 -05:00

65 lines
2.1 KiB
Bash
Executable File

#!/bin/sh -eu
if [ -z "${1:-}" ] || [ -z "${2:-}" ]; then
echo "Usage: ${0} VERSION NAME"
exit 1
fi
# Check if instance already exists
if incus info "${2}" >/dev/null 2>&1; then
echo "Instance ${2} already exists"
exit 1
fi
# Setup temporary directory
TEMPDIR=$(mktemp -d)
cleanup() {
rm -Rf "${TEMPDIR}"
}
trap cleanup EXIT HUP INT TERM
# Grab the image
echo "=> Downloading the image"
echo "==> Downloading Incus OS ${1}"
curl -sL "https://github.com/lxc/incus-os/releases/download/${1}/IncusOS_${1}.raw.gz" | gzip -d > "${TEMPDIR}/root.raw"
echo "==> Downloading debug package"
curl -sL "https://github.com/lxc/incus-os/releases/download/${1}/debug.raw.gz" | gzip -d > "${TEMPDIR}/debug.raw"
echo "==> Downloading incus package"
curl -sL "https://github.com/lxc/incus-os/releases/download/${1}/incus.raw.gz" | gzip -d > "${TEMPDIR}/incus.raw"
# Prepare the Incus image
echo "=> Importing into Incus"
qemu-img convert -f raw -O qcow2 "${TEMPDIR}/root.raw" "${TEMPDIR}/root.qcow2"
incus image import --alias "incus-os-${1}" test/metadata.tar.xz "${TEMPDIR}/root.qcow2"
# Create an instance
echo "=> Creating an Incus OS instance"
incus create --vm "incus-os-${1}" "${2}" \
-c security.secureboot=false \
-c limits.cpu=2 \
-c limits.memory=2GiB \
-d root,size=50GiB
incus image delete "incus-os-${1}"
incus config device add "${2}" vtpm tpm
incus start "${2}"
# Waiting for instance to be ready
echo "=> Waiting for instance to boot"
while :; do
sleep 3
incus exec "${2}" -- /usr/bin/true >/dev/null 2>&1 && break
done
# Load the extensions
echo "=> Loading the packages"
incus exec "${2}" -- mkdir -p /var/lib/extensions
incus file push --quiet "${TEMPDIR}/debug.raw" "${2}/var/lib/extensions/debug.raw"
incus file push --quiet "${TEMPDIR}/incus.raw" "${2}/var/lib/extensions/incus.raw"
incus exec "${2}" -- systemd-sysext list
incus exec "${2}" -- systemd-sysext merge
incus exec "${2}" -- systemd-sysusers
incus exec "${2}" -- systemctl enable --now incus-lxcfs incus-startup incus incus.socket
# Done
echo ""
echo "Incus OS (${1}) now running in ${2}"