mirror of
https://github.com/outbackdingo/incus-os.git
synced 2026-01-27 10:19:24 +00:00
57 lines
1.7 KiB
Bash
Executable File
57 lines
1.7 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 "==> Getting image metadata"
|
|
JSON_RELEASE="$(curl -sL "https://api.github.com/repos/lxc/incus-os/releases/tags/${1}")"
|
|
ARTIFACTS="$(echo "${JSON_RELEASE}" | jq -r ".assets | .[].browser_download_url")"
|
|
|
|
for URL in ${ARTIFACTS}; do
|
|
FILENAME="$(echo "${URL}" | sed "s#.*/##g")"
|
|
|
|
[ "${FILENAME}" = "IncusOS_${1}.raw.gz" ] && continue
|
|
|
|
echo "==> Downloading ${FILENAME}"
|
|
curl -sL "${URL}" | gzip -d > "${TEMPDIR}/$(echo "${FILENAME}" | sed "s/.gz$//g")"
|
|
done
|
|
|
|
# Uploading the update
|
|
echo "=> Uploading the update"
|
|
|
|
incus file create "${2}/var/lib/updates/" --type=directory
|
|
incus file push --quiet "${TEMPDIR}/"* "${2}/var/lib/updates/"
|
|
incus exec "${2}" -- mv /var/lib/updates/debug.raw /var/lib/extensions/
|
|
incus exec "${2}" -- mv /var/lib/updates/incus.raw /var/lib/extensions/
|
|
|
|
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})"
|