#!/bin/bash
# Quick VM Setup Script für Infoscreen Deployment Test

echo "🧪 Infoscreen VM Test Setup"
echo "=========================="

# System Update
echo "📦 System aktualisieren..."
sudo apt update -y
sudo apt upgrade -y

# Docker Installation
echo "🐳 Docker installieren..."
sudo apt install -y docker.io docker-compose-plugin curl wget htop

# Docker aktivieren
sudo systemctl enable docker
sudo systemctl start docker

# User zu Docker-Gruppe hinzufügen
sudo usermod -aG docker $USER

# Firewall konfigurieren
echo "🔥 Firewall konfigurieren..."
sudo ufw --force enable
sudo ufw allow 22/tcp   # SSH
sudo ufw allow 80/tcp   # HTTP
sudo ufw allow 443/tcp  # HTTPS

# Test-Verzeichnis erstellen
mkdir -p ~/infoscreen-test
cd ~/infoscreen-test

# Basis-Konfiguration erstellen
cat > docker-compose.test.yml << 'EOF'
version: '3.8'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx-test.conf:/etc/nginx/nginx.conf:ro

  test-api:
    image: httpd:alpine
    environment:
      - TEST=true
EOF

cat > nginx-test.conf << 'EOF'
events {}
http {
    server {
        listen 80;
        location / {
            return 200 "✅ VM Test erfolgreich!\n";
            add_header Content-Type text/plain;
        }
    }
}
EOF

echo ""
echo "✅ VM Setup abgeschlossen!"
echo ""
echo "Nächste Schritte:"
echo "1. Logout/Login für Docker-Gruppe"
echo "2. Test: docker run hello-world"
echo "3. Test: docker compose -f docker-compose.test.yml up -d"
echo "4. Test: curl http://localhost"
echo "5. Echtes Deployment: Dateien übertragen und starten"
echo ""
echo "🔍 System-Info:"
echo "Docker: $(docker --version)"
echo "Compose: $(docker compose version)"
echo "RAM: $(free -h | grep Mem | awk '{print $2}')"
echo "Disk: $(df -h / | tail -1 | awk '{print $4}') frei"
