#!/bin/bash

# Z.CRM Server Deployment Script
# Run this script ON THE SERVER

set -e

echo "🚀 Z.CRM Deployment Starting..."

# Install Docker if not installed
if ! command -v docker &> /dev/null; then
    echo "📦 Installing Docker..."
    curl -fsSL https://get.docker.com -o get-docker.sh
    sh get-docker.sh
    systemctl enable docker
    systemctl start docker
    rm get-docker.sh
fi

# Install Docker Compose if not installed
if ! command -v docker-compose &> /dev/null; then
    echo "📦 Installing Docker Compose..."
    curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
fi

# Create app directory
APP_DIR="/opt/zerp"
mkdir -p $APP_DIR
cd $APP_DIR

echo "✅ Prerequisites installed"
echo ""
echo "📋 Next steps:"
echo "1. Copy your project files to $APP_DIR"
echo "2. Create .env file with production values"
echo "3. Run: docker-compose up -d"
echo ""
echo "🎉 Setup complete!"
