Files
os-build/scripts/common.sh
Blake Ridgway 0361c12c07 fix: resolve grub-pc / grub-efi-amd64 "held broken packages" conflict
The edition package lists installed BOTH grub-pc and grub-efi-amd64
(+ shim-signed). Those provide the same bootloader role and conflict in
apt, so every rootfs build failed with "unable to correct problems, you
have held broken packages".

A rootfs now carries exactly ONE bootloader, chosen by the BOOT variable
(mirroring the existing --boot bios|efi deploy option):

- versions.mk / common.sh: BOOT := bios (bios -> grub-pc,
  efi -> grub-efi-amd64 + shim-signed + mokutil), exported via the
  Makefile.
- build-rootfs.sh validates BOOT early and injects the matching boot
  packages into the apt install; the static package lists no longer
  contain any grub package.
- deploy-disk.sh / build-image.sh / install.sh default --boot from the
  same BOOT variable, so a rootfs and the artifact deployed from it can
  never disagree (BOOT=efi make image-cloud produces a UEFI image).
- mokutil is now installed explicitly in the efi flavour (it was not
  pulled in because we install with --no-install-recommends).
- docs updated (building.md knob + rationale, secureboot.md note).
2026-08-21 14:15:10 -05:00

83 lines
4.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# Arcline OS — shared build environment + helpers
#
# Every script under scripts/ sources this first. Values mirror versions.mk;
# when invoked through the Makefile the exported variables take precedence, so
# versions.mk stays the single source of truth.
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
# ── identity ────────────────────────────────────────────────────────────────
: "${DISTRO_NAME:=Arcline OS}"
: "${DISTRO_ID:=arclineos}"
: "${VERSION:=0.1.0}"
: "${RELEASE_NAME:=arclines}"
: "${DEBIAN_SUITE:=trixie}"
: "${DEBIAN_MIRROR:=http://deb.debian.org/debian}"
: "${SECURITY_MIRROR:=http://security.debian.org/debian-security}"
: "${ARCH:=amd64}"
: "${KERNEL_PACKAGE:=linux-image-amd64}"
: "${KERNEL_VERSION:=6.12}"
# Boot flavour (mirrors versions.mk): bios → grub-pc, efi → grub-efi-amd64.
: "${BOOT:=bios}"
# Toolchain policy for image builds:
# auto (default) install the Arcline tools if build/debs/*.deb exist,
# otherwise build without them (with a warning)
# skip never install the tools, even if debs are present
# require fail the build if no toolchain debs are available
: "${ARCLINE_TOOLCHAIN:=auto}"
# ── paths (relative to the repo root) ───────────────────────────────────────
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
: "${BUILD_DIR:=$ROOT/build}"
: "${ROOTFS_DIR:=$BUILD_DIR/rootfs}"
: "${IMAGE_DIR:=$BUILD_DIR/iso}"
: "${DEB_DIR:=$BUILD_DIR/debs}"
: "${LOG_DIR:=$BUILD_DIR/logs}"
: "${ARTIFACT_DIR:=$BUILD_DIR/artifacts}"
# Valid edition names, mirroring versions.mk.
EDITIONS=(server workstation cloud)
# ── tool resolution ─────────────────────────────────────────────────────────
# Many build tools (debootstrap, sgdisk, losetup, partprobe, mkfs.vfat,
# grub-install, update-grub) live in /usr/sbin or /sbin. Non-root users and
# service accounts (CI runners, systemd timers) often omit those from PATH,
# which makes `command -v` report them as missing even though the packages are
# installed — and makes direct invocations fail. Prepend the sbin dirs so
# every script finds them regardless of who runs the build.
case ":$PATH:" in
*":/usr/local/sbin:"*|*":/usr/sbin:"*|*":/sbin:"*) ;;
*) export PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH" ;;
esac
# ── output helpers ──────────────────────────────────────────────────────────
log() { printf '\033[1;34m[arcline]\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m[arcline]\033[0m warning: %s\n' "$*" >&2; }
die() { printf '\033[1;31m[arcline]\033[0m error: %s\n' "$*" >&2; exit 1; }
# ── path helpers ────────────────────────────────────────────────────────────
edition_dir() { printf '%s/editions/%s' "$ROOT" "$1"; }
validate_edition() {
local e
for e in "${EDITIONS[@]}"; do [[ "$e" == "$1" ]] && return 0; done
die "unknown edition '$1' (expected: ${EDITIONS[*]})"
}
# ── privilege helper ────────────────────────────────────────────────────────
# Builds need root (debootstrap / chroot / mount). If we are not root and sudo
# is present, re-exec under sudo so the rest of the script can assume root.
require_root() {
if [[ $EUID -eq 0 ]]; then
return 0
elif command -v sudo >/dev/null; then
exec sudo -E "$0" "$@"
else
die "build requires root: run with sudo or as root (debootstrap + chroot need it)"
fi
}