#!/bin/bash # DevMatrix Setup Script for Proxmox # Tailored for: Roberth's Proxmox Environment # Network: vmbr1 | VM IDs: 300+ | Windows: LTSC IoT # Run this script ON THE PROXMOX HOST as root set -e # ============================================ # CONFIGURATION (User Specified) # ============================================ NETWORK_BRIDGE="vmbr1" VM_ID_START=300 PROXMOX_NODE="pve" # Change if your node has a different name # VM IDs MAIN_VMID=300 # OpenClaw DevMatrix (Ubuntu) WIN_VMID=301 # Windows LTSC IoT Test VM ANDROID_VMID=302 # Android Emulator VM # Resource Allocation MAIN_RAM=32768 # 32GB RAM for main dev VM MAIN_CORES=16 # 16 CPU cores MAIN_DISK=500 # 500GB primary disk MAIN_SECONDARY=200 # 200GB secondary disk WIN_RAM=16384 # 16GB RAM for Windows WIN_CORES=8 # 8 CPU cores WIN_DISK=150 # 150GB disk ANDROID_RAM=8192 # 8GB RAM for Android ANDROID_CORES=4 # 4 CPU cores ANDROID_DISK=100 # 100GB disk # ============================================ # COLORS FOR OUTPUT # ============================================ RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' NC='\033[0m' # No Color log() { echo -e "${GREEN}[DevMatrix]${NC} $1" } warn() { echo -e "${YELLOW}[Warning]${NC} $1" } error() { echo -e "${RED}[Error]${NC} $1" exit 1 } info() { echo -e "${CYAN}[Info]${NC} $1" } # ============================================ # PRE-FLIGHT CHECKS # ============================================ log "🔍 Running pre-flight checks..." # Check if running as root if [ "$EUID" -ne 0 ]; then error "Please run as root (use: sudo bash $0)" fi # Check if vmbr1 exists if ! ip link show "$NETWORK_BRIDGE" &> /dev/null; then error "Network bridge '$NETWORK_BRIDGE' not found!" fi log "✓ Network bridge '$NETWORK_BRIDGE' found" # Check available storage log "📦 Checking available storage..." pvesm status # Let user select storage info "Available storage locations (select one for VM disks):" pvesm status | grep -v "Name" | nl echo "" read -p "Enter the storage name to use (e.g., local-lvm, vm-storage): " STORAGE_NAME if [ -z "$STORAGE_NAME" ]; then error "Storage name cannot be empty" fi # Verify storage exists if ! pvesm status | grep -q "^$STORAGE_NAME"; then error "Storage '$STORAGE_NAME' not found" fi log "✓ Using storage: $STORAGE_NAME" # Check if VM IDs are available log "🔍 Checking VM ID availability..." for vmid in $MAIN_VMID $WIN_VMID $ANDROID_VMID; do if qm status "$vmid" &> /dev/null; then error "VM ID $vmid already exists!" fi done log "✓ VM IDs $MAIN_VMID, $WIN_VMID, $ANDROID_VMID are available" # Check available resources log "📊 Checking available resources..." AVAILABLE_RAM=$(free -m | awk '/^Mem:/{print $7}') AVAILABLE_DISK=$(pvesm status | grep "^$STORAGE_NAME" | awk '{print $4}' | sed 's/G//') info "Available RAM: ${AVAILABLE_RAM}MB" info "Available Disk: ${AVAILABLE_DISK}GB" TOTAL_RAM_NEEDED=$((MAIN_RAM + WIN_RAM + ANDROID_RAM)) TOTAL_DISK_NEEDED=$((MAIN_DISK + MAIN_SECONDARY + WIN_DISK + ANDROID_DISK)) info "RAM needed: ${TOTAL_RAM_NEEDED}MB" info "Disk needed: ${TOTAL_DISK_NEEDED}GB" if [ "$AVAILABLE_RAM" -lt "$TOTAL_RAM_NEEDED" ]; then warn "Low RAM! You may need to adjust VM memory" read -p "Continue anyway? (y/N): " confirm if [ "$confirm" != "y" ]; then exit 1; fi fi echo "" log "✅ Pre-flight checks complete!" echo "" # ============================================ # DOWNLOAD ISO IMAGES # ============================================ log "⬇️ Checking for required ISO images..." ISO_DIR="/var/lib/vz/template/iso" mkdir -p "$ISO_DIR" # Ubuntu 22.04 Server ISO UBUNTU_ISO="$ISO_DIR/ubuntu-22.04.5-live-server-amd64.iso" if [ -f "$UBUNTU_ISO" ]; then log "✓ Ubuntu ISO already exists" else log "⬇️ Downloading Ubuntu 22.04 Server ISO..." wget -O "$UBUNTU_ISO" \ "https://releases.ubuntu.com/22.04/ubuntu-22.04.5-live-server-amd64.iso" \ --progress=bar:force 2>&1 | tail -f -n +6 log "✓ Ubuntu ISO downloaded" fi # Windows 11 LTSC IoT ISO WIN_ISO="$ISO_DIR/Win11_Ent_LTSC_IoT.iso" if [ -f "$WIN_ISO" ]; then log "✓ Windows LTSC IoT ISO already exists" else warn "⚠️ Windows 11 LTSC IoT ISO not found" info "Please download the ISO manually from Microsoft VLSC or your volume licensing portal" info "Expected location: $WIN_ISO" info "" info "Alternative: Use Windows 11 standard ISO for now" read -p "Download Windows 11 standard ISO instead? (y/N): " download_win if [ "$download_win" == "y" ]; then log "⬇️ Downloading Windows 11 standard ISO..." warn "This is a large download (~6GB) and may take a while" # Note: Microsoft doesn't provide direct ISO links, user needs to download manually info "Please download Windows 11 ISO from: https://www.microsoft.com/software-download/windows11" info "Save it to: $ISO_DIR/Win11.iso" read -p "Press Enter when Windows ISO is ready..." fi fi echo "" # ============================================ # CREATE VM 300: OpenClaw DevMatrix (Ubuntu) # ============================================ log "🚀 Creating VM $MAIN_VMID: OpenClaw DevMatrix" # Create VM qm create $MAIN_VMID \ --name "OpenClaw-DevMatrix" \ --memory $MAIN_RAM \ --cores $MAIN_CORES \ --cpu host \ --net0 virtio,bridge=$NETWORK_BRIDGE \ --scsihw virtio-scsi-single \ --bios ovmf \ --machine q35 # Add EFI disk qm set $MAIN_VMID --efidisk0 ${STORAGE_NAME}:1,format=qcow2,efitype=4m,pre-enrolled-keys=1 # Add primary disk qm set $MAIN_VMID --scsi0 ${STORAGE_NAME}:${MAIN_DISK},format=qcow2,discard=on,iothread=1,ssd=1 # Add secondary disk for projects qm set $MAIN_VMID --scsi1 ${STORAGE_NAME}:${MAIN_SECONDARY},format=qcow2,discard=on,iothread=1,ssd=1 # Add cloud-init drive qm set $MAIN_VMID --ide2 ${STORAGE_NAME}:cloudinit,media=cdrom # Attach Ubuntu ISO qm set $MAIN_VMID --ide0 local:iso/ubuntu-22.04.5-live-server-amd64.iso,media=cdrom # Set boot order qm set $MAIN_VMID --boot order=scsi0;ide0 # Enable QEMU Guest Agent qm set $MAIN_VMID --agent enabled=1,fstrim_cloned_disks=1 # Configure cloud-init qm set $MAIN_VMID --ciuser devmatrix qm set $MAIN_VMID --cipassword $(openssl rand -base64 32) qm set $MAIN_VMID --ipconfig0 ip=dhcp # Generate SSH key pair if [ ! -f ~/.ssh/devmatrix_id_rsa ]; then ssh-keygen -t rsa -b 4096 -f ~/.ssh/devmatrix_id_rsa -N "" -C "devmatrix@proxmox" fi qm set $MAIN_VMID --sshkeys ~/.ssh/devmatrix_id_rsa.pub log "✓ VM $MAIN_VMID created successfully" echo "" # ============================================ # CREATE VM 301: Windows LTSC IoT Test VM # ============================================ log "🚀 Creating VM $WIN_VMID: Windows-LTSC-Test" qm create $WIN_VMID \ --name "Windows-LTSC-Test" \ --memory $WIN_RAM \ --cores $WIN_CORES \ --cpu host \ --net0 virtio,bridge=$NETWORK_BRIDGE \ --scsihw virtio-scsi-single \ --bios ovmf \ --machine q35 # Add EFI disk qm set $WIN_VMID --efidisk0 ${STORAGE_NAME}:1,format=qcow2,efitype=4m,pre-enrolled-keys=1 # Add disk qm set $WIN_VMID --scsi0 ${STORAGE_NAME}:${WIN_DISK},format=qcow2,discard=on,iothread=1,ssd=1 # Attach Windows ISO (try both names) if [ -f "$ISO_DIR/Win11_Ent_LTSC_IoT.iso" ]; then qm set $WIN_VMID --ide0 local:iso/Win11_Ent_LTSC_IoT.iso,media=cdrom elif [ -f "$ISO_DIR/Win11.iso" ]; then qm set $WIN_VMID --ide0 local:iso/Win11.iso,media=cdrom else warn "⚠️ No Windows ISO attached. Please attach manually after download." fi # Set boot order qm set $WIN_VMID --boot order=scsi0;ide0 # Enable QEMU Guest Agent qm set $WIN_VMID --agent enabled=1 log "✓ VM $WIN_VMID created successfully" echo "" # ============================================ # CREATE VM 302: Android Emulator VM # ============================================ log "🚀 Creating VM $ANDROID_VMID: Android-Emulator" qm create $ANDROID_VMID \ --name "Android-Emulator" \ --memory $ANDROID_RAM \ --cores $ANDROID_CORES \ --cpu host \ --net0 virtio,bridge=$NETWORK_BRIDGE \ --scsihw virtio-scsi-single \ --bios ovmf \ --machine q35 # Add EFI disk qm set $ANDROID_VMID --efidisk0 ${STORAGE_NAME}:1,format=qcow2,efitype=4m,pre-enrolled-keys=1 # Add disk qm set $ANDROID_VMID --scsi0 ${STORAGE_NAME}:${ANDROID_DISK},format=qcow2,discard=on,iothread=1,ssd=1 # Attach Ubuntu ISO (for Android development environment) qm set $ANDROID_VMID --ide0 local:iso/ubuntu-22.04.5-live-server-amd64.iso,media=cdrom # Set boot order qm set $ANDROID_VMID --boot order=scsi0;ide0 # Enable QEMU Guest Agent qm set $ANDROID_VMID --agent enabled=1 log "✓ VM $ANDROID_VMID created successfully" echo "" # ============================================ # SUMMARY # ============================================ log "🎉 DevMatrix VMs Created Successfully!" echo "" echo "╔════════════════════════════════════════════════════════════╗" echo "║ VM INVENTORY ║" echo "╠════════════════════════════════════════════════════════════╣" echo "║ ID │ Name │ RAM │ Disk │ Status ║" echo "╠═══════╪═════════════════════════╪════════╪═══════╪════════╣" printf "║ %d │ %-23s │ %dGB │ %dGB │ Ready ║\n" $MAIN_VMID "OpenClaw-DevMatrix" $((MAIN_RAM/1024)) $((MAIN_DISK+MAIN_SECONDARY)) printf "║ %d │ %-23s │ %dGB │ %dGB │ Ready ║\n" $WIN_VMID "Windows-LTSC-Test" $((WIN_RAM/1024)) $WIN_DISK printf "║ %d │ %-23s │ %dGB │ %dGB │ Ready ║\n" $ANDROID_VMID "Android-Emulator" $((ANDROID_RAM/1024)) $ANDROID_DISK echo "╚════════════════════════════════════════════════════════════╝" echo "" # ============================================ # NEXT STEPS # ============================================ log "📋 Next Steps:" echo "" echo "1. INSTALL UBUNTU ON VM $MAIN_VMID:" echo " qm start $MAIN_VMID" echo " # Connect via console: qm console $MAIN_VMID" echo " # Or use Proxmox web UI console" echo "" echo "2. AFTER UBUNTU INSTALL, RUN SETUP:" echo " # SSH into the VM:" echo " ssh -i ~/.ssh/devmatrix_id_rsa devmatrix@" echo "" echo " # Download and run the OpenClaw setup script:" echo " curl -fsSL https://raw.githubusercontent.com/yourrepo/devmatrix/main/setup_openclaw_dev.sh | bash" echo "" echo "3. INSTALL WINDOWS ON VM $WIN_VMID:" echo " qm start $WIN_VMID" echo " # Install Windows LTSC IoT manually" echo " # Then run: setup_windows_vm.ps1 (provided separately)" echo "" echo "4. CONFIGURE API KEYS (YOU DO THIS):" echo " # Inside the Ubuntu VM, run:" echo " ~/scripts/configure_api_keys.sh" echo " # Enter your Kimi and Antigravity API keys" echo "" # Save VM info to file cat > ~/devmatrix_vm_info.txt << EOF DevMatrix VM Information ======================== Created: $(date) Network: $NETWORK_BRIDGE Storage: $STORAGE_NAME VM 300: OpenClaw-DevMatrix (Ubuntu 22.04) - RAM: ${MAIN_RAM}MB (32GB) - CPU: ${MAIN_CORES} cores - Disk: ${MAIN_DISK}GB + ${MAIN_SECONDARY}GB - SSH Key: ~/.ssh/devmatrix_id_rsa VM 301: Windows-LTSC-Test (Windows 11 LTSC IoT) - RAM: ${WIN_RAM}MB (16GB) - CPU: ${WIN_CORES} cores - Disk: ${WIN_DISK}GB VM 302: Android-Emulator (Ubuntu) - RAM: ${ANDROID_RAM}MB (8GB) - CPU: ${ANDROID_CORES} cores - Disk: ${ANDROID_DISK}GB SSH Access: ssh -i ~/.ssh/devmatrix_id_rsa devmatrix@ Proxmox Commands: Start VM 300: qm start 300 Stop VM 300: qm stop 300 Console: qm console 300 Status: qm status 300 EOF log "📄 VM information saved to: ~/devmatrix_vm_info.txt" log "🔑 SSH private key: ~/.ssh/devmatrix_id_rsa" log "🔓 SSH public key: ~/.ssh/devmatrix_id_rsa.pub" echo "" log "✅ Setup script complete! Review the steps above to continue."