mirror of
https://github.com/outbackdingo/incus-os.git
synced 2026-01-27 18:19:22 +00:00
51 lines
1.3 KiB
Bash
Executable File
51 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
|
|
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"
|
|
|
|
# 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
|
|
|
|
# Done
|
|
echo ""
|
|
echo "Incus OS (${1}) now running in ${2}"
|