builder/adapters/build-iso.sh
2026-11-21 12:20:59 +03:00

400 lines
23 KiB
Bash

# Experimental profile; all package and image operations execute in an Arch nspawn.
[[ $EUID == 0 ]] || { echo 'Build requires root for nspawn' >&2; exit 1; }
work=$(realpath -m "$1")
archive=$(realpath "$2")
binary=$(realpath "$3")
profile=${4:-core}
output_kind=${ARCHIPELAGO_BUILD_OUTPUT:-iso}
[[ $output_kind == iso || $output_kind == ostree ]] || { echo 'Invalid build output' >&2; exit 1; }
[[ $profile == core || $profile == gnome-probe || $profile == container-runner ]]
core_bind=()
if [[ $profile != core ]]; then
core_input=$(realpath "${ARCHIPELAGO_CORE_BUILD:?Purpose builds require an existing Core build artifact}")
test -d "$core_input/repo"
core_bind=(--bind-ro="$core_input:/core-input")
fi
[[ $work != / && $work != /usr && $work != /var && $work != *:* && $work != *','* ]]
mkdir -p "$work"
printf '%s\n' "$output_kind" > "$work/build-output"
exec 9>"$work/build.lock"
flock -n 9
outer="$work"
# ZFS O_TMPFILE -> linkat can wait for a transaction group for each OSTree object.
# Keep all bytes on the selected volume, using an ext4 image for staging semantics.
if [[ $(stat -f -c %T "$work") == zfs ]]; then
[[ ! -e $outer/workspace.ext4 ]] || { echo 'Use a fresh build directory' >&2; exit 1; }
truncate -s 32G "$outer/workspace.ext4"
/usr/sbin/mkfs.ext4 -q -F "$outer/workspace.ext4"
mkdir "$outer/workspace"
mount -o loop "$outer/workspace.ext4" "$outer/workspace"
trap 'umount "$outer/workspace"' EXIT
work="$outer/workspace"
fi
cache=$(realpath -m "${ARCHIPELAGO_PACKAGE_CACHE:-$outer/package-cache}")
# Generated locale archive is a pure function of glibc + locale.gen; keep it
# next to the package cache and bind it into the build container.
locale_cache=${ARCHIPELAGO_LOCALE_CACHE:-$(dirname "$cache")/locale-archive}
mkdir -p "$locale_cache"
[[ $cache != *:* && $cache != *','* ]]
mkdir -p "$cache"
printf '%s %s\n' 655bc99849b80859173fa39338a6c910185e952173f6a1a61526cfa34ab8339c "$archive" | sha256sum -c -
if [[ ! -d $work/tools/root.x86_64 ]]; then
mkdir -p "$work/extractor" "$work/tools"
tar --zstd -xpf "$archive" -C "$work/extractor"
systemd-nspawn --machine="archipelago-extract-$$" --settings=no --register=no --private-network -D "$work/extractor/root.x86_64" \
--bind-ro="$archive:/bootstrap.tar.zst" --bind="$work/tools:/output" \
bsdtar --xattrs --acls -xpf /bootstrap.tar.zst -C /output
fi
toolroot="$work/tools/root.x86_64"
mirror=${ARCHIPELAGO_MIRROR_URL:-'https://mirror.nw-sys.ru/archlinux/$repo/os/$arch'}
[[ $mirror != *$'\n'* && $mirror != *$'\r'* ]]
printf 'Server = %s\n' "$mirror" > "$toolroot/etc/pacman.d/mirrorlist"
# The container script writes the same value into the image; /job is this work dir.
printf '%s\n' "$mirror" > "$work/mirror.txt"
cat > "$work/update.json" <<'PROFILE'
@@UPDATE_PROFILE@@
PROFILE
cat > "$work/ostree.asc" <<'KEY'
@@UPDATE_PUBLIC_KEY@@
KEY
if [[ -n ${ARCHIPELAGO_UPDATE_PROFILE:-} ]]; then
[[ -n ${ARCHIPELAGO_UPDATE_PUBLIC_KEY:-} ]] || { echo 'Custom update profile requires an explicit public key'; exit 1; }
cp "$ARCHIPELAGO_UPDATE_PROFILE" "$work/update.json"
cp "$ARCHIPELAGO_UPDATE_PUBLIC_KEY" "$work/ostree.asc"
fi
if [[ -n ${ARCHIPELAGO_TOOLBOX_CONFIG:-} ]]; then cp "$ARCHIPELAGO_TOOLBOX_CONFIG" "$work/toolbox.conf"; fi
if [[ -n ${ARCHIPELAGO_SOFTWARE_PLUGIN:-} ]]; then
cp "$ARCHIPELAGO_SOFTWARE_PLUGIN" "$work/gnome-software-plugin.so"
sha256sum "$work/gnome-software-plugin.so" > "$work/software-plugin.sha256"
fi
if [[ -n ${ARCHIPELAGO_DISCOVER_PLUGIN:-} ]]; then
[[ -n ${ARCHIPELAGO_DISCOVER_VERSION:-} ]] || { echo 'Discover plugin requires the built package identity' >&2; exit 1; }
cp "$ARCHIPELAGO_DISCOVER_PLUGIN" "$work/discover-plugin.so"
sha256sum "$work/discover-plugin.so" > "$work/discover-plugin.sha256"
printf '%s\n' "$ARCHIPELAGO_DISCOVER_VERSION" > "$work/discover-version.txt"
fi
if [[ -n ${ARCHIPELAGO_FLATPAK_POLICY:-} ]]; then cp "$ARCHIPELAGO_FLATPAK_POLICY" "$work/flatpak-policy.json"; fi
if [[ -n ${ARCHIPELAGO_PLASMA_SETUP_PACKAGE:-} ]]; then
cp "$ARCHIPELAGO_PLASMA_SETUP_PACKAGE" "$work/plasma-setup.pkg.tar.zst"
sha256sum "$work/plasma-setup.pkg.tar.zst" > "$work/plasma-setup-input.sha256"
fi
cat > "$work/image-size.py" <<'ARCHIPELAGO_IMAGE_SIZE'
@@IMAGE_SIZE@@
ARCHIPELAGO_IMAGE_SIZE
chmod 0755 "$work/image-size.py"
grep -q '^DisableSandbox' "$toolroot/etc/pacman.conf" || sed -i '/\[options\]/a DisableSandbox\nNoProgressBar' "$toolroot/etc/pacman.conf"
install -m755 "$binary" "$work/archipelago"
printf '%s\n' "$profile" > "$work/build-profile"
if [[ $profile != core ]]; then
test -f "$core_input/repo/refs/heads/layers/core"
cp "$core_input/repo/refs/heads/layers/core" "$work/core-layer.commit"
cat > "$work/layer-delta.py" <<'ARCHIPELAGO_LAYER_DELTA'
@@LAYER_DELTA@@
ARCHIPELAGO_LAYER_DELTA
fi
if [[ $profile == gnome-probe ]]; then
seed=$(realpath -e "${ARCHIPELAGO_FLATPAK_SEED:?GNOME requires a prepared installation-media Flatpak seed}")
test -f "$seed/SHA256SUMS"
(cd "$seed"; sha256sum --quiet --check SHA256SUMS)
mkdir "$work/flatpak-seed"
cp -a "$seed/." "$work/flatpak-seed/"
(cd "$work/flatpak-seed"; sha256sum --quiet --check SHA256SUMS)
cat > "$work/flatpak-import.sh" <<'ARCHIPELAGO_FLATPAK_IMPORT_SCRIPT'
@@FLATPAK_IMPORT@@
ARCHIPELAGO_FLATPAK_IMPORT_SCRIPT
cat > "$work/gnome-packages.txt" <<'PACKAGES'
# GNOME_PACKAGE_LIST
PACKAGES
if [[ -n ${ARCHIPELAGO_FLATPAK_REMOTE_FILE:-} ]]; then
[[ -n ${ARCHIPELAGO_FLATPAK_POLICY:-} ]] || { echo 'Custom Flatpak remote requires a seed policy'; exit 1; }
cp "$ARCHIPELAGO_FLATPAK_REMOTE_FILE" "$work/flathub.flatpakrepo"
else
curl --fail --location --max-time 120 https://dl.flathub.org/repo/flathub.flatpakrepo -o "$work/flathub.flatpakrepo"
printf '%s %s\n' 3371dd250e61d9e1633630073fefda153cd4426f72f4afa0c3373ae2e8fea03a "$work/flathub.flatpakrepo" | sha256sum -c -
fi
fi
if [[ $profile == container-runner ]]; then
cat > "$work/container-runner-packages.txt" <<'PACKAGES'
# CONTAINER_RUNNER_PACKAGE_LIST
PACKAGES
fi
cat > "$work/build-in-container.sh" <<'BUILD'
set -euxo pipefail
export LC_ALL=C
export ARCHIPELAGO_BUILD_PROFILE=$(cat /job/build-profile)
# The image keeps the repository it was composed from: either the public rolling
# mirror or the immutable snapshot bound to this build. An internal build
# transport must never leak in, and a snapshot build must not silently fall back
# to the rolling mirror - that is what broke updates on deployed hosts when the
# mirror pruned a pinned package. Purpose builds skip the Core-tree block below,
# so the value is read once here for every profile.
mirror=$(cat /job/mirror.txt)
case $mirror in
'https://mirror.nw-sys.ru/archlinux'*|'https://mirror.nw-sys.ru/archipelago/arch-repo-snapshot/'*) ;;
*) echo "Installed-system repository must be mirror.nw-sys.ru, got: $mirror" >&2; exit 1 ;;
esac
if [[ ! -f /etc/pacman.d/gnupg/trustdb.gpg ]]; then
pacman-key --init
pacman-key --populate archlinux
fi
# Capture multilib in the same repository universe as Core, even though only
# Desktop enables it in the installed package-manager configuration.
if ! pacman-conf --repo-list | grep -qx multilib; then
printf '\n[multilib]\nInclude = /etc/pacman.d/mirrorlist\n' >> /etc/pacman.conf
fi
# Include the Archipelago runtime dependencies checked by makepkg below.
pacman -Syu --noconfirm --needed archiso ostree openssh sudo gptfdisk parted nano diffutils fakeroot file pyalpm polkit
printf 'ARCHIPELAGO_PHASE\tcore\n'
[[ ! -e /job/core && ! -e /job/iso-work ]] || { echo 'Use a fresh work directory for a new build'; exit 1; }
mkdir -p /job/core /job/evidence /job/output
cat > /job/package.sh <<'PACKAGE'
@@PACKAGE_SCRIPT@@
PACKAGE
if [[ $ARCHIPELAGO_BUILD_PROFILE == container-runner ]]; then
@@CONTAINER_RUNNER_LAYER_BUILD@@
elif [[ $ARCHIPELAGO_BUILD_PROFILE == gnome-probe ]]; then
@@GNOME_LAYER_BUILD@@
else
bash /job/package.sh
mkdir -p /job/core/etc/pacman.d/hooks
# Defer the kernel's generated initramfs to the explicit complete-Core finalizer.
ln -s /dev/null /job/core/etc/pacman.d/hooks/90-mkinitcpio-install.hook
cp /var/lib/pacman/sync/*.db /job/evidence/
sha256sum /job/evidence/*.db > /job/evidence/databases.sha256
snapshot=$(sha256sum /job/evidence/databases.sha256 | cut -d' ' -f1)
cp /etc/pacman.conf /job/core-pacman.conf
sed -i '/\[options\]/a HookDir = /job/core/etc/pacman.d/hooks' /job/core-pacman.conf
# Same-version local packages can have different per-run lab signatures.
# Prefer this run's exact archive/signature pair over the shared upstream cache.
sed -i '/\[options\]/a CacheDir = /job/private-package-cache\nCacheDir = /var/cache/pacman/pkg' /job/core-pacman.conf
pacstrap -C /job/core-pacman.conf -c -G -M /job/core base linux linux-firmware linux-firmware-amd linux-firmware-amdgpu linux-firmware-atheros linux-firmware-broadcom linux-firmware-cirrus linux-firmware-intel linux-firmware-liquidio linux-firmware-marvell linux-firmware-mediatek linux-firmware-mellanox linux-firmware-nfp linux-firmware-nvidia linux-firmware-other linux-firmware-qcom linux-firmware-qlogic linux-firmware-radeon linux-firmware-realtek linux-firmware-ti linux-firmware-whence x11-ssh-askpass usb_modeswitch archipelago kmscon terminus-font podman toolbox 2>&1 | tee /job/evidence/core-transaction.log
if grep -Ei 'error:|==> ERROR:' /job/evidence/core-transaction.log; then
echo 'Required Core transaction action failed' >&2; exit 1
fi
# D-076/D-118: Core ships Toolbx and rootless Podman, so Core-only hosts,
# Container Runner and every Desktop Purpose can create an Arch Toolbx container.
# The default is the upstream Arch image, never Fedora; users keep their own
# ~/.config/containers/toolbox.conf overrides. Desktop finalizers install the same
# content from the Purpose payload.
mkdir -p /job/core/etc/containers/registries.conf.d
cat > /job/core/etc/containers/toolbox.conf <<'TOOLBOX'
@@TOOLBOX_CONFIG@@
TOOLBOX
cat > /job/core/etc/containers/registries.conf.d/60-archipelago-toolbox.conf <<'TOOLBOX_REGISTRIES'
@@TOOLBOX_REGISTRIES@@
TOOLBOX_REGISTRIES
for db in /job/evidence/*.db; do cmp "$db" "/job/core/var/lib/pacman/sync/$(basename "$db")"; done
sha256sum /var/cache/pacman/pkg/*.pkg.tar.zst > /job/evidence/package-archives.sha256
sha256sum /job/private-package-cache/*.pkg.tar.zst > /job/evidence/private-cache-archives.sha256
cp /etc/pacman.d/mirrorlist /job/core/etc/pacman.d/mirrorlist
awk '/^\[/ { skip = ($0 == "[multilib]") } !skip { print }' /etc/pacman.conf > /job/core/etc/pacman.conf
mkdir -p /job/core/etc/pacman.d/archipelago-repos
printf '# Additional repositories are supplied by the selected Purpose.\n' > /job/core/etc/pacman.d/archipelago-repos/base.conf
printf '\nInclude = /etc/pacman.d/archipelago-repos/*.conf\n' >> /job/core/etc/pacman.conf
sed -i 's/^LocalFileSigLevel.*/LocalFileSigLevel = Required/' /job/core/etc/pacman.conf
mkdir -p /job/core/usr/lib/archipelago /job/core/usr/lib/ostree /job/core/usr/share/archipelago/packages
printf '%s\n' "$snapshot" > /job/core/usr/lib/archipelago/snapshot
# Machine defaults are instantiated from the package, separate from package files.
rm -f /job/core/etc/os-release
cp /job/core/usr/lib/archipelago/defaults/os-release /job/core/etc/os-release
printf 'archipelago\n' > /job/core/etc/hostname
cp /job/core/usr/lib/archipelago/defaults/{locale.conf,vconsole.conf} /job/core/etc/
ln -sfn /usr/share/zoneinfo/UTC /job/core/etc/localtime
mkdir -p /job/core/etc/systemd/network
cp /job/core/usr/lib/archipelago/defaults/20-wired.network /job/core/etc/systemd/network/
ln -sfn /run/systemd/resolve/stub-resolv.conf /job/core/etc/resolv.conf
systemctl --root=/job/core disable archipelago-firstboot@tty1
systemctl --root=/job/core enable systemd-networkd systemd-resolved systemd-timesyncd sshd archipelago-ssh-keys archipelago-keyring getty@tty1 ostree-remount
# Core and Container Runner use the plain kernel console: vconsole.conf already
# selects Terminus, and kmscon cannot start without mesa (every render engine
# needs libEGL/libgbm/libGLESv2, which the Arch package does not depend on). The
# packaged getty@tty1 drop-in runs the same onboarding wrapper as kmscon did.
# Desktop purposes ship mesa; their finalizers add kmscon for logind VTs (D-109).
# Generate every locale supplied by glibc, including non-UTF-8 variants. This
# shared Core output is inherited by every Purpose; never borrow host locales.
sed -i -E 's/^#[[:space:]]*([a-z][a-z][a-z]?_[A-Z][A-Z][^[:space:]]*[[:space:]]+[^[:space:]#]+)[[:space:]]*$/\1/' /job/core/etc/locale.gen
# localedef is the most expensive step of Core (882 locales, ~28 min on the lab
# worker). The archive is a pure function of the glibc version and locale.gen, so
# cache it across builds; any change to either invalidates the key.
locale_key=$( { arch-chroot /job/core pacman -Q glibc; sha256sum /job/core/etc/locale.gen; } |
sha256sum | cut -d' ' -f1 )
if [[ -f /archipelago-locale-cache/$locale_key ]]; then
install -Dm0644 "/archipelago-locale-cache/$locale_key" /job/core/usr/lib/locale/locale-archive
printf 'reused cached locale archive %s\n' "$locale_key" > /job/evidence/locales.log
else
arch-chroot /job/core locale-gen > /job/evidence/locales.log 2>&1
install -Dm0644 /job/core/usr/lib/locale/locale-archive "/archipelago-locale-cache/$locale_key"
fi
arch-chroot /job/core locale -a > /job/evidence/locales.txt
# Retain package hook inventory and source scripts for review, before any commit.
cp -a /job/core/usr/share/libalpm/hooks /job/evidence/hooks
find /job/core/var/lib/pacman/local -name install -exec cp --parents '{}' /job/evidence/ \;
mkdir -p /job/core/usr/lib/archipelago/hook-policy
(cd /job/core; sha256sum usr/share/libalpm/hooks/*.hook) > /job/core/usr/lib/archipelago/hook-policy/hooks.sha256
find /job/core/var/lib/pacman/local -name install -exec sha256sum '{}' + > /job/core/usr/lib/archipelago/hook-policy/scriptlets.sha256
arch-chroot /job/core /bin/bash -euxc 'archipelago self-check; k=$(basename /usr/lib/modules/*); depmod "$k"; config=/usr/lib/archipelago/mkinitcpio-core.conf; if [[ -f /usr/lib/archipelago/mkinitcpio-gnome.conf ]]; then config=/usr/lib/archipelago/mkinitcpio-gnome.conf; fi; mkinitcpio -c "$config" -k "$k" -g "/usr/lib/modules/$k/initramfs.img"; ldconfig; systemd-hwdb update --usr'
pacman --sysroot /job/core -Q > /job/evidence/core-packages.txt
cp /job/evidence/core-packages.txt /job/core/usr/lib/archipelago/packages.txt
cp /var/cache/pacman/pkg/nano-*.pkg.tar.zst /job/core/usr/share/archipelago/packages/
cp /var/cache/pacman/pkg/nano-*.pkg.tar.zst.sig /job/core/usr/share/archipelago/packages/
sha256sum /job/core/usr/share/archipelago/packages/*.pkg.tar.zst > /job/evidence/extension.sha256
cd /job/core/usr/share/archipelago/packages
sha256sum *.pkg.tar.zst *.pkg.tar.zst.sig > SHA256SUMS
cd /
# Image DB has normal ALPM records. Account files originate from filesystem defaults;
# sysusers reconciles service accounts on target boot.
mv /job/core/var/lib/pacman /job/core/usr/lib/archipelago/package-db
sed -i '/\[options\]/a DBPath = /usr/lib/archipelago/package-db/' /job/core/etc/pacman.conf
rm -f /job/core/etc/machine-id /job/core/var/lib/dbus/machine-id
touch /job/core/etc/machine-id
# Discard accounts allocated by build-time sysusers. Boot reconciles declarations
# over the filesystem package's factory defaults; do not ship a staging identity DB.
for database in passwd shadow group gshadow; do
cp -a "/job/core/usr/share/factory/etc/$database" "/job/core/etc/$database"
done
rm -rf /job/core/etc/pacman.d/gnupg
rm -f /job/core/etc/ssh/ssh_host_* /job/core/etc/.pwd.lock
printf 'Server = %s\n' "$mirror" > /job/core/etc/pacman.d/mirrorlist
mv /job/core/etc /job/core/usr/etc
rm -rf /job/core/var /job/core/home /job/core/root /job/core/srv /job/core/opt /job/core/mnt /job/core/usr/local /job/core/boot/*
mkdir -p /job/core/var /job/core/sysroot /job/core/efi
ln -s sysroot/ostree /job/core/ostree
for pair in home:home root:roothome srv:srv opt:opt mnt:mnt; do
ln -s "var/${pair#*:}" "/job/core/${pair%:*}"
done
ln -s ../var/usrlocal /job/core/usr/local
mkdir -p /job/layer/metadata
mv /job/core /job/layer/payload
cp /job/evidence/core-packages.txt /job/layer/metadata/packages.txt
cp -a /job/layer/payload/usr/lib/archipelago/package-db/local /job/layer/metadata/package-index
cat > /job/layer/metadata/transformations.txt <<'EOF'
Experimental Core profile: package /etc defaults stored at /usr/etc; authoritative
ALPM DB moved to /usr/lib/archipelago/package-db; persistence symlinks and runtime
tmpfiles follow D-030. mkinitcpio/ldconfig/hwdb outputs generated for this Core-only
composition. archipelago binary and units are distribution additions. Package DB
files retain runtime paths; metadata and installed-file validation are distinct.
EOF
printf '%s\n' "$snapshot" > /job/layer/metadata/snapshot
ostree --repo=/job/repo init --mode=archive
layercommit=$(ostree --repo=/job/repo commit --fsync=0 -b layers/core --tree=dir=/job/layer --add-metadata-string=archipelago.snapshot="$snapshot")
ostree --repo=/job/repo checkout --force-copy --subpath=payload "$layercommit" /job/composed
# Clients only receive commit metadata before they decide to update. Measure the
# composed tree once, then record both sizes in the published commit so the
# software centers can show them without downloading the image.
image=$(ostree --repo=/job/repo commit --fsync=0 --orphan --tree=dir=/job/composed)
read -r image_transfer image_installed < <(python3 /job/image-size.py /job/repo "$image")
[[ $image_transfer =~ ^[0-9]+$ && $image_installed =~ ^[0-9]+$ ]]
ostree --repo=/job/repo commit --fsync=0 -b core --tree=dir=/job/composed --add-metadata-string=archipelago.snapshot="$snapshot" --add-metadata-string=archipelago.layer-core="$layercommit" --add-metadata-string=archipelago.image-size="$image_transfer" --add-metadata-string=archipelago.image-installed-size="$image_installed"
mkdir -p /job/overlay/payload/usr/share/archipelago /job/overlay/metadata
printf 'Archipelago managed overlay test\n' > /job/overlay/payload/usr/share/archipelago/test-marker
printf '%s\n' "$snapshot" > /job/overlay/metadata/snapshot
ostree --repo=/job/repo commit --fsync=0 -b test-marker --tree=dir=/job/overlay --add-metadata-string=archipelago.snapshot="$snapshot"
fi
# Minimal UEFI archiso profile based on packaged releng boot integration.
if [[ $(cat /job/build-output) == ostree ]]; then
cp -a /job/package-repo /job/output/packages
printf 'OSTree image and layers ready; ISO packaging not requested\n'
exit 0
fi
cp -a /usr/share/archiso/configs/releng /job/profile
cat > /job/profile/profiledef.sh <<'EOF'
iso_name="archipelago-core"
iso_label="ARCHIPELAGO"
iso_publisher="Archipelago experimental lab"
iso_application="Archipelago Core Installer"
iso_version="latest"
install_dir="arch"
bootmodes=('uefi.systemd-boot')
pacman_conf="pacman.conf"
airootfs_image_type="squashfs"
airootfs_image_tool_options=('-comp' 'zstd' '-Xcompression-level' '3' '-processors' "$(nproc)")
kernel_params_x86_64="console=tty0 console=ttyS0,115200"
file_permissions=(["/etc/shadow"]="0:0:400" ["/root"]="0:0:750")
EOF
rm -rf /job/profile/airootfs
if [[ $ARCHIPELAGO_BUILD_PROFILE == gnome-probe ]]; then
sed -i 's/iso_name="archipelago-core"/iso_name="archipelago-gnome-probe"/; s/Archipelago experimental lab/Archipelago private GNOME integration probe/' /job/profile/profiledef.sh
elif [[ $ARCHIPELAGO_BUILD_PROFILE == container-runner ]]; then
sed -i 's/iso_name="archipelago-core"/iso_name="archipelago-container-runner"/; s/Archipelago experimental lab/Archipelago Container Runner/' /job/profile/profiledef.sh
fi
mkdir -p /job/profile/airootfs/etc/mkinitcpio.conf.d /job/profile/airootfs/root
mkdir -p /job/profile/airootfs/etc/pacman.d
printf 'Server = %s\n' "$mirror" > /job/profile/airootfs/etc/pacman.d/mirrorlist
cat > /job/profile/airootfs/etc/mkinitcpio.conf.d/archiso.conf <<'EOF'
HOOKS=(base udev modconf archiso archiso_loop_mnt block filesystems keyboard)
COMPRESSION="zstd"
COMPRESSION_OPTIONS=(-T1 -3)
EOF
printf 'root::14871::::::\n' > /job/profile/airootfs/etc/shadow
printf 'archipelago-live\n' > /job/profile/airootfs/etc/hostname
printf 'LANG=C.UTF-8\n' > /job/profile/airootfs/etc/locale.conf
printf 'KEYMAP=us\nFONT=ter-v24b\n' > /job/profile/airootfs/etc/vconsole.conf
# Live console: plain kernel console with Terminus (vconsole.conf above) and a
# getty on tty1. kmscon is deliberately not enabled: the live image ships no
# mesa, so it has no render engine and would leave tty1 blank.
mkdir -p /job/profile/airootfs/etc/systemd/system/getty.target.wants
ln -sfn /usr/lib/systemd/system/getty@.service /job/profile/airootfs/etc/systemd/system/getty.target.wants/getty@tty1.service
ln -s /usr/share/zoneinfo/UTC /job/profile/airootfs/etc/localtime
mkdir -p /job/profile/airootfs/etc/systemd/system
cat > /job/profile/packages.x86_64 <<'EOF'
base
linux
linux-firmware
archipelago
archiso
mkinitcpio
mkinitcpio-archiso
ostree
arch-install-scripts
dosfstools
e2fsprogs
gptfdisk
parted
sudo
openssh
terminus-font
EOF
cp /etc/pacman.conf /job/profile/pacman.conf
sed -i '/\[options\]/a CacheDir = /job/private-package-cache\nCacheDir = /var/cache/pacman/pkg' /job/profile/pacman.conf
mkdir -p /job/profile/airootfs/usr/share/archipelago
cp -a /job/repo /job/profile/airootfs/usr/share/archipelago/repo
if [[ $ARCHIPELAGO_BUILD_PROFILE == gnome-probe ]]; then
printf 'flatpak\npython\n' >> /job/profile/packages.x86_64
cp -a /job/flatpak-seed /job/profile/airootfs/usr/share/archipelago/flatpak-seed
cp /job/flatpak-import.sh /job/profile/airootfs/usr/share/archipelago/flatpak-import.sh
sha256sum /job/flatpak-seed/SHA256SUMS > /job/evidence/flatpak-seed.sha256
fi
mkdir -p /job/profile/airootfs/etc/tmpfiles.d
printf 'f /run/archipelago-live 0644 root root -\n' > /job/profile/airootfs/etc/tmpfiles.d/archipelago-live.conf
printf '\nArchipelago Core experimental installer\nRun: archipelago install /dev/vda --erase\n' > /job/profile/airootfs/etc/issue
mkdir -p /job/profile/airootfs/etc/systemd/system/serial-getty@ttyS0.service.d
cat > /job/profile/airootfs/etc/systemd/system/serial-getty@ttyS0.service.d/autologin.conf <<'EOF'
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear %I 115200 linux
EOF
printf 'ARCHIPELAGO_PHASE\tiso\n'
mkarchiso -v -w /job/iso-work -o /job/output /job/profile 2>&1 | tee /job/evidence/iso-build.log
if grep -Ei 'error:|==> ERROR:' /job/evidence/iso-build.log; then
echo 'Required live-image action failed; ISO candidate rejected' >&2; exit 1
fi
[[ -x /job/iso-work/x86_64/airootfs/usr/bin/archipelago ]]
arch-chroot /job/iso-work/x86_64/airootfs /usr/bin/archipelago self-check
cp -a /job/package-repo /job/output/packages
iso=$(find /job/output -maxdepth 1 -name '*.iso' -print -quit)
[[ -n $iso ]]
output_name=archipelago-core-latest.iso
if [[ $ARCHIPELAGO_BUILD_PROFILE == gnome-probe ]]; then output_name=archipelago-gnome-probe.iso; fi
if [[ $ARCHIPELAGO_BUILD_PROFILE == container-runner ]]; then output_name=archipelago-container-runner.iso; fi
if [[ $iso != /job/output/$output_name ]]; then mv "$iso" "/job/output/$output_name"; fi
cd /job/output
sha256sum "$output_name" > SHA256SUMS
BUILD
systemd-nspawn --machine="archipelago-build-$$" --settings=no --register=no --resolv-conf=replace-host --capability=CAP_SYS_ADMIN,CAP_MKNOD \
-D "$toolroot" --bind="$work:/job" --bind="$cache:/var/cache/pacman/pkg" \
--bind="$locale_cache:/archipelago-locale-cache" "${core_bind[@]}" /usr/bin/bash /job/build-in-container.sh 2>&1 | tee "$outer/build.log"
if [[ $outer != "$work" ]]; then
cp -a "$work/output" "$outer/output"
cp -a "$work/evidence" "$outer/evidence"
fi
echo "ISO output ($profile): $outer/output/"