#!/bin/bash source ~/.bashrc # Complete All Infrastructure Setup # Sets up cluster, storage, and network on both Proxmox hosts set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" # Load environment variables if [ -f "$PROJECT_ROOT/.env" ]; then set -a source <(grep -v '^#' "$PROJECT_ROOT/.env" | grep -v '^$' | sed 's/#.*$//' | grep '=') set +a fi # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' log_info() { echo -e "${GREEN}[INFO]${NC} $1" } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } log_step() { echo -e "\n${BLUE}=== $1 ===${NC}" } ML110_IP="${PROXMOX_ML110_IP:-192.168.1.206}" R630_IP="${PROXMOX_R630_IP:-192.168.1.49}" SSH_KEY="$HOME/.ssh/id_ed25519_proxmox" SSH_OPTS="-i $SSH_KEY" execute_remote() { local host=$1 local command=$2 local description=$3 log_info "$description on $host" if ssh $SSH_OPTS -o StrictHostKeyChecking=no "root@$host" "$command"; then log_info "✓ $description completed on $host" return 0 else log_error "✗ $description failed on $host" return 1 fi } copy_file_remote() { local host=$1 local source=$2 local dest=$3 log_info "Copying $source to root@$host:$dest" scp $SSH_OPTS "$source" "root@$host:$dest" } # Step 1: Create cluster on ML110 create_cluster_ml110() { log_step "Creating Proxmox Cluster on ML110" # Check if cluster already exists if ssh $SSH_OPTS "root@$ML110_IP" "pvecm status" &>/dev/null; then log_warn "Cluster already exists on ML110" ssh $SSH_OPTS "root@$ML110_IP" "pvecm status" return 0 fi # Copy cluster setup script copy_file_remote "$ML110_IP" "$PROJECT_ROOT/infrastructure/proxmox/cluster-setup.sh" "/tmp/cluster-setup.sh" # Execute cluster creation execute_remote "$ML110_IP" \ "chmod +x /tmp/cluster-setup.sh && CLUSTER_NAME=hc-cluster NODE_ROLE=create /tmp/cluster-setup.sh" \ "Cluster creation" # Verify execute_remote "$ML110_IP" "pvecm status && pvecm nodes" "Cluster verification" } # Step 2: Join R630 to cluster join_cluster_r630() { log_step "Joining R630 to Proxmox Cluster" # Check if already in cluster if ssh $SSH_OPTS "root@$R630_IP" "pvecm status" &>/dev/null; then log_warn "R630 already in cluster" return 0 fi # Copy cluster setup script copy_file_remote "$R630_IP" "$PROJECT_ROOT/infrastructure/proxmox/cluster-setup.sh" "/tmp/cluster-setup.sh" # Execute cluster join if [ -n "$PVE_ROOT_PASS" ]; then execute_remote "$R630_IP" \ "chmod +x /tmp/cluster-setup.sh && CLUSTER_NAME=hc-cluster NODE_ROLE=join CLUSTER_NODE_IP=$ML110_IP ROOT_PASSWORD='$PVE_ROOT_PASS' /tmp/cluster-setup.sh" \ "Cluster join" else log_error "PVE_ROOT_PASS not set. Cannot join cluster without root password." return 1 fi } # Step 3: Configure NFS storage on ML110 configure_nfs_ml110() { log_step "Configuring NFS Storage on ML110" # Check if storage already exists if ssh $SSH_OPTS "root@$ML110_IP" "pvesm status | grep router-storage" &>/dev/null; then log_warn "NFS storage already configured on ML110" return 0 fi # Copy NFS storage script copy_file_remote "$ML110_IP" "$PROJECT_ROOT/infrastructure/proxmox/nfs-storage.sh" "/tmp/nfs-storage.sh" # Execute NFS configuration execute_remote "$ML110_IP" \ "chmod +x /tmp/nfs-storage.sh && NFS_SERVER=10.10.10.1 NFS_PATH=/mnt/storage STORAGE_NAME=router-storage /tmp/nfs-storage.sh" \ "NFS storage configuration" # Verify execute_remote "$ML110_IP" "pvesm status" "NFS storage verification" } # Step 4: Configure NFS storage on R630 configure_nfs_r630() { log_step "Configuring NFS Storage on R630" # Check if storage already exists if ssh $SSH_OPTS "root@$R630_IP" "pvesm status | grep router-storage" &>/dev/null; then log_warn "NFS storage already configured on R630" return 0 fi # Copy NFS storage script copy_file_remote "$R630_IP" "$PROJECT_ROOT/infrastructure/proxmox/nfs-storage.sh" "/tmp/nfs-storage.sh" # Execute NFS configuration execute_remote "$R630_IP" \ "chmod +x /tmp/nfs-storage.sh && NFS_SERVER=10.10.10.1 NFS_PATH=/mnt/storage STORAGE_NAME=router-storage /tmp/nfs-storage.sh" \ "NFS storage configuration" # Verify execute_remote "$R630_IP" "pvesm status" "NFS storage verification" } # Step 5: Configure VLAN bridges on ML110 configure_vlans_ml110() { log_step "Configuring VLAN Bridges on ML110" # Copy VLAN script copy_file_remote "$ML110_IP" "$PROJECT_ROOT/infrastructure/network/configure-proxmox-vlans.sh" "/tmp/configure-proxmox-vlans.sh" # Execute VLAN configuration execute_remote "$ML110_IP" \ "chmod +x /tmp/configure-proxmox-vlans.sh && /tmp/configure-proxmox-vlans.sh && systemctl restart networking" \ "VLAN configuration" # Verify execute_remote "$ML110_IP" "ip addr show | grep -E 'vmbr[0-9]+' | head -10" "VLAN verification" } # Step 6: Configure VLAN bridges on R630 configure_vlans_r630() { log_step "Configuring VLAN Bridges on R630" # Copy VLAN script copy_file_remote "$R630_IP" "$PROJECT_ROOT/infrastructure/network/configure-proxmox-vlans.sh" "/tmp/configure-proxmox-vlans.sh" # Execute VLAN configuration execute_remote "$R630_IP" \ "chmod +x /tmp/configure-proxmox-vlans.sh && /tmp/configure-proxmox-vlans.sh && systemctl restart networking" \ "VLAN configuration" # Verify execute_remote "$R630_IP" "ip addr show | grep -E 'vmbr[0-9]+' | head -10" "VLAN verification" } main() { log_info "Completing All Infrastructure Setup" echo "" # Check SSH access if [ ! -f "$SSH_KEY" ]; then log_error "SSH key not found: $SSH_KEY" log_info "Run: ./scripts/utils/setup-ssh-keys.sh" exit 1 fi if ! ssh $SSH_OPTS -o ConnectTimeout=5 "root@$ML110_IP" "echo 'SSH OK'" &> /dev/null; then log_error "SSH access to ML110 failed" exit 1 fi # Infrastructure setup create_cluster_ml110 configure_nfs_ml110 configure_vlans_ml110 # R630 setup (if SSH available) if ssh $SSH_OPTS -o ConnectTimeout=5 "root@$R630_IP" "echo 'SSH OK'" &> /dev/null; then join_cluster_r630 configure_nfs_r630 configure_vlans_r630 else log_warn "SSH access to R630 not available, skipping R630 setup" fi log_step "Infrastructure Setup Complete!" log_info "Next: Verify VM boot and network connectivity" } main "$@"