#!/bin/bash # Test Podman Environment for ParticleOS Build # Verifies system is ready for safe containerized 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 Podman Environment Test" echo "=====================================" echo "Testing system readiness for safe containerized 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=15 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 Podman availability print_header "Test 4: Podman Availability" if ! command -v podman &> /dev/null; then print_error "Podman is not installed" echo "Please install Podman: sudo apt update && sudo apt install -y podman" exit 1 fi print_success "Podman is installed" # Test 5: Check Podman permissions print_header "Test 5: Podman Permissions" if podman info &> /dev/null; then PODMAN_CMD="podman" print_success "Podman can run without sudo" else PODMAN_CMD="sudo podman" print_warning "Podman requires sudo (this is normal)" fi echo "Podman command: $PODMAN_CMD" # Test 6: Test Podman functionality print_header "Test 6: Podman Functionality" if $PODMAN_CMD version &> /dev/null; then print_success "Podman is working correctly" else print_error "Podman is not working correctly" exit 1 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 for existing containers/images print_header "Test 8: Existing Containers/Images" if $PODMAN_CMD container exists particleos-builder 2>/dev/null; then print_warning "Existing container 'particleos-builder' found" echo "This will be removed during the build process" else print_success "No existing particleos-builder container found" fi if $PODMAN_CMD image exists particleos-builder:latest 2>/dev/null; then print_warning "Existing image 'particleos-builder:latest' found" echo "This will be removed during the build process" else print_success "No existing particleos-builder image found" fi # Test 9: Test container creation print_header "Test 9: Container Creation Test" if $PODMAN_CMD run --rm --name test-container ubuntu:22.04 echo "test" &> /dev/null; then print_success "Container creation test passed" else print_error "Container creation test failed" exit 1 fi # Test 10: Check volume mounting print_header "Test 10: Volume Mounting Test" TEST_DIR="/tmp/particleos-test-$$" mkdir -p "$TEST_DIR" echo "test" > "$TEST_DIR/test.txt" if $PODMAN_CMD run --rm -v "$TEST_DIR:/test:Z" ubuntu:22.04 cat /test/test.txt 2>/dev/null | grep -q "test"; then print_success "Volume mounting test passed" else print_error "Volume mounting test failed" rm -rf "$TEST_DIR" exit 1 fi rm -rf "$TEST_DIR" echo "" print_success "Podman environment test completed successfully!" echo "" echo "✅ System is ready for safe containerized building" echo "🚀 You can now run: ./build-iso-podman.sh" echo "" echo "🛡️ Safety features of this approach:" echo " - Complete isolation from host system" echo " - No sudo chroot commands on host" echo " - No filesystem mounting on host" echo " - Container is automatically cleaned up" echo " - Host system cannot be affected" echo "" echo "⚠️ Important notes:" echo " - The build process will use Podman" echo " - A large amount of disk space will be used (15GB+)" echo " - The process may take 30-60 minutes" echo " - You can safely interrupt with Ctrl+C at any time" echo " - The container will be automatically cleaned up"