#!/bin/bash # build-release - Build and distribute the archangel ISO # # Usage: # ./scripts/build-release # Full build, sanity test, and distribute # ./scripts/build-release --full-test # Full build with comprehensive install tests # ./scripts/build-release --skip-build # Skip build, just distribute existing ISO # ./scripts/build-release --skip-test # Skip all testing # # Distribution targets: # - truenas.local:/mnt/vault/isos (if reachable) set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" # Get actual user (not root when running with sudo) if [[ -n "$SUDO_USER" ]]; then REAL_USER="$SUDO_USER" REAL_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6) else REAL_USER="$USER" REAL_HOME="$HOME" fi # Distribution targets TRUENAS_HOST="truenas.local" TRUENAS_PATH="/mnt/vault/isos" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' CYAN='\033[0;36m' NC='\033[0m' info() { echo -e "${GREEN}[INFO]${NC} $1"; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } step() { echo -e "\n${CYAN}=== $1 ===${NC}\n"; } # Parse arguments SKIP_BUILD=false SKIP_TEST=false FULL_TEST=false while [[ $# -gt 0 ]]; do case $1 in --skip-build) SKIP_BUILD=true; shift ;; --skip-test) SKIP_TEST=true; shift ;; --full-test) FULL_TEST=true; shift ;; -h|--help) echo "Usage: $0 [--skip-build] [--skip-test] [--full-test]" echo "" echo "Options:" echo " --skip-build Skip ISO build, distribute existing ISO" echo " --skip-test Skip QEMU sanity test" echo " --full-test Run comprehensive install tests (single, mirror, raidz1)" exit 0 ;; *) error "Unknown option: $1" ;; esac done # Distribution status tracking TRUENAS_SUCCESS=false # Check root for build check_root() { if [[ $EUID -ne 0 ]]; then error "This script must be run as root (for build operations)" fi } # Find the latest ISO find_iso() { ISO_FILE=$(ls -t "$PROJECT_DIR/out/"*.iso 2>/dev/null | head -1) if [[ -z "$ISO_FILE" ]]; then error "No ISO found in $PROJECT_DIR/out/" fi ISO_NAME=$(basename "$ISO_FILE") info "Found ISO: $ISO_NAME" info "Size: $(du -h "$ISO_FILE" | cut -f1)" } # Build the ISO build_iso() { step "Building ISO" cd "$PROJECT_DIR" ./build.sh find_iso } # Run sanity test in QEMU (automated) sanity_test() { step "Sanity Test (Automated)" if ! "$SCRIPT_DIR/sanity-test.sh"; then error "Sanity test failed!" exit 1 fi info "Sanity test passed!" } # Run full installation tests (automated) full_test() { step "Full Installation Tests" if ! "$SCRIPT_DIR/full-test.sh"; then error "Full installation test failed!" exit 1 fi info "All installation tests passed!" } # Distribute to TrueNAS distribute_truenas() { step "Distributing to TrueNAS" # Check if reachable if ! ping -c 1 -W 2 "$TRUENAS_HOST" &>/dev/null; then warn "TrueNAS ($TRUENAS_HOST) not reachable, skipping" return 0 fi info "TrueNAS is reachable" # Run SCP as the real user (not root) to use their SSH keys local scp_cmd="scp" if [[ -n "$SUDO_USER" ]]; then scp_cmd="sudo -u $SUDO_USER scp" fi info "Copying to $TRUENAS_HOST:$TRUENAS_PATH/" if $scp_cmd "$ISO_FILE" "cjennings@$TRUENAS_HOST:$TRUENAS_PATH/"; then info "Done: $TRUENAS_HOST:$TRUENAS_PATH/$ISO_NAME" TRUENAS_SUCCESS=true else warn "Failed to copy to TrueNAS (SSH key issue?), skipping" return 0 fi } # Summary show_summary() { step "Distribution Complete" echo "ISO: $ISO_NAME" echo "" if $TRUENAS_SUCCESS; then echo "Distributed to: $TRUENAS_HOST:$TRUENAS_PATH/" else echo "TrueNAS not reachable - ISO only in out/" fi } # Main main() { check_root if $SKIP_BUILD; then step "Skipping Build" find_iso else build_iso fi if $FULL_TEST; then full_test elif ! $SKIP_TEST; then sanity_test else step "Skipping Tests" fi distribute_truenas show_summary } main "$@"