46 lines
2.4 KiB
Bash
46 lines
2.4 KiB
Bash
[[ $EUID == 0 ]] || { echo 'Run as root' >&2; exit 1; }
|
|
if [[ $1 == boot-sync ]]; then
|
|
[[ ${SERVICE_RESULT:-success} == success ]] || { echo 'OSTree finalization failed; ESP unchanged' >&2; exit 1; }
|
|
[[ -e /run/ostree-booted ]]
|
|
mountpoint -q /efi
|
|
# Copy new artifacts before changing entry selection; retain old artifacts.
|
|
cp -a /sysroot/boot/ostree/. /efi/ostree/
|
|
mkdir -p /efi/loader/entries
|
|
cp -aL /sysroot/boot/loader/entries/. /efi/loader/entries/
|
|
sync -f /efi
|
|
exit 0
|
|
fi
|
|
[[ -e /run/ostree-booted ]] || { echo 'Not an installed OSTree deployment' >&2; exit 1; }
|
|
if [[ $1 == status ]]; then
|
|
ostree admin status
|
|
printf 'Experimental Core; public release gates not yet satisfied\n'
|
|
if [[ -f /usr/lib/archipelago/overlays ]]; then cat /usr/lib/archipelago/overlays; fi
|
|
exit 0
|
|
fi
|
|
[[ -f /etc/archipelago/provisioned ]] || { echo 'Complete firstboot before preparing deployments' >&2; exit 1; }
|
|
id "$(cat /etc/archipelago/provisioned)" >/dev/null
|
|
exec 9>/run/archipelago-compose.lock
|
|
flock -n 9
|
|
repo=/sysroot/ostree/repo
|
|
[[ ! -e /run/ostree/staged-deployment ]] || { echo 'Activate the pending deployment first'; exit 1; }
|
|
booted=$(ostree admin status | sed -n 's/^\* *archipelago \([0-9a-f]*\)\..*/\1/p')
|
|
[[ $booted =~ ^[a-f0-9]{64}$ ]]
|
|
work=$(mktemp -d /var/tmp/archipelago-compose.XXXXXX)
|
|
trap 'rm -rf "$work"' EXIT
|
|
ostree --repo="$repo" checkout --force-copy "$booted" "$work/root"
|
|
if [[ $1 == overlay ]]; then
|
|
[[ ! -f /usr/lib/archipelago/host-extensions ]] || { echo 'Apply managed overlay before Host Extensions in this prototype'; exit 1; }
|
|
ostree --repo="$repo" checkout --force-copy test-marker "$work/layer"
|
|
cmp "$work/layer/metadata/snapshot" "$work/root/usr/lib/archipelago/snapshot"
|
|
target=usr/share/archipelago/test-marker
|
|
[[ ! -e $work/root/$target && ! -L $work/root/$target ]]
|
|
[[ ! -L $work/root/usr/share/archipelago ]]
|
|
install -m644 "$work/layer/payload/$target" "$work/root/$target"
|
|
printf 'test-marker\n' > "$work/root/usr/lib/archipelago/overlays"
|
|
fi
|
|
ref="local/$(date +%s)-$$"
|
|
commit=$(ostree --repo="$repo" commit -b "$ref" --tree="dir=$work/root" \
|
|
--add-metadata-string="archipelago.base=$booted" \
|
|
--add-metadata-string="archipelago.snapshot=$(cat "$work/root/usr/lib/archipelago/snapshot")")
|
|
ostree admin deploy --stage --retain --os=archipelago "$commit"
|
|
echo "Prepared $commit; activate with an explicit reboot. Current /usr unchanged."
|