#!/bin/bash # =========================================== # Gitea Git LFS Setup Script for dalidou # Server: 192.168.86.50 # =========================================== set -e echo "=== Gitea Git LFS Setup for dalidou ===" echo "" # ----------------------------------------- # Step 1: Find Gitea container and config # ----------------------------------------- echo "[1/5] Finding Gitea container..." GITEA_CONTAINER=$(docker ps --format '{{.Names}}' | grep -i gitea | head -1) if [ -z "$GITEA_CONTAINER" ]; then echo "ERROR: Gitea container not found!" echo "Make sure Gitea is running: docker ps" exit 1 fi echo "Found container: $GITEA_CONTAINER" # ----------------------------------------- # Step 2: Find app.ini location # ----------------------------------------- echo "" echo "[2/5] Locating app.ini..." # Try common locations APP_INI_PATHS=( "/data/gitea/conf/app.ini" "/etc/gitea/app.ini" "/app/gitea/conf/app.ini" ) APP_INI="" for path in "${APP_INI_PATHS[@]}"; do if docker exec "$GITEA_CONTAINER" test -f "$path" 2>/dev/null; then APP_INI="$path" break fi done if [ -z "$APP_INI" ]; then echo "WARNING: Could not find app.ini automatically." echo "Searching inside container..." APP_INI=$(docker exec "$GITEA_CONTAINER" find / -name "app.ini" 2>/dev/null | head -1) fi if [ -z "$APP_INI" ]; then echo "ERROR: app.ini not found!" exit 1 fi echo "Found app.ini at: $APP_INI" # ----------------------------------------- # Step 3: Backup current config # ----------------------------------------- echo "" echo "[3/5] Backing up current configuration..." BACKUP_NAME="app.ini.backup.$(date +%Y%m%d_%H%M%S)" docker exec "$GITEA_CONTAINER" cp "$APP_INI" "${APP_INI}.backup" echo "Backup created: ${APP_INI}.backup" # ----------------------------------------- # Step 4: Check/Enable LFS settings # ----------------------------------------- echo "" echo "[4/5] Checking LFS configuration..." # Check if LFS is already configured if docker exec "$GITEA_CONTAINER" grep -q "LFS_START_SERVER" "$APP_INI"; then echo "LFS_START_SERVER already exists in config" docker exec "$GITEA_CONTAINER" grep "LFS_START_SERVER" "$APP_INI" else echo "LFS not configured. Adding LFS settings..." # Create a temporary script to modify the config docker exec "$GITEA_CONTAINER" sh -c " # Add LFS_START_SERVER to [server] section if not present if grep -q '^\[server\]' '$APP_INI'; then sed -i '/^\[server\]/a LFS_START_SERVER = true' '$APP_INI' fi " echo "Added LFS_START_SERVER = true to [server] section" fi # Check/add [lfs] section if docker exec "$GITEA_CONTAINER" grep -q "^\[lfs\]" "$APP_INI"; then echo "[lfs] section already exists" docker exec "$GITEA_CONTAINER" grep -A5 "^\[lfs\]" "$APP_INI" else echo "Adding [lfs] section..." docker exec "$GITEA_CONTAINER" sh -c " echo '' >> '$APP_INI' echo '[lfs]' >> '$APP_INI' echo 'PATH = /data/lfs' >> '$APP_INI' " echo "Added [lfs] section with PATH = /data/lfs" fi # ----------------------------------------- # Step 5: Create LFS directory and set permissions # ----------------------------------------- echo "" echo "[5/5] Setting up LFS directory..." docker exec "$GITEA_CONTAINER" sh -c " mkdir -p /data/lfs chown -R git:git /data/lfs 2>/dev/null || chown -R 1000:1000 /data/lfs chmod 755 /data/lfs " echo "LFS directory created at /data/lfs" # ----------------------------------------- # Show final configuration # ----------------------------------------- echo "" echo "=== Current LFS Configuration ===" docker exec "$GITEA_CONTAINER" grep -E "(LFS_START_SERVER|^\[lfs\]|^PATH)" "$APP_INI" || true echo "" echo "=== Next Steps ===" echo "1. Restart Gitea to apply changes:" echo " docker restart $GITEA_CONTAINER" echo "" echo "2. Verify LFS is enabled:" echo " docker logs $GITEA_CONTAINER 2>&1 | grep -i lfs" echo "" echo "3. Test from Windows client (see windows-setup.ps1)" echo "" echo "Done!"