232 lines
9.0 KiB
Bash
Executable File
232 lines
9.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# ==============================================================================
|
|
# build.sh -- OREBOLT OS v1.4 build orchestrator
|
|
# ==============================================================================
|
|
# Phases:
|
|
# 0 host dep check (pacman)
|
|
# 1 toolchain verification (mipsel-linux-musl-*)
|
|
# 2 workspace integrity check (16 modules + headers + scripts)
|
|
# 3 overlay/ tree creation
|
|
# 4 permission fixups on init scripts
|
|
# 5 H2 Core v6.1 build (LVGL clone + liblvgl.so + h2_test + 16 modules)
|
|
# 6 OreBolt OS v1.4 build (liborebolt.a + 150-payload matrix)
|
|
# 7 artifact verification (MIPS LE ELF check, sizes)
|
|
# 8 optional --deploy to SD card
|
|
#
|
|
# v1.4 changes vs v1.3:
|
|
# * Phase 0 now also probes for the FiiO M3K kernel tree (or XBurst BSP)
|
|
# and exports KERNEL_HEADERS to all sub-makes.
|
|
# * Phase 2 module count reconciled to 16.
|
|
# * Phase 5 LVGL clone mirrors the manual fallback in PREREQUISITES §8.
|
|
# * Phase 7 now also verifies that bitchat.mod carries the AGPL_BITCHAT
|
|
# define (strings | grep -q AGPL_BITCHAT).
|
|
# ==============================================================================
|
|
set -euo pipefail
|
|
|
|
CROSS_COMPILE="${CROSS_COMPILE:-mipsel-linux-musl-}"
|
|
KERNEL_HEADERS="${KERNEL_HEADERS:-/opt/fiio-m3k-linux}"
|
|
SD_CARD_MOUNT="${SD_CARD_MOUNT:-/mnt/h2-sd}"
|
|
NO_COLOR="${NO_COLOR:-}"
|
|
|
|
# ANSI color helpers
|
|
if [ -z "$NO_COLOR" ]; then
|
|
C_RESET="\033[0m"; C_OK="\033[1;32m"; C_WARN="\033[1;33m"
|
|
C_ERR="\033[1;31m"; C_INFO="\033[1;36m"
|
|
else
|
|
C_RESET=""; C_OK=""; C_WARN=""; C_ERR=""; C_INFO=""
|
|
fi
|
|
|
|
log() { echo -e "${C_INFO}[*]${C_RESET} $*"; }
|
|
ok() { echo -e "${C_OK}[OK]${C_RESET} $*"; }
|
|
warn() { echo -e "${C_WARN}[!]${C_RESET} $*"; }
|
|
die() { echo -e "${C_ERR}[-]${C_RESET} $*"; exit 1; }
|
|
|
|
DEPLOY=0
|
|
CLEAN=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--deploy) DEPLOY=1 ;;
|
|
--deploy-only) DEPLOY=1; SKIP_BUILD=1 ;;
|
|
--clean) CLEAN=1 ;;
|
|
--help|-h)
|
|
cat <<EOF
|
|
OreBolt OS v1.4 build orchestrator
|
|
Usage: $0 [--deploy|--deploy-only|--clean|--help]
|
|
|
|
Environment:
|
|
CROSS_COMPILE Toolchain prefix (default: mipsel-linux-musl-)
|
|
KERNEL_HEADERS FiiO M3K GPL kernel tree (default: /opt/fiio-m3k-linux)
|
|
SD_CARD_MOUNT SD card mount point (default: /mnt/h2-sd)
|
|
HARDWARE_GPIO Set to 1 to compile real GPIO panic-purge path
|
|
NO_COLOR Set to 1 to disable ANSI color
|
|
EOF
|
|
exit 0 ;;
|
|
*) die "unknown arg: $arg" ;;
|
|
esac
|
|
done
|
|
|
|
# --- Phase 0: host deps ------------------------------------------------------
|
|
log "Phase 0: checking host dependencies..."
|
|
for pkg in base-devel git make python3 rsync dosfstools e2fsprogs parted file; do
|
|
if ! pacman -Qi "$pkg" >/dev/null 2>&1; then
|
|
warn "missing package: $pkg (installing...)"
|
|
sudo pacman -S --noconfirm "$pkg" || die "install failed for $pkg"
|
|
fi
|
|
done
|
|
ok "host deps satisfied"
|
|
|
|
# --- Phase 1: toolchain ------------------------------------------------------
|
|
log "Phase 1: verifying cross toolchain..."
|
|
for bin in gcc strip ar ranlib; do
|
|
if ! command -v "${CROSS_COMPILE}${bin}" >/dev/null 2>&1; then
|
|
die "missing toolchain binary: ${CROSS_COMPILE}${bin}"
|
|
fi
|
|
done
|
|
TARGET=$("${CROSS_COMPILE}gcc" -dumpmachine 2>/dev/null || true)
|
|
case "$TARGET" in
|
|
*mips*) ok "toolchain target: $TARGET" ;;
|
|
*) die "compiler target '$TARGET' does not look like MIPS" ;;
|
|
esac
|
|
|
|
# v1.4 NEW: kernel headers tree presence check
|
|
if [ ! -d "$KERNEL_HEADERS" ]; then
|
|
die "KERNEL_HEADERS not found at $KERNEL_HEADERS (see HEADERS.md)"
|
|
fi
|
|
if [ ! -f "$KERNEL_HEADERS/include/uapi/linux/kernel.h" ]; then
|
|
die "$KERNEL_HEADERS does not look like a Linux kernel tree"
|
|
fi
|
|
ok "kernel headers root: $KERNEL_HEADERS"
|
|
export KERNEL_HEADERS
|
|
|
|
# --- Phase 2: workspace integrity -------------------------------------------
|
|
log "Phase 2: verifying workspace integrity..."
|
|
for f in main.c h2_ui.h log_manager.h lv_conf.h.dist Makefile \
|
|
Makefile.h2-core-v6.1 Makefile.orebolt-v1.4 build.sh inject_payloads.sh \
|
|
PREREQUISITES.md QUICKSTART.md HEADERS.md LICENSE.md CHANGELOG.md \
|
|
ARCHITECTURE.md README.md BUILD_MANIFEST.txt SHA256SUMS; do
|
|
[ -f "$f" ] || die "missing required file: $f"
|
|
done
|
|
|
|
# v1.4: 16 modules, reconciled with PREREQUISITES §5.1
|
|
EXPECTED_MODULES=(
|
|
vault nettap deploy studio probe vterm radar ducky extract noise reset
|
|
emulate emulator_input_mapper rfid wifi glitch pwdb bitchat
|
|
)
|
|
for m in "${EXPECTED_MODULES[@]}"; do
|
|
# locate the module source -- names don't always match the dir
|
|
found=0
|
|
for path in modules/orebolt-${m}/${m}.c \
|
|
modules/orebolt-${m}/$(echo $m | sed 's/^emulator_input_mapper$/emulator_input_mapper/').c; do
|
|
if [ -f "$path" ]; then found=1; break; fi
|
|
done
|
|
[ $found -eq 1 ] || die "missing module source for: $m"
|
|
done
|
|
ok "16 modules present"
|
|
|
|
# Hardware library sources
|
|
for f in src/modules/mod_core_hid.c src/modules/mod_forensics.c \
|
|
src/modules/mod_panic_hardware_purge.c src/modules/mod_panic_purge.c \
|
|
src/modules/mod_radio_input_multiplex.c src/modules/mod_ui_frame_graphics.c \
|
|
src/modules/mod_bitchat_mesh.c src/modules/panic_purge_api.h; do
|
|
[ -f "$f" ] || die "missing: $f"
|
|
done
|
|
|
|
# Init scripts
|
|
for f in overlay/etc/init.d/S98emulator-input overlay/etc/init.d/S99broker \
|
|
overlay/etc/init.d/bt_input_daemon.sh; do
|
|
[ -f "$f" ] || die "missing: $f"
|
|
done
|
|
ok "workspace integrity OK"
|
|
|
|
if [ "$CLEAN" = "1" ]; then
|
|
log "Cleaning build artifacts..."
|
|
make clean KERNEL_HEADERS="$KERNEL_HEADERS" || true
|
|
exit 0
|
|
fi
|
|
|
|
# --- Phase 3: overlay tree ---------------------------------------------------
|
|
log "Phase 3: creating overlay/ tree..."
|
|
mkdir -p overlay/usr/lib overlay/usr/bin overlay/apps \
|
|
overlay/data/payloads/linux overlay/data/payloads/macos \
|
|
overlay/data/payloads/windows overlay/data/vault/payloads \
|
|
overlay/data/forensics_bin overlay/data/vterm/freedos/bin \
|
|
overlay/etc/init.d
|
|
ok "overlay tree ready"
|
|
|
|
# --- Phase 4: permissions ----------------------------------------------------
|
|
log "Phase 4: fixing script permissions..."
|
|
chmod +x overlay/etc/init.d/S98emulator-input overlay/etc/init.d/S99broker \
|
|
overlay/etc/init.d/bt_input_daemon.sh \
|
|
overlay/usr/bin/enable_vault_usb.sh overlay/usr/bin/enable_vault_ble.sh \
|
|
inject_payloads.sh build.sh 2>/dev/null || true
|
|
ok "permissions set"
|
|
|
|
# --- Phase 5: H2 Core v6.1 ---------------------------------------------------
|
|
log "Phase 5: building H2 Core Platform v6.1..."
|
|
|
|
# LVGL clone fallback (PREREQUISITES §8 troubleshooting path baked in)
|
|
if [ ! -d lvgl/src ]; then
|
|
log "cloning LVGL v8.3.11 + lv_drivers v8.3.0..."
|
|
git clone --depth 1 -b v8.3.11 https://github.com/lvgl/lvgl.git || \
|
|
die "LVGL clone failed (see PREREQUISITES §8 for offline fallback)"
|
|
git clone --depth 1 -b v8.3.0 https://github.com/lvgl/lv_drivers.git
|
|
[ -f lv_conf.h ] || cp lv_conf.h.dist lv_conf.h
|
|
[ -f lv_drv_conf.h ] || cp lv_drivers/lv_drv_conf_template.h lv_drv_conf.h
|
|
sed -i 's/#if 0/#if 1/' lv_drv_conf.h
|
|
sed -i 's/USE_FBDEV 0/USE_FBDEV 1/' lv_drv_conf.h
|
|
sed -i 's/USE_EVDEV 0/USE_EVDEV 1/' lv_drv_conf.h
|
|
fi
|
|
|
|
make -f Makefile.h2-core-v6.1 all KERNEL_HEADERS="$KERNEL_HEADERS"
|
|
ok "H2 Core v6.1 built"
|
|
|
|
# --- Phase 6: OreBolt OS v1.4 ---------------------------------------------------
|
|
log "Phase 6: building OreBolt OS v1.4..."
|
|
make -f Makefile.orebolt-v1.4 all \
|
|
HARDWARE_GPIO="${HARDWARE_GPIO:-0}" \
|
|
KERNEL_HEADERS="$KERNEL_HEADERS"
|
|
ok "OreBolt OS v1.4 built"
|
|
|
|
# --- Phase 7: artifact verification -----------------------------------------
|
|
log "Phase 7: verifying artifacts..."
|
|
verify_mips() {
|
|
local f=$1
|
|
[ -f "$f" ] || die "missing artifact: $f"
|
|
local info
|
|
info=$(file "$f")
|
|
case "$info" in
|
|
*MIPS*LSB*) ok "$(basename $f): MIPS LE ELF" ;;
|
|
*) die "BAD: $f -- $info" ;;
|
|
esac
|
|
}
|
|
for f in overlay/usr/bin/h2_test overlay/usr/bin/emulator_input_mapper \
|
|
overlay/usr/lib/liblvgl.so liborebolt.a; do
|
|
verify_mips "$f"
|
|
done
|
|
for m in "${EXPECTED_MODULES[@]}"; do
|
|
verify_mips "overlay/apps/${m}.mod"
|
|
done
|
|
|
|
# v1.4 NEW: bitchat AGPL marker check
|
|
if ! strings overlay/apps/bitchat.mod | grep -q "AGPL_BITCHAT"; then
|
|
die "bitchat.mod missing AGPL_BITCHAT marker (license violation)"
|
|
fi
|
|
ok "bitchat AGPL marker present"
|
|
|
|
# --- Phase 8: deploy ---------------------------------------------------------
|
|
if [ "$DEPLOY" = "1" ]; then
|
|
log "Phase 8: deploying to $SD_CARD_MOUNT..."
|
|
[ -d "$SD_CARD_MOUNT" ] || die "SD card mount point missing: $SD_CARD_MOUNT"
|
|
cp -v overlay/usr/lib/liblvgl.so "$SD_CARD_MOUNT/usr/lib/"
|
|
cp -v overlay/usr/bin/h2_test "$SD_CARD_MOUNT/usr/bin/"
|
|
cp -v overlay/usr/bin/emulator_input_mapper "$SD_CARD_MOUNT/usr/bin/"
|
|
cp -v overlay/apps/*.mod "$SD_CARD_MOUNT/apps/"
|
|
cp -rv overlay/etc/init.d/* "$SD_CARD_MOUNT/etc/init.d/" 2>/dev/null || true
|
|
cp -rv overlay/data/payloads "$SD_CARD_MOUNT/data/"
|
|
cp -v liborebolt.a "$SD_CARD_MOUNT/"
|
|
sync
|
|
ok "deployment complete"
|
|
fi
|
|
|
|
ok "OREBOLT OS v1.4 BUILD COMPLETE"
|