installer/adapters/install.sh

65 lines
3.8 KiB
Bash

[[ $EUID == 0 && -e /run/archipelago-live ]] || { echo 'Installation requires the Archipelago live environment' >&2; exit 1; }
device=$(readlink -f "$1")
[[ -b $device && $(lsblk -dnro TYPE "$device") == disk ]] || { echo 'Expected a whole disk' >&2; exit 1; }
[[ $(lsblk -dnro RO "$device") == 0 ]]
if lsblk -nrpo MOUNTPOINTS "$device" | grep -q '[^[:space:]]'; then
echo 'Target disk has mounted filesystems' >&2; exit 1
fi
size=$(blockdev --getsize64 "$device")
(( size >= 12 * 1024 * 1024 * 1024 )) || { echo 'Minimum disk size is 12 GiB' >&2; exit 1; }
echo "Erasing selected disk $device ($size bytes), GPT: 2 GiB ESP, remaining ext4 root"
exec 9>/run/archipelago-install.lock
flock -n 9
if ostree --repo=/usr/share/archipelago/repo cat core /usr/lib/archipelago/purpose 2>/dev/null | grep -Eqx 'purpose/desktop/(gnome|kde)'; then
test -f /usr/share/archipelago/flatpak-seed/SHA256SUMS || { echo 'Desktop installation media lacks its application seed' >&2; exit 1; }
fi
sgdisk --zap-all "$device"
# D-103: systemd-boot reads only firmware-supported filesystems (FAT) and
# OSTree needs a POSIX /boot for loader symlinks. Keep /boot on root ext4 and
# seed the ESP with kernel/initramfs copies; the safe boot-sync maintains them.
sgdisk -n 1:0:+2G -t 1:ef00 -c 1:ARCHIPELAGO-ESP -n 2:0:0 -t 2:8300 -c 2:ARCHIPELAGO-ROOT "$device"
partprobe "$device"
udevadm settle
part1=$(lsblk -nrpo NAME,PARTN "$device" | awk '$2==1 {print $1}')
part2=$(lsblk -nrpo NAME,PARTN "$device" | awk '$2==2 {print $1}')
[[ -b $part1 && -b $part2 ]]
mkfs.fat -F32 "$part1"
mkfs.ext4 -F "$part2"
target=$(mktemp -d /mnt/archipelago.XXXXXX)
trap 'umount -R "$target" 2>/dev/null || true; rmdir "$target" 2>/dev/null || true' EXIT
mount "$part2" "$target"
ostree admin init-fs "$target"
ostree --repo="$target/ostree/repo" config set sysroot.bootloader none
ostree admin --sysroot="$target" os-init archipelago
ostree --repo="$target/ostree/repo" pull-local /usr/share/archipelago/repo core test-marker
rootuuid=$(blkid -s UUID -o value "$part2")
espuuid=$(blkid -s UUID -o value "$part1")
desktop_args=()
if ostree --repo="$target/ostree/repo" cat core /usr/lib/archipelago/desktop-boot 2>/dev/null | grep -qx plymouth; then
desktop_args+=(--karg-append=quiet --karg-append=splash --karg-append=plymouth.ignore-serial-consoles)
fi
ostree admin --sysroot="$target" deploy --os=archipelago --karg="root=UUID=$rootuuid" --karg=rw --karg-append=console=tty0 --karg-append=console=ttyS0,115200 "${desktop_args[@]}" core
deployment=$(find "$target/ostree/deploy/archipelago/deploy" -mindepth 1 -maxdepth 1 -type d -name '*.0' | head -1)
[[ -n $deployment ]]
printf 'UUID=%s / ext4 defaults 0 1\nUUID=%s /efi vfat umask=0077 0 2\n' "$rootuuid" "$espuuid" > "$deployment/etc/fstab"
install -d "$target/efi" "$deployment/efi"
mount "$part1" "$target/efi"
bootctl --esp-path="$target/efi" --no-variables install
# Seed the ESP atomically enough for first boot: artifacts first, then entries,
# and only after every referenced kernel/initrd really exists on the ESP.
cp -a "$target/boot/ostree/." "$target/efi/ostree/"
mkdir -p "$target/efi/loader/entries"
for entry in "$target/boot/loader/entries"/*.conf; do
[[ -f $entry ]] || continue
linux=$(awk '$1=="linux"{print $2}' "$entry")
initrd=$(awk '$1=="initrd"{print $2}' "$entry")
[[ -f "$target/efi$linux" && -f "$target/efi$initrd" ]] || { echo "missing installed boot artifact for ${entry##*/}" >&2; exit 1; }
done
cp -aL "$target/boot/loader/entries/." "$target/efi/loader/entries/"
printf 'timeout 3\ndefault ostree-*\n' > "$target/efi/loader/loader.conf"
if [[ -d /usr/share/archipelago/flatpak-seed ]]; then
bash /usr/share/archipelago/flatpak-import.sh /usr/share/archipelago/flatpak-seed \
"$target/ostree/deploy/archipelago/var/lib/flatpak"
fi
sync
echo 'ARCHIPELAGO_INSTALL_COMPLETE: shut down and boot this disk without the ISO'