Files
incus-os/scripts/spawn-image
Stéphane Graber 0d3493a2af scripts: Fix spawn-image
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2025-05-07 00:01:36 -04:00

52 lines
1.3 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
cleanup() {
rm -f .incus-os.img
}
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}.img.gz" | gzip -d > .incus-os.img
# Add seed data
echo "=> Injecting seed data"
dd status=none if=test/seed.install.tar of=.incus-os.img seek=4196352 bs=512 conv=notrunc
# Create an instance
echo "=> Creating an Incus OS instance"
incus create --vm --empty "${2}" \
-c security.secureboot=false \
-c limits.cpu=4 \
-c limits.memory=8GiB \
-d root,size=50GiB
incus config device add "${2}" vtpm tpm
incus config device add "${2}" boot-media disk source="$(pwd)/.incus-os.img" boot.priority=10
echo "=> Starting Incus OS for installation"
incus start "${2}" --console
sleep 5
incus console "${2}"
sleep 5
clear
# Remove install media
incus stop -f "${2}"
incus config device remove "${2}" boot-media
# Start the installed system
echo "=> Starting installed Incus OS"
incus start "${2}" --console