#!/bin/bash # SamiOS Desktop ISO build script # # Builds a desktop ISO by merging the base packages.x86_64 with the # desktop overlay (packages.x86_64.desktop) into a temporary profile, # then running mkarchiso on that profile. # # Usage: sudo bash packaging/archiso/build-desktop.sh set -euo pipefail PROFILE_DIR="$(cd "$(dirname "$0")" && pwd)" OUT_DIR="${OUT_DIR:-$PROFILE_DIR/out}" # ── Create work dir via mktemp (not caller-selected) ───────────────────── # We deliberately do NOT honor a caller-provided WORK_DIR for rm -rf # safety. A caller-selected path is vulnerable to symlink races on # shared /tmp. Instead, we create a root-owned mktemp directory. WORK_DIR="$(mktemp -d /tmp/samios-desktop-build.XXXXXX)" OUT_DIR="$(readlink -f "$OUT_DIR" 2>/dev/null || echo "$OUT_DIR")" # ── Create temp profile (BEFORE this, no side effects) ────────────────── TMP_PROFILE="$(mktemp -d /tmp/samios-desktop-profile.XXXXXX)" cleanup() { rm -rf "$TMP_PROFILE" "$WORK_DIR" } trap cleanup EXIT echo "Building SamiOS Desktop ISO..." echo "Base profile: $PROFILE_DIR" echo "Temp profile: $TMP_PROFILE" echo "Work directory: $WORK_DIR" echo "Output: $OUT_DIR" # ── Copy base profile (excluding output dir) ───────────────────────────── for item in "$PROFILE_DIR"/* "$PROFILE_DIR"/.*; do [ -e "$item" ] || continue base="$(basename "$item")" case "$base" in out|.|..) continue ;; esac cp -a "$item" "$TMP_PROFILE/" done # ── Merge package lists ───────────────────────────────────────────────── cat "$PROFILE_DIR/packages.x86_64" \ "$PROFILE_DIR/packages.x86_64.desktop" \ > "$TMP_PROFILE/packages.x86_64" # Copy VERSION into the temp profile so profiledef.sh can find it # (profiledef.sh walks up from its own directory looking for VERSION; # without this copy, it falls back to 0.0.0-unknown) # PROFILE_DIR is packaging/archiso, so VERSION is two levels up. REPO_ROOT="$(cd "$PROFILE_DIR/../.." && pwd)" if [ -f "$REPO_ROOT/VERSION" ]; then cp "$REPO_ROOT/VERSION" "$TMP_PROFILE/VERSION" fi # Verify the merged list has more packages than base alone base_pkgs=$(grep -vE '^\s*#|^\s*$' "$PROFILE_DIR/packages.x86_64" | wc -l) merged_pkgs=$(grep -vE '^\s*#|^\s*$' "$TMP_PROFILE/packages.x86_64" | wc -l) if [ "$merged_pkgs" -le "$base_pkgs" ]; then echo "ERROR: merged package list ($merged_pkgs) not larger than base ($base_pkgs)" exit 1 fi echo "Packages: $base_pkgs (base) + $((merged_pkgs - base_pkgs)) (desktop) = $merged_pkgs (total)" # ── Enable SDDM display manager in the TEMP profile only ──────────────── # This goes into the temp profile, NOT the shared base airootfs, so # base-only ISO builds are unaffected. PRESET_DIR="$TMP_PROFILE/airootfs/etc/systemd/system-preset" mkdir -p "$PRESET_DIR" echo "enable sddm.service" > "$PRESET_DIR/00-samios-desktop.preset" # Create the display-manager.service symlink (standard Arch way to # enable a display manager — sddm gets activated on boot) DM_LINK="$TMP_PROFILE/airootfs/etc/systemd/system/display-manager.service" ln -sf /usr/lib/systemd/system/sddm.service "$DM_LINK" # ── Clean previous build state and build ──────────────────────────────── rm -rf "$WORK_DIR" mkdir -p "$WORK_DIR" "$OUT_DIR" mkarchiso -v -w "$WORK_DIR" -o "$OUT_DIR" "$TMP_PROFILE" echo "" echo "Build complete!" echo "ISO location: $OUT_DIR/samios-*.iso"