mirror of
https://github.com/blazblue547-afk/aero3.git
synced 2026-12-02 14:24:17 -05:00
107 lines
4.0 KiB
Bash
Executable File
107 lines
4.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# build.sh — AeroOS build orchestrator.
|
|
#
|
|
# ./build.sh check host requirement check
|
|
# ./build.sh fetch download all upstream sources
|
|
# ./build.sh stage NN run a single stage (00..08)
|
|
# ./build.sh all run every stage in order
|
|
# ./build.sh run-qemu boot the produced ISO in QEMU (UEFI)
|
|
# ./build.sh clean remove build tree (keeps downloaded sources)
|
|
# ./build.sh distclean remove build tree AND sources
|
|
set -Eeuo pipefail
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
source scripts/lib/common.sh
|
|
|
|
# Stages that must run as root (chroot/mount); others run as the build user.
|
|
ROOT_STAGES="03 04 05 06 07 08"
|
|
ALL_STAGES="00 01 02 03 04 05 06 07 08"
|
|
|
|
stage_script() {
|
|
case "$1" in
|
|
00) echo scripts/00-prepare.sh ;;
|
|
01) echo scripts/01-toolchain.sh ;;
|
|
02) echo scripts/02-temp-tools.sh ;;
|
|
03) echo scripts/03-chroot-base.sh ;;
|
|
04) echo scripts/04-kernel.sh ;;
|
|
05) echo scripts/05-systemd-boot.sh ;;
|
|
06) echo scripts/06-desktop.sh ;;
|
|
07) echo scripts/07-aero-theme.sh ;;
|
|
08) echo scripts/08-image.sh ;;
|
|
*) die "unknown stage: $1 (valid: $ALL_STAGES)" ;;
|
|
esac
|
|
}
|
|
|
|
needs_root() { [[ " $ROOT_STAGES " == *" $1 "* ]]; }
|
|
|
|
run_stage() {
|
|
local n="$1" script; script="$(stage_script "$n")"
|
|
step "STAGE $n ($script)"
|
|
mkdir -p "$AEROS_LOGDIR"
|
|
local log="$AEROS_LOGDIR/stage-$n.log"
|
|
if needs_root "$n"; then
|
|
[[ $EUID -eq 0 ]] || die "stage $n needs root; re-run: sudo ./build.sh stage $n"
|
|
bash "$script" 2>&1 | tee "$log"
|
|
else
|
|
if [[ $EUID -eq 0 ]]; then
|
|
warn "stage $n should run unprivileged; dropping to \$SUDO_USER if set"
|
|
if [[ -n "${SUDO_USER:-}" ]]; then
|
|
sudo -u "$SUDO_USER" -E bash "$script" 2>&1 | tee "$log"
|
|
else
|
|
die "refusing to build toolchain as root; run as a normal user"
|
|
fi
|
|
else
|
|
bash "$script" 2>&1 | tee "$log"
|
|
fi
|
|
fi
|
|
ok "stage $n complete (log: $log)"
|
|
}
|
|
|
|
run_qemu() {
|
|
require_cmd qemu-system-x86_64
|
|
local iso; iso="$(cat "$AEROS_OUT/.last-iso" 2>/dev/null || echo "$AEROS_OUT/$AEROS_ISO_NAME")"
|
|
[[ -s "$iso" ]] || die "no ISO found; run ./build.sh all first"
|
|
local ovmf=""
|
|
for p in /usr/share/OVMF/OVMF_CODE.fd /usr/share/ovmf/OVMF.fd \
|
|
/usr/share/edk2-ovmf/x64/OVMF_CODE.fd; do
|
|
[[ -f "$p" ]] && { ovmf="$p"; break; }
|
|
done
|
|
log "booting $iso in QEMU"
|
|
local args=(-m 4096 -smp 4 -enable-kvm -cpu host
|
|
-device virtio-vga-gl -display gtk,gl=on
|
|
-device intel-hda -device hda-duplex
|
|
-cdrom "$iso" -boot d)
|
|
[[ -n "$ovmf" ]] && args+=(-drive "if=pflash,format=raw,readonly=on,file=$ovmf")
|
|
qemu-system-x86_64 "${args[@]}" || \
|
|
qemu-system-x86_64 -m 4096 -smp 4 -vga virtio -cdrom "$iso" -boot d
|
|
}
|
|
|
|
main() {
|
|
local cmd="${1:-help}"; shift || true
|
|
case "$cmd" in
|
|
check) bash scripts/00-prepare.sh check ;;
|
|
fetch) bash scripts/00-prepare.sh all ;;
|
|
stage) [[ $# -ge 1 ]] || die "usage: ./build.sh stage NN"; run_stage "$1" ;;
|
|
all) for s in $ALL_STAGES; do run_stage "$s"; done
|
|
ok "AeroOS build finished -> $AEROS_OUT/$AEROS_ISO_NAME" ;;
|
|
run-qemu) run_qemu ;;
|
|
clean) warn "removing $AEROS_ROOT and $AEROS_OUT"; rm -rf "$AEROS_ROOT" "$AEROS_OUT" "$AEROS_LOGDIR" ;;
|
|
distclean) warn "removing build tree + sources"; rm -rf "$AEROS_ROOT" "$AEROS_OUT" "$AEROS_LOGDIR" "$AEROS_SOURCES" ;;
|
|
help|*) cat <<EOF
|
|
AeroOS build system
|
|
./build.sh check # verify host has required tools
|
|
./build.sh fetch # download all upstream sources
|
|
./build.sh stage NN # run one stage (00..08)
|
|
./build.sh all # full build -> bootable ISO
|
|
./build.sh run-qemu # test the ISO in QEMU (UEFI if OVMF present)
|
|
./build.sh clean # wipe build tree (keep sources)
|
|
./build.sh distclean # wipe build tree + sources
|
|
|
|
Stages: 00 prepare · 01 toolchain · 02 temp-tools · 03 base · 04 kernel
|
|
05 systemd/boot · 06 desktop+aerowm · 07 aero theme · 08 ISO
|
|
Note: stages 03-08 need root (chroot); 00-02 run as your normal user.
|
|
EOF
|
|
;;
|
|
esac
|
|
}
|
|
main "$@"
|