#!/bin/bash # Test Environment for ParticleOS Build # Verifies system is ready for safe building set -euo pipefail # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } print_header() { echo "" echo -e "${BLUE}================================${NC}" echo -e "${BLUE}$1${NC}" echo -e "${BLUE}================================${NC}" } # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BUILD_DIR="$SCRIPT_DIR/build" echo "🔍 ParticleOS Environment Test" echo "==============================" echo "Testing system readiness for safe building" echo "" # Test 1: Check if we're in a safe directory print_header "Test 1: Directory Safety" if [[ "$SCRIPT_DIR" == "/" ]] || [[ "$SCRIPT_DIR" == "/home" ]] || [[ "$SCRIPT_DIR" == "/opt" ]]; then print_error "Script is in a critical system directory: $SCRIPT_DIR" exit 1 fi print_success "Script directory is safe: $SCRIPT_DIR" # Test 2: Check disk space print_header "Test 2: Disk Space" available_space=$(df "$SCRIPT_DIR" | awk 'NR==2 {print $4}') available_gb=$((available_space / 1024 / 1024)) required_gb=10 echo "Available space: ${available_gb}GB" echo "Required space: ${required_gb}GB" if [ "$available_space" -lt $((required_gb * 1024 * 1024)) ]; then print_error "Insufficient disk space. Need at least ${required_gb}GB free" exit 1 fi print_success "Sufficient disk space available" # Test 3: Check for existing build artifacts print_header "Test 3: Existing Build Artifacts" if [ -d "$BUILD_DIR" ]; then print_warning "Existing build directory found: $BUILD_DIR" echo "This will be removed during the build process" else print_success "No existing build directory found" fi # Test 4: Check for mounted filesystems print_header "Test 4: Mounted Filesystems" if mount | grep -q "$BUILD_DIR"; then print_error "Found mounted filesystems in build directory" mount | grep "$BUILD_DIR" exit 1 fi print_success "No problematic mounts found" # Test 5: Check build prerequisites print_header "Test 5: Build Prerequisites" missing_packages=() for package in mmdebstrap squashfs-tools xorriso grub-pc-bin grub-efi-amd64-bin; do if ! dpkg -s "$package" &>/dev/null; then missing_packages+=("$package") fi done if [ ${#missing_packages[@]} -gt 0 ]; then print_warning "Missing packages: ${missing_packages[*]}" echo "These will be installed during the build process" else print_success "All required packages are installed" fi # Test 6: Check ISOLINUX print_header "Test 6: ISOLINUX" if [ ! -f "/usr/lib/ISOLINUX/isohdpfx.bin" ]; then print_warning "ISOLINUX isohdpfx.bin not found" echo "This may be installed as part of the build process" else print_success "ISOLINUX found" fi # Test 7: Check network connectivity print_header "Test 7: Network Connectivity" if ping -c 1 archive.ubuntu.com &>/dev/null; then print_success "Can reach Ubuntu archives" else print_error "Cannot reach Ubuntu archives" exit 1 fi if curl -s -I "https://git.raines.xyz/robojerk/apt-ostree/raw/branch/main/apt-ostree_0.1.0-1_amd64.deb" | head -n 1 | grep "HTTP/[12] [23].." > /dev/null; then print_success "Can reach apt-ostree repository" else print_error "Cannot reach apt-ostree repository" exit 1 fi # Test 8: Check sudo access print_header "Test 8: Sudo Access" if sudo -n true 2>/dev/null; then print_success "Sudo access confirmed" else print_warning "Sudo access may require password" echo "The build process will require sudo privileges" fi echo "" print_success "Environment test completed successfully!" echo "" echo "✅ System is ready for safe building" echo "🚀 You can now run: ./build-iso-mmdebstrap-safe.sh" echo "" echo "⚠️ Important safety notes:" echo " - The build process will use sudo" echo " - A large amount of disk space will be used" echo " - The process may take 30-60 minutes" echo " - You can safely interrupt with Ctrl+C at any time"