#!/bin/bash # Particle-OS Basic Testing (No sudo required) # Tests basic functionality without requiring root privileges set -euo pipefail # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Logging functions log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # Test results tracking TESTS_PASSED=0 TESTS_FAILED=0 TESTS_SKIPPED=0 record_test() { local result=$1 local test_name=$2 case $result in "PASS") log_success "✓ $test_name" ((TESTS_PASSED++)) ;; "FAIL") log_error "✗ $test_name" ((TESTS_FAILED++)) ;; "SKIP") log_warning "⚠ $test_name (skipped)" ((TESTS_SKIPPED++)) ;; esac } # Phase 1: Tool Availability Testing (No sudo required) test_tool_availability() { log_info "=== Phase 1: Tool Availability Testing ===" # Test 1: Check if tools are installed local tools=("apt-layer" "composefs-alternative" "bootc-alternative" "bootupd-alternative" "particle-orchestrator") for tool in "${tools[@]}"; do if command -v "$tool" >/dev/null 2>&1; then record_test "PASS" "Tool installed: $tool" else record_test "FAIL" "Tool not found: $tool" fi done # Test 2: Check if tools are executable for tool in "${tools[@]}"; do local tool_path=$(command -v "$tool" 2>/dev/null || echo "") if [[ -n "$tool_path" && -x "$tool_path" ]]; then record_test "PASS" "Tool executable: $tool" else record_test "FAIL" "Tool not executable: $tool" fi done } # Phase 2: Basic Command Testing (No sudo required) test_basic_commands() { log_info "=== Phase 2: Basic Command Testing ===" # Test help commands for available tools local tools=("apt-layer" "composefs-alternative" "bootc-alternative" "bootupd-alternative" "particle-orchestrator") for tool in "${tools[@]}"; do if command -v "$tool" >/dev/null 2>&1; then if timeout 10s "$tool" --help >/dev/null 2>&1; then record_test "PASS" "Help command works: $tool" else record_test "FAIL" "Help command failed: $tool" fi else record_test "SKIP" "Help command test: $tool" fi done } # Phase 3: Configuration Testing (No sudo required) test_configuration() { log_info "=== Phase 3: Configuration Testing ===" # Test if configuration file exists local config_file="/usr/local/etc/particle-config.sh" if [[ -f "$config_file" ]]; then record_test "PASS" "Configuration file exists: $config_file" # Test if configuration is readable if [[ -r "$config_file" ]]; then record_test "PASS" "Configuration file readable" else record_test "FAIL" "Configuration file not readable" fi # Test if configuration syntax is valid if bash -n "$config_file" 2>/dev/null; then record_test "PASS" "Configuration syntax valid" else record_test "FAIL" "Configuration syntax invalid" fi else record_test "FAIL" "Configuration file missing: $config_file" fi } # Phase 4: Directory Structure Testing (No sudo required) test_directory_structure() { log_info "=== Phase 4: Directory Structure Testing ===" # Test if directories exist local dirs=("/var/lib/particle-os" "/var/log/particle-os" "/var/cache/particle-os") for dir in "${dirs[@]}"; do if [[ -d "$dir" ]]; then record_test "PASS" "Directory exists: $dir" else record_test "FAIL" "Directory missing: $dir" fi done # Test if directories are accessible (readable) for dir in "${dirs[@]}"; do if [[ -d "$dir" && -r "$dir" ]]; then record_test "PASS" "Directory accessible: $dir" else record_test "FAIL" "Directory not accessible: $dir" fi done } # Phase 5: Dependency Testing (No sudo required) test_dependencies() { log_info "=== Phase 5: Dependency Testing ===" # Check system dependencies local deps=("squashfs-tools" "jq" "coreutils" "util-linux" "podman" "skopeo") for dep in "${deps[@]}"; do if command -v "$dep" >/dev/null 2>&1 || dpkg -l | grep -q "^ii.*$dep" 2>/dev/null; then record_test "PASS" "Dependency available: $dep" else record_test "FAIL" "Dependency missing: $dep" fi done # Check kernel modules (read-only check) if modprobe -n squashfs >/dev/null 2>&1; then record_test "PASS" "Kernel module available: squashfs" else record_test "FAIL" "Kernel module missing: squashfs" fi } # Show installation recommendations show_recommendations() { log_info "=== Installation Recommendations ===" local missing_tools=() local tools=("apt-layer" "composefs-alternative" "bootc-alternative" "bootupd-alternative" "particle-orchestrator") for tool in "${tools[@]}"; do if ! command -v "$tool" >/dev/null 2>&1; then missing_tools+=("$tool") fi done if [[ ${#missing_tools[@]} -gt 0 ]]; then log_warning "Missing tools: ${missing_tools[*]}" echo log_info "To install missing tools, run:" echo " sudo ./install-particle-os.sh" echo fi # Check for missing dependencies local missing_deps=() local deps=("squashfs-tools" "jq" "coreutils" "util-linux" "podman" "skopeo") for dep in "${deps[@]}"; do if ! command -v "$dep" >/dev/null 2>&1 && ! dpkg -l | grep -q "^ii.*$dep" 2>/dev/null; then missing_deps+=("$dep") fi done if [[ ${#missing_deps[@]} -gt 0 ]]; then log_warning "Missing dependencies: ${missing_deps[*]}" echo log_info "To install missing dependencies, run:" echo " sudo apt update" echo " sudo apt install ${missing_deps[*]}" echo fi } # Main test runner main() { log_info "Starting Particle-OS Basic Testing Suite (No sudo required)" log_info "Date: $(date)" log_info "System: $(uname -a)" # Run all test phases test_tool_availability test_basic_commands test_configuration test_directory_structure test_dependencies # Print summary log_info "=== Test Summary ===" log_info "Tests Passed: $TESTS_PASSED" log_info "Tests Failed: $TESTS_FAILED" log_info "Tests Skipped: $TESTS_SKIPPED" local total=$((TESTS_PASSED + TESTS_FAILED + TESTS_SKIPPED)) if [[ $total -gt 0 ]]; then local pass_rate=$((TESTS_PASSED * 100 / total)) log_info "Pass Rate: ${pass_rate}%" fi # Show recommendations show_recommendations if [[ $TESTS_FAILED -eq 0 ]]; then log_success "All basic tests completed successfully!" log_info "You can now run the full test suite with: sudo ./test-particle-os-complete.sh" exit 0 else log_error "Some tests failed. Please review the recommendations above." log_info "After fixing issues, run: sudo ./test-particle-os-complete.sh" exit 1 fi } # Run main function main "$@"