#!/bin/bash # ============================================================================ # DarkForge Linux — Phase 0, Chapter 7: Run All Chroot Build Scripts # ============================================================================ # Purpose: Enters the chroot and runs scripts 024-031 in sequence. # This is a convenience wrapper — run it on the HOST as root, # AFTER 023-chroot-setup.sh has mounted virtual filesystems. # Usage: sudo bash /mnt/darkforge/sources/toolchain-scripts/023a-chroot-build-all.sh # Inputs: LFS environment variable (default: /mnt/darkforge) # Outputs: Completed chroot tools (gettext, bison, perl, python, texinfo, util-linux) # Assumes: 023-chroot-setup.sh already ran, virtual filesystems mounted # ============================================================================ set -euo pipefail LFS="${LFS:-/mnt/darkforge}" SCRIPTS="/sources/toolchain-scripts" # Color output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' ok() { echo -e "${GREEN}>>> $*${NC}"; } warn() { echo -e "${YELLOW}>>> $*${NC}"; } fail() { echo -e "${RED}>>> $*${NC}"; exit 1; } [ "$(id -u)" -eq 0 ] || fail "This script must be run as root." # Verify chroot is ready (virtual filesystems mounted) if ! mountpoint -q "${LFS}/proc" 2>/dev/null; then fail "${LFS}/proc is not mounted. Run 023-chroot-setup.sh first." fi echo "============================================================" echo " DarkForge Linux — Chroot Build Phase (Chapter 7)" echo "============================================================" echo "" # Build a script that runs inside the chroot # We write it to a temp file inside $LFS so the chroot can see it cat > "${LFS}/tmp/chroot-build-runner.sh" << 'CHROOT_EOF' #!/bin/bash set -euo pipefail SCRIPTS="/sources/toolchain-scripts" LOG_DIR="/sources/logs" mkdir -p "${LOG_DIR}" RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' run_script() { local script="$1" local name name=$(basename "${script}" .sh) local logfile="${LOG_DIR}/${name}.log" echo -e "${YELLOW}>>> [$(date '+%H:%M:%S')] Starting: ${name}${NC}" if bash "${script}" 2>&1 | tee "${logfile}"; then echo -e "${GREEN}>>> [$(date '+%H:%M:%S')] PASSED: ${name}${NC}" echo "" else echo -e "${RED}>>> [$(date '+%H:%M:%S')] FAILED: ${name}${NC}" echo "Log file: ${logfile}" exit 1 fi } echo "=== Chapter 7: Chroot Build Scripts ===" echo "" run_script "${SCRIPTS}/024-chroot-essentials.sh" run_script "${SCRIPTS}/025-gettext.sh" run_script "${SCRIPTS}/026-bison.sh" run_script "${SCRIPTS}/027-perl.sh" run_script "${SCRIPTS}/028-python.sh" run_script "${SCRIPTS}/029-texinfo.sh" run_script "${SCRIPTS}/030-util-linux.sh" run_script "${SCRIPTS}/031-cleanup.sh" echo "" echo "============================================================" echo " Chapter 7 chroot builds complete!" echo "============================================================" CHROOT_EOF chmod +x "${LFS}/tmp/chroot-build-runner.sh" # Enter chroot and run the build script # PATH includes /tools/bin where the cross-compiled gcc lives chroot "${LFS}" /usr/bin/env -i \ HOME=/root \ TERM="${TERM}" \ PS1='(darkforge chroot) \u:\w\$ ' \ PATH=/usr/bin:/usr/sbin:/tools/bin \ MAKEFLAGS="-j32" \ /bin/bash /tmp/chroot-build-runner.sh # Clean up rm -f "${LFS}/tmp/chroot-build-runner.sh" echo "" echo -e "${GREEN}Phase 0 is FULLY COMPLETE.${NC}" echo "" echo "The toolchain chroot environment is ready." echo "Next: Phase 1 (dpack) or Phase 3 (base system packages)."