#!/bin/bash
set -e

# Read from env
ADMIN_USER="${GITEA_ADMIN_USER:-daywave}"
ADMIN_PASS="${GITEA_ADMIN_PASS:-daywavedaywave}"
ADMIN_EMAIL="${GITEA_ADMIN_EMAIL:-day@wave.ru}"
SERVICES_DIR="${GITEA_SERVICES_DIR:-./services}"

echo "[*] Using environment:"
echo "  ADMIN_USER=$ADMIN_USER"
echo "  ADMIN_EMAIL=$ADMIN_EMAIL"
echo "  SERVICES_DIR=$SERVICES_DIR"

# Use variables normally
/usr/local/bin/gitea admin user create \
  --username "$ADMIN_USER" \
  --password "$ADMIN_PASS" \
  --email "$ADMIN_EMAIL" \
  --admin

for dir in "$SERVICES_DIR"/*/; do
  repo_name=$(basename "$dir")
  /usr/local/bin/gitea admin repo create \
    --owner "$ADMIN_USER" \
    --name "$repo_name" \
    --private
done
