#!/bin/bash # Automated Gitea Setup via API # This script attempts to configure Gitea programmatically set -euo pipefail GITEA_IP="${GITEA_IP:-192.168.1.121}" GITEA_URL="http://${GITEA_IP}:3000" ADMIN_USER="${ADMIN_USER:-admin}" ADMIN_EMAIL="${ADMIN_EMAIL:-admin@hc-stack.local}" ADMIN_PASSWORD="${ADMIN_PASSWORD:-admin123}" echo "=== Automated Gitea Setup ===" echo "" # Check if Gitea is already configured echo "Checking Gitea status..." STATUS=$(curl -s "${GITEA_URL}/api/v1/version" 2>&1 || echo "not_ready") if echo "$STATUS" | grep -q "version"; then echo "✓ Gitea is already configured" echo "Access: ${GITEA_URL}" exit 0 fi echo "Gitea needs initial setup. Attempting automated configuration..." echo "" # Try to configure via setup API SETUP_RESPONSE=$(curl -s -X POST "${GITEA_URL}/api/v1/setup" \ -H "Content-Type: application/json" \ -d "{ \"db_type\": \"postgres\", \"db_host\": \"db:5432\", \"db_user\": \"gitea\", \"db_passwd\": \"gitea\", \"db_name\": \"gitea\", \"ssl_mode\": \"disable\", \"repo_root_path\": \"/data/git/repositories\", \"lfs_root_path\": \"/data/git/lfs\", \"log_root_path\": \"/data/gitea/log\", \"run_user\": \"git\", \"domain\": \"${GITEA_IP}\", \"ssh_port\": 2222, \"http_port\": 3000, \"app_name\": \"Gitea\", \"enable_federated_avatar\": false, \"enable_open_id_sign_in\": false, \"enable_open_id_sign_up\": false, \"default_allow_create_organization\": true, \"default_enable_timetracking\": true, \"no_reply_address\": \"noreply.hc-stack.local\", \"admin_name\": \"${ADMIN_USER}\", \"admin_email\": \"${ADMIN_EMAIL}\", \"admin_passwd\": \"${ADMIN_PASSWORD}\", \"admin_confirm_passwd\": \"${ADMIN_PASSWORD}\" }" 2>&1) if echo "$SETUP_RESPONSE" | grep -q "success\|created"; then echo "✓ Gitea configured successfully!" echo "" echo "Access: ${GITEA_URL}" echo "Username: ${ADMIN_USER}" echo "Password: ${ADMIN_PASSWORD}" echo "" echo "⚠️ Please change the default password after first login" else echo "⚠️ Automated setup failed or Gitea requires manual configuration" echo "" echo "Please complete setup manually:" echo "1. Open: ${GITEA_URL}" echo "2. Complete the installation form" echo "3. Use the following settings:" echo " - Database Type: PostgreSQL" echo " - Database Host: db:5432" echo " - Database User: gitea" echo " - Database Password: gitea" echo " - Database Name: gitea" echo " - Repository Root: /data/git/repositories" echo " - SSH Server Domain: ${GITEA_IP}" echo " - SSH Port: 2222" echo " - HTTP Port: 3000" echo " - Gitea Base URL: ${GITEA_URL}" echo "" echo "Response: $SETUP_RESPONSE" fi