#!/bin/bash
# Gitea Docker Setup Script
# Run with: sudo bash gitea-setup.sh

set -e

echo "Setting up Gitea Docker environment..."

# Create directory structure
echo "Creating /opt/docker/gitea directory..."
mkdir -p /opt/docker/gitea/data

# Copy docker-compose file
echo "Copying docker-compose.yml..."
cp gitea-docker-compose.yml /opt/docker/gitea/docker-compose.yml

# Set correct permissions
echo "Setting permissions..."
chown -R hoborg:hoborg /opt/docker/gitea

# Start Gitea
echo "Starting Gitea container..."
cd /opt/docker/gitea
docker-compose up -d

echo ""
echo "✅ Gitea setup complete!"
echo ""
echo "🌐 Web interface: http://192.168.0.100:3000"
echo "🌍 External access: http://ak-homelab.duckdns.org:3000 (after router port forwarding)"
echo ""
echo "📋 Next steps:"
echo "1. Configure router port forwarding: 3000 → 192.168.0.100:3000"
echo "2. Access web interface to complete initial setup"
echo "3. Configure admin user and repository settings"
echo ""
echo "🔧 Container management:"
echo "  View logs: docker logs gitea"
echo "  Stop:      docker-compose down"
echo "  Update:    docker-compose pull && docker-compose up -d"