#!/usr/bin/env bash
# Quick Bootstrap Script
# Bootstraps network for already-deployed containers (assumes containers and configs exist)

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

source "$PROJECT_ROOT/lib/common.sh"

# Load configuration
load_config
load_config "$PROJECT_ROOT/config/network.conf" || true

log_info "========================================="
log_info "Quick Network Bootstrap"
log_info "========================================="
log_info ""
log_info "This script bootstraps the network for existing containers."
log_info "Assumes containers are deployed and configuration files are copied."
log_info ""

# Check prerequisites
if ! command_exists pct; then
    error_exit "pct command not found. This script must be run on Proxmox host."
fi

if [[ $EUID -ne 0 ]]; then
    error_exit "This script must be run as root"
fi

# Run the main bootstrap script
if [[ -f "$PROJECT_ROOT/scripts/network/bootstrap-network.sh" ]]; then
    log_info "Running network bootstrap..."
    "$PROJECT_ROOT/scripts/network/bootstrap-network.sh" || {
        log_error "Network bootstrap failed"
        exit 1
    }
    log_success "Quick bootstrap complete!"
else
    error_exit "Bootstrap script not found: $PROJECT_ROOT/scripts/network/bootstrap-network.sh"
fi

exit 0

