#!/bin/bash source ~/.bashrc # Complete Deployment Automation Script # Orchestrates all deployment tasks set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' 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 "${BLUE}[STEP]${NC} $1" } log_header() { echo -e "${CYAN}========================================${NC}" echo -e "${CYAN}$1${NC}" echo -e "${CYAN}========================================${NC}" } # Check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } # Check VM connectivity check_vm_connectivity() { local ip=$1 local name=$2 log_info "Checking connectivity to $name ($ip)..." if ping -c 1 -W 2 "$ip" >/dev/null 2>&1; then log_info "✓ $name is reachable" return 0 else log_warn "✗ $name is not reachable (may still be installing OS)" return 1 fi } # Main deployment flow main() { log_header "Complete Deployment Automation" echo "" log_step "Phase 1: Prerequisites Check" echo "" # Check Proxmox connections log_info "Verifying Proxmox connections..." if ./scripts/utils/test-proxmox-connection.sh > /dev/null 2>&1; then log_info "✓ Proxmox connections verified" else log_error "Proxmox connection failed" exit 1 fi echo "" log_step "Phase 2: VM Creation Status" echo "" log_warn "VM creation requires manual steps via Proxmox Web UI" log_info "Run: ./scripts/create-all-vms.sh to see available resources" log_info "Then create VMs at: https://192.168.1.206:8006" echo "" # VM IPs declare -A VM_IPS=( ["cloudflare-tunnel"]="192.168.1.60" ["k3s-master"]="192.168.1.188" ["git-server"]="192.168.1.121" ["observability"]="192.168.1.82" ) log_info "Checking VM connectivity..." for vm_name in "${!VM_IPS[@]}"; do check_vm_connectivity "${VM_IPS[$vm_name]}" "$vm_name" done echo "" log_step "Phase 3: Post-VM-Creation Automation" echo "" log_info "Once VMs are created and OS is installed, run:" echo "" echo " For Cloudflare Tunnel VM:" echo " ssh user@192.168.1.60" echo " sudo bash <(curl -s https://raw.githubusercontent.com/your-repo/scripts/setup-cloudflare-tunnel.sh)" echo " # Or copy scripts/setup-cloudflare-tunnel.sh to VM" echo "" echo " For K3s VM:" echo " ssh user@192.168.1.188" echo " sudo bash <(curl -s https://raw.githubusercontent.com/your-repo/scripts/setup-k3s.sh)" echo " # Or copy scripts/setup-k3s.sh to VM" echo "" log_step "Phase 4: Generate Setup Packages" echo "" # Create setup package for each VM mkdir -p /tmp/vm-setup-packages log_info "Creating setup packages..." # Cloudflare Tunnel setup package cat > /tmp/vm-setup-packages/cloudflare-tunnel-setup.sh <<'EOFTUNNEL' #!/bin/bash # Cloudflare Tunnel VM Setup # Run this on the Cloudflare Tunnel VM after OS installation set -e cd /tmp curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared chmod +x /usr/local/bin/cloudflared useradd -r -s /bin/false cloudflared || true mkdir -p /etc/cloudflared chown cloudflared:cloudflared /etc/cloudflared echo "cloudflared installed. Next steps:" echo "1. Run: cloudflared tunnel login" echo "2. Run: cloudflared tunnel create azure-stack-hci" echo "3. Configure /etc/cloudflared/config.yml" echo "4. Set up systemd service" EOFTUNNEL # K3s setup package cat > /tmp/vm-setup-packages/k3s-setup.sh <<'EOFK3S' #!/bin/bash # K3s Setup # Run this on the K3s VM after OS installation set -e curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" sh - systemctl status k3s echo "K3s installed. Next steps:" echo "1. Configure kubectl: export KUBECONFIG=/etc/rancher/k3s/k3s.yaml" echo "2. Verify: kubectl get nodes" EOFK3S chmod +x /tmp/vm-setup-packages/*.sh log_info "✓ Setup packages created in /tmp/vm-setup-packages/" echo "" log_step "Phase 5: Documentation" echo "" log_info "All documentation is ready:" echo " - CREATE_VMS.md - VM creation guide" echo " - QUICK_START.md - Quick reference" echo " - DEPLOYMENT_WITHOUT_AZURE.md - Full plan" echo " - DEPLOYMENT_CHECKLIST.md - Progress tracker" echo "" log_header "Deployment Automation Complete" echo "" log_info "Next Steps:" echo " 1. Create VMs via Proxmox Web UI (see CREATE_VMS.md)" echo " 2. Install OS on each VM" echo " 3. Copy setup scripts to VMs and run them" echo " 4. Follow DEPLOYMENT_CHECKLIST.md to track progress" echo "" } main "$@"