#!/bin/bash set -e # Define standard storage paths inside our writeable volume DB_PATH="/data/gitea/gitea.db" CONF_DIR="/data/gitea/conf" CONF_PATH="$CONF_DIR/app.ini" # 1. Initialize writeable working directories and hand ownership to the 'git' user mkdir -p "$CONF_DIR" mkdir -p /data/gitea/app_data chown -R git:git /data # 2. Restore SQLite database if it exists in Cloud Storage if [ ! -f "$DB_PATH" ]; then echo "[Litestream] SQLite database not found locally. Checking GCS for replica..." if litestream restore -config /etc/litestream.yml "$DB_PATH"; then echo "[Litestream] Database successfully restored from GCS." chown git:git "$DB_PATH" else echo "[Litestream] No backup replica found. Initializing new database." fi fi # 3. Launch the Litestream background replication process echo "[Litestream] Starting replication backend process..." litestream replicate -config /etc/litestream.yml & # 4. MANUALLY WRITE THE APP.INI CONFIG FILE (Bypasses all Gitea wizards) echo "[Gitea] Writing configuration profile to app.ini..." cat < "$CONF_PATH" APP_NAME = Serverless Git RUN_MODE = prod RUN_USER = git [database] DB_TYPE = sqlite3 PATH = $DB_PATH [security] INSTALL_LOCK = true [server] HTTP_PORT = 3000 PROTOCOL = http [repository] ROOT = /data/gitea/app_data/repositories EOF # Ensure the config file is fully readable and writeable by the git user chown git:git "$CONF_PATH" # 5. Drop Root Privileges and boot the Gitea Web server pointing to our manual config echo "[Gitea] Dropping privileges to 'git' user and booting web service core..." exec su git -c "/app/gitea/gitea web --config $CONF_PATH --port 3000"