#!/bin/bash
# setup.sh — первоначальная настройка на сервере
# Запускать один раз: bash setup.sh
set -e

DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DEPLOY_DIR"

echo "=== [1/4] Загружаем образ в Docker ==="
docker load < breadcrumb-the-shire.tar.gz

echo "=== [2/4] Создаём папки для данных ==="
mkdir -p storage/logs storage/runtime storage/users
mkdir -p var/cache var/log var/tmp
mkdir -p nginx/certs

echo "=== [3/4] Права на папки ==="
chmod 755 storage var
chmod 775 storage/logs storage/runtime storage/users
chmod 775 var/cache var/log var/tmp

echo "=== [4/4] Готово! ==="
echo ""
echo "Следующие шаги:"
echo "  1. Получи SSL-сертификат:"
echo "     certbot certonly --standalone -d projects.breadcrumb-online.de"
echo ""
echo "  2. Скопируй сертификаты:"
echo "     cp /etc/letsencrypt/live/projects.breadcrumb-online.de/fullchain.pem nginx/certs/"
echo "     cp /etc/letsencrypt/live/projects.breadcrumb-online.de/privkey.pem   nginx/certs/"
echo ""
echo "  3. Запусти стек:"
echo "     docker compose up -d"
echo ""
echo "  4. Проверь логи:"
echo "     docker compose logs -f"
