#!/bin/bash
# 🚀 Auto-generated by The AltStack
# https://thealtstack.com

echo "🔵 Starting AltStack Deployment..."

# 1. Check/Install Docker
if ! command -v docker &> /dev/null; then
    echo "📦 Docker not found. Installing..."
    curl -fsSL https://get.docker.com -o get-docker.sh
    sh get-docker.sh
    rm get-docker.sh
    echo "✅ Docker installed."
else
    echo "✅ Docker is already installed."
fi

# 2. Setup Directory
APP_DIR="seaweedfs-deploy"
mkdir -p $APP_DIR
cd $APP_DIR
echo "📂 Created directory: $APP_DIR"

# 3. Create docker-compose.yml
echo "📄 Writing configuration..."
cat << 'INNER_EOF' > docker-compose.yml

# -------------------------------------------------------------------------
# 🚀 Created and distributed by The AltStack
# 🌍 https://thealtstack.com
# -------------------------------------------------------------------------

services:
  master:
    image: chrislusf/seaweedfs
    container_name: seaweedfs-master
    restart: unless-stopped
    ports:
      - "9333:9333"
    command: "master -ip=master"

  volume:
    image: chrislusf/seaweedfs
    container_name: seaweedfs-volume
    restart: unless-stopped
    ports:
      - "8080:8080"
    command: "volume -mserver=master:9333 -port=8080"
    depends_on:
      - master
    volumes:
      - seaweedfs_data:/data

  filer:
    image: chrislusf/seaweedfs
    container_name: seaweedfs-filer
    restart: unless-stopped
    ports:
      - "8888:8888"
    command: "filer -master=master:9333"
    depends_on:
      - master

  s3:
    image: chrislusf/seaweedfs
    container_name: seaweedfs-s3
    restart: unless-stopped
    ports:
      - "8333:8333"
    command: "s3 -filer=filer:8888"
    depends_on:
      - filer

volumes:
  seaweedfs_data:

INNER_EOF

# 4. Start Services
echo "🚀 Starting services..."
docker compose up -d

echo ""
echo "✅ Deployment Complete!"
echo "👉 Your SeaweedFS stack is running."
echo "   Master UI:  http://localhost:9333"
echo "   S3 API:     http://localhost:8333"
echo "   Filer:      http://localhost:8888"
