Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
268 lines
7.5 KiB
Bash
Executable File
268 lines
7.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Deploy network configuration to both Proxmox servers via SSH
|
|
# ML110: 192.168.1.206
|
|
# R630: 192.168.1.49
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
DEPLOY_DIR="/opt/proxmox-network-config"
|
|
|
|
# Server configuration
|
|
ML110_IP="192.168.1.206"
|
|
R630_IP="192.168.1.49"
|
|
SSH_USER="root"
|
|
|
|
# SSH key (if available)
|
|
SSH_KEY=""
|
|
if [ -f ~/.ssh/id_ed25519_proxmox ]; then
|
|
SSH_KEY="-i ~/.ssh/id_ed25519_proxmox"
|
|
elif [ -f ~/.ssh/id_rsa ]; then
|
|
SSH_KEY="-i ~/.ssh/id_rsa"
|
|
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_server() {
|
|
echo -e "${BLUE}[$1]${NC} $2"
|
|
}
|
|
|
|
check_ssh_access() {
|
|
local server_ip=$1
|
|
local server_name=$2
|
|
|
|
log_info "Checking SSH access to $server_name ($server_ip)..."
|
|
|
|
if ssh $SSH_KEY -o ConnectTimeout=5 -o StrictHostKeyChecking=no "$SSH_USER@$server_ip" "echo 'Connection successful'" &>/dev/null; then
|
|
log_info "✓ SSH access to $server_name confirmed"
|
|
return 0
|
|
else
|
|
log_error "✗ Cannot SSH to $server_name ($server_ip)"
|
|
log_error "Please ensure:"
|
|
log_error " - Server is accessible on the network"
|
|
log_error " - SSH is enabled and accessible"
|
|
log_error " - SSH key authentication is set up, or password auth is enabled"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
transfer_scripts() {
|
|
local server_ip=$1
|
|
local server_name=$2
|
|
|
|
log_server "$server_name" "Transferring scripts..."
|
|
|
|
# Create directory on remote server
|
|
ssh $SSH_KEY "$SSH_USER@$server_ip" "mkdir -p $DEPLOY_DIR" || {
|
|
log_error "Failed to create directory on $server_name"
|
|
return 1
|
|
}
|
|
|
|
# Transfer all necessary files
|
|
scp $SSH_KEY -r "$SCRIPT_DIR"/*.sh "$SSH_USER@$server_ip:$DEPLOY_DIR/" 2>/dev/null || {
|
|
log_error "Failed to transfer scripts to $server_name"
|
|
return 1
|
|
}
|
|
|
|
# Transfer documentation (optional but helpful)
|
|
scp $SSH_KEY "$SCRIPT_DIR"/*.md "$SSH_USER@$server_ip:$DEPLOY_DIR/" 2>/dev/null || true
|
|
|
|
# Make scripts executable
|
|
ssh $SSH_KEY "$SSH_USER@$server_ip" "chmod +x $DEPLOY_DIR/*.sh" || {
|
|
log_error "Failed to make scripts executable on $server_name"
|
|
return 1
|
|
}
|
|
|
|
log_server "$server_name" "✓ Scripts transferred successfully"
|
|
}
|
|
|
|
deploy_to_server() {
|
|
local server_ip=$1
|
|
local server_name=$2
|
|
|
|
log_server "$server_name" "Starting deployment..."
|
|
|
|
# Run deployment script remotely
|
|
ssh $SSH_KEY -t "$SSH_USER@$server_ip" "cd $DEPLOY_DIR && ./deploy-network-config.sh" || {
|
|
log_error "Deployment failed on $server_name"
|
|
return 1
|
|
}
|
|
|
|
log_server "$server_name" "✓ Deployment completed"
|
|
}
|
|
|
|
verify_deployment() {
|
|
local server_ip=$1
|
|
local server_name=$2
|
|
|
|
log_server "$server_name" "Verifying deployment..."
|
|
|
|
# Check if bridges are configured
|
|
ssh $SSH_KEY "$SSH_USER@$server_ip" "ip link show vmbr0 && ip link show vmbr1" &>/dev/null || {
|
|
log_warn "Bridges not yet up on $server_name (may need time for DHCP)"
|
|
return 0
|
|
}
|
|
|
|
# Check IP addresses
|
|
local vmbr0_ip=$(ssh $SSH_KEY "$SSH_USER@$server_ip" "ip addr show vmbr0 2>/dev/null | grep 'inet ' | awk '{print \$2}'" || echo "")
|
|
local vmbr1_ip=$(ssh $SSH_KEY "$SSH_USER@$server_ip" "ip addr show vmbr1 2>/dev/null | grep 'inet ' | awk '{print \$2}'" || echo "")
|
|
|
|
if [ -n "$vmbr0_ip" ]; then
|
|
log_server "$server_name" "✓ vmbr0 IP: $vmbr0_ip"
|
|
else
|
|
log_warn "vmbr0 has no IP yet (DHCP pending)"
|
|
fi
|
|
|
|
if [ -n "$vmbr1_ip" ]; then
|
|
log_server "$server_name" "✓ vmbr1 IP: $vmbr1_ip"
|
|
else
|
|
log_warn "vmbr1 has no IP yet (DHCP pending)"
|
|
fi
|
|
}
|
|
|
|
deploy_to_all() {
|
|
log_info "========================================="
|
|
log_info "Deploying to All Proxmox Servers"
|
|
log_info "========================================="
|
|
echo ""
|
|
|
|
# Check SSH access first
|
|
log_info "Step 1: Checking SSH access..."
|
|
if ! check_ssh_access "$ML110_IP" "ML110"; then
|
|
log_error "Cannot access ML110. Aborting."
|
|
exit 1
|
|
fi
|
|
|
|
if ! check_ssh_access "$R630_IP" "R630"; then
|
|
log_error "Cannot access R630. Aborting."
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
# Transfer scripts
|
|
log_info "Step 2: Transferring scripts to servers..."
|
|
if ! transfer_scripts "$ML110_IP" "ML110"; then
|
|
log_error "Failed to transfer scripts to ML110"
|
|
exit 1
|
|
fi
|
|
|
|
if ! transfer_scripts "$R630_IP" "R630"; then
|
|
log_error "Failed to transfer scripts to R630"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
# Deploy to ML110 first
|
|
log_info "Step 3: Deploying to ML110..."
|
|
log_warn "This will modify network configuration and may temporarily disconnect you."
|
|
read -p "Continue with ML110 deployment? (yes/no): " CONFIRM_ML110
|
|
|
|
if [ "$CONFIRM_ML110" = "yes" ]; then
|
|
if ! deploy_to_server "$ML110_IP" "ML110"; then
|
|
log_error "ML110 deployment failed"
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
verify_deployment "$ML110_IP" "ML110"
|
|
else
|
|
log_warn "ML110 deployment skipped"
|
|
fi
|
|
echo ""
|
|
|
|
# Deploy to R630
|
|
log_info "Step 4: Deploying to R630..."
|
|
read -p "Continue with R630 deployment? (yes/no): " CONFIRM_R630
|
|
|
|
if [ "$CONFIRM_R630" = "yes" ]; then
|
|
if ! deploy_to_server "$R630_IP" "R630"; then
|
|
log_error "R630 deployment failed"
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
verify_deployment "$R630_IP" "R630"
|
|
else
|
|
log_warn "R630 deployment skipped"
|
|
fi
|
|
echo ""
|
|
|
|
log_info "========================================="
|
|
log_info "Deployment Complete!"
|
|
log_info "========================================="
|
|
log_info "Please verify connectivity on both servers:"
|
|
log_info " - Check Proxmox web interface"
|
|
log_info " - Verify LAN connectivity"
|
|
log_info " - Verify WAN connectivity"
|
|
}
|
|
|
|
# Auto-deploy mode (no prompts)
|
|
auto_deploy() {
|
|
log_info "========================================="
|
|
log_info "Auto-Deploying to All Proxmox Servers"
|
|
log_info "========================================="
|
|
echo ""
|
|
|
|
# Check SSH access
|
|
log_info "Step 1: Checking SSH access..."
|
|
check_ssh_access "$ML110_IP" "ML110" || exit 1
|
|
check_ssh_access "$R630_IP" "R630" || exit 1
|
|
echo ""
|
|
|
|
# Transfer scripts
|
|
log_info "Step 2: Transferring scripts..."
|
|
transfer_scripts "$ML110_IP" "ML110" || exit 1
|
|
transfer_scripts "$R630_IP" "R630" || exit 1
|
|
echo ""
|
|
|
|
# Deploy to ML110
|
|
log_info "Step 3: Deploying to ML110..."
|
|
ssh $SSH_KEY -t "$SSH_USER@$ML110_IP" "cd $DEPLOY_DIR && echo 'yes' | ./deploy-network-config.sh" || {
|
|
log_error "ML110 deployment failed"
|
|
exit 1
|
|
}
|
|
sleep 3
|
|
verify_deployment "$ML110_IP" "ML110"
|
|
echo ""
|
|
|
|
# Deploy to R630
|
|
log_info "Step 4: Deploying to R630..."
|
|
ssh $SSH_KEY -t "$SSH_USER@$R630_IP" "cd $DEPLOY_DIR && echo 'yes' | ./deploy-network-config.sh" || {
|
|
log_error "R630 deployment failed"
|
|
exit 1
|
|
}
|
|
sleep 3
|
|
verify_deployment "$R630_IP" "R630"
|
|
echo ""
|
|
|
|
log_info "========================================="
|
|
log_info "Auto-Deployment Complete!"
|
|
log_info "========================================="
|
|
}
|
|
|
|
main() {
|
|
if [ "$1" = "--auto" ]; then
|
|
auto_deploy
|
|
else
|
|
deploy_to_all
|
|
fi
|
|
}
|
|
|
|
main "$@"
|
|
|