#!/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:=bookworm}" : "${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.1}" # 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) # ── 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 }