Add installer/live/build.sh: overlay the static installer, the OpenCode manifest and the Debian tools the standard live image lacks (cryptsetup, btrfs-progs, gdisk, dosfstools, parted, util-linux-extra) onto a Debian-Live stable base, patch the boot config for a serial console, and preserve the hybrid BIOS+UEFI boot. The live squashfs is never repacked and libc is never bundled, so the appliance is unchanged and the target remains Gentoo-only. Records ADR 0005 and the implementation plan.
128 lines
5.2 KiB
Bash
Executable file
128 lines
5.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Build the Phoebus installer appliance ISO on a Debian-Live base.
|
|
#
|
|
# The live squashfs is left untouched (repacking it without root would destroy
|
|
# ownership and setuid bits). Instead the installer and the tools the live
|
|
# image lacks are overlaid as /phoebus, and the boot config is made
|
|
# serial-friendly. See README.md and docs/PLAN-DEBIAN-LIVE.md.
|
|
#
|
|
# Requirements: xorriso, curl, dpkg-deb, and a static installer build.
|
|
# No root.
|
|
set -euo pipefail
|
|
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
root="$(cd "$here/../.." && pwd)"
|
|
work="${WORKDIR:-$here/build}"
|
|
out="${OUT:-$here/phoebus-installer-amd64.iso}"
|
|
base="${BASE_ISO:-$root/debian-live-standard.iso}"
|
|
|
|
base_url="https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-13.7.0-amd64-standard.iso"
|
|
base_sha="$(awk '{print $1}' "$here/base.sha256")"
|
|
target="x86_64-unknown-linux-gnu"
|
|
release_dir="$root/installer-rs/target/$target/release"
|
|
|
|
tools=()
|
|
while IFS= read -r line; do
|
|
[[ -z "$line" || "$line" == \#* ]] && continue
|
|
tools+=("$line")
|
|
done < "$here/tools.list"
|
|
|
|
say() { printf '\n== %s ==\n' "$*"; }
|
|
|
|
say "preflight"
|
|
for c in xorriso curl dpkg-deb; do
|
|
command -v "$c" >/dev/null || { echo "missing tool: $c" >&2; exit 1; }
|
|
done
|
|
for b in phoebus-installer sys; do
|
|
[[ -x "$release_dir/$b" ]] || {
|
|
echo "missing $release_dir/$b; build it first:" >&2
|
|
echo " cd installer-rs && RUSTFLAGS=\"-C target-feature=+crt-static\" \\" >&2
|
|
echo " cargo build --release -p phoebus-installer --target $target" >&2
|
|
exit 1
|
|
}
|
|
done
|
|
|
|
say "base ISO"
|
|
if [[ ! -f "$base" ]]; then
|
|
echo "downloading $base_url"
|
|
curl -fL --retry 3 -o "$base" "$base_url"
|
|
fi
|
|
echo "$base_sha $base" | sha256sum -c - >/dev/null || { echo "base ISO checksum mismatch" >&2; exit 1; }
|
|
echo "base OK: $base"
|
|
|
|
say "fetch Debian tool packages"
|
|
apt_dir="$work/apt"
|
|
debs="$work/debs"
|
|
payload="$work/payload"
|
|
rm -rf "$work"
|
|
mkdir -p "$apt_dir"/{etc/apt/sources.list.d,var/lib/apt/lists/partial,var/cache/apt/archives/partial,var/lib/dpkg} \
|
|
"$debs" "$payload/bin" "$payload/tools"
|
|
: > "$apt_dir/var/lib/dpkg/status"
|
|
printf 'deb http://deb.debian.org/debian trixie main\n' > "$apt_dir/etc/apt/sources.list"
|
|
|
|
keyring_deb="$work/debian-archive-keyring.deb"
|
|
curl -fsS -o "$keyring_deb" \
|
|
"https://deb.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2025.1_all.deb"
|
|
dpkg-deb -x "$keyring_deb" "$work/keyring"
|
|
key="$work/keyring/usr/share/keyrings/debian-archive-keyring.gpg"
|
|
apt-get -o Dir="$apt_dir" -o Dir::Etc::trusted="$key" -o APT::Get::List-Cleanup=0 \
|
|
-o Acquire::Languages=none update >/dev/null
|
|
( cd "$debs" && apt-get -o Dir="$apt_dir" -o Dir::Etc::trusted="$key" \
|
|
-o Dir::Cache::archives="$debs" -y --no-install-recommends --download-only \
|
|
install "${tools[@]}" >/dev/null )
|
|
echo "fetched $(ls "$debs"/*.deb | wc -l) packages"
|
|
|
|
say "assemble payload"
|
|
cp "$here/payload/README" "$payload/README"
|
|
install -m 0755 "$here/payload/bin/phoebus" "$payload/bin/phoebus"
|
|
install -m 0755 "$here/payload/bin/phoebus-sys" "$payload/bin/phoebus-sys"
|
|
install -m 0755 "$release_dir/phoebus-installer" "$payload/bin/phoebus-installer"
|
|
install -m 0755 "$release_dir/sys" "$payload/bin/sys"
|
|
cp "$root/installer-rs/crates/phoebus-installer/resources/opencode.manifest" "$payload/opencode.manifest"
|
|
for d in "$debs"/*.deb; do dpkg-deb -x "$d" "$payload/tools"; done
|
|
chmod -R u+rwX "$payload/tools" 2>/dev/null || true
|
|
|
|
# Keep only libraries the live image lacks. Bundling libc would shadow the
|
|
# live system's own libc (and break its tools) via LD_LIBRARY_PATH.
|
|
libdir="$payload/tools/usr/lib/x86_64-linux-gnu"
|
|
if [[ -d "$libdir" ]]; then
|
|
( cd "$libdir" && for f in *; do
|
|
case "$f" in
|
|
libcryptsetup.so.12*|libparted.so.2*|liblzo2.so.2*|libaudit.so.1*|libreiserfscore.so.0*) : ;;
|
|
engines-3|ossl-modules) : ;;
|
|
*) rm -rf "$f" ;;
|
|
esac
|
|
done )
|
|
fi
|
|
for t in cryptsetup sgdisk partprobe mkfs.fat mkfs.btrfs btrfs; do
|
|
find "$payload/tools" -type f -name "$t" | grep -q . || { echo "payload missing $t" >&2; exit 1; }
|
|
done
|
|
echo "payload ready"
|
|
|
|
say "patch boot config for serial console"
|
|
bootcfg="$work/bootcfg"; mkdir -p "$bootcfg"
|
|
xorriso -osirrox on -indev "$base" \
|
|
-extract /boot/grub/grub.cfg "$bootcfg/grub.cfg" \
|
|
-extract /boot/grub/config.cfg "$bootcfg/config.cfg" >/dev/null 2>&1
|
|
chmod u+w "$bootcfg/grub.cfg" "$bootcfg/config.cfg"
|
|
sed -i 's#boot=live components quiet splash findiso=#boot=live components console=ttyS0,115200 findiso=#' "$bootcfg/grub.cfg"
|
|
python3 - "$bootcfg/config.cfg" <<'PY'
|
|
import sys
|
|
p = sys.argv[1]
|
|
t = open(p).read()
|
|
t = t.replace("set default=0\n",
|
|
"set default=0\nset timeout=5\nserial --unit=0 --speed=115200\n"
|
|
"terminal_input console serial\nterminal_output console serial\n", 1)
|
|
t = t.replace("terminal_output gfxterm", "terminal_output gfxterm serial")
|
|
open(p, "w").write(t)
|
|
PY
|
|
|
|
say "assemble ISO"
|
|
rm -f "$out"
|
|
xorriso -indev "$base" -outdev "$out" \
|
|
-map "$payload" /phoebus \
|
|
-map "$bootcfg/grub.cfg" /boot/grub/grub.cfg \
|
|
-map "$bootcfg/config.cfg" /boot/grub/config.cfg \
|
|
-boot_image any keep >/dev/null
|
|
sha256sum "$out" | tee "$out.sha256"
|
|
ls -lh "$out"
|