Files
incus-os/scripts/update-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

56 lines
2.5 KiB
Bash
Executable File

#!/bin/sh -eu
if [ -z "${1:-}" ] || [ -z "${2:-}" ]; then
echo "Usage: ${0} VERSION NAME"
exit 1
fi
# Check if instance exists
if ! incus info "${2}" >/dev/null 2>&1; then
echo "Instance ${2} doesn't exist"
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}.efi.gz" | gzip -d > "${TEMPDIR}/efi"
curl -sL "https://github.com/lxc/incus-os/releases/download/${1}/IncusOS_${1}.usr-x86-64.raw.gz" | gzip -d > "${TEMPDIR}/usr-x86-64.raw"
curl -sL "https://github.com/lxc/incus-os/releases/download/${1}/IncusOS_${1}.usr-x86-64-verity.raw.gz" | gzip -d > "${TEMPDIR}/usr-x86-64-verity.raw"
curl -sL "https://github.com/lxc/incus-os/releases/download/${1}/IncusOS_${1}.usr-x86-64-verity-sig.raw.gz" | gzip -d > "${TEMPDIR}/usr-x86-64-verity-sig.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"
# Uploading the update
echo "=> Uploading the update"
incus file create "${2}/var/lib/updates/" --type=directory
incus file push --quiet "${TEMPDIR}/efi" "${2}/var/lib/updates/IncusOS_${1}.efi"
incus file push --quiet "${TEMPDIR}/usr-x86-64.raw" "${2}/var/lib/updates/IncusOS_${1}.usr-x86-64.raw"
incus file push --quiet "${TEMPDIR}/usr-x86-64-verity.raw" "${2}/var/lib/updates/IncusOS_${1}.usr-x86-64-verity.raw"
incus file push --quiet "${TEMPDIR}/usr-x86-64-verity-sig.raw" "${2}/var/lib/updates/IncusOS_${1}.usr-x86-64-verity-sig.raw"
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}" -- systemctl start boot.mount
incus exec "${2}" -- unshare -m -- sh -c "mount /dev/mapper/usr /usr && /usr/lib/systemd/systemd-sysupdate && /usr/lib/systemd/systemd-sysupdate update && /usr/lib/systemd/systemd-sysupdate && /usr/lib/systemd/systemd-sysupdate reboot"
while :; do
sleep 3
incus exec "${2}" -- /usr/bin/true >/dev/null 2>&1 && break
done
incus exec "${2}" -- systemctl daemon-reload
incus exec "${2}" -- systemctl enable --now incus-lxcfs incus-startup incus incus.socket
# Done
echo ""
echo "Instance ${2} is now running Incus OS (${1})"