Three-layer access scheme: owner -> reader account -> scoped API token. Includes 6 automation scripts, config template, EN/RU docs, and manual curl guide. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
42 lines
1.1 KiB
Bash
Executable File
42 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
CONFIG="${1:-$SCRIPT_DIR/../config.ini}"
|
|
|
|
if [[ ! -f "$CONFIG" ]]; then
|
|
echo "ERROR: config file not found: $CONFIG"
|
|
exit 1
|
|
fi
|
|
|
|
# --- Parse INI ---
|
|
parse_ini() {
|
|
local file="$1" section="$2" key="$3"
|
|
sed -n "/^\[$section\]/,/^\[/p" "$file" | grep "^${key}\s*=" | head -1 | sed 's/^[^=]*=\s*//' | sed 's/\s*$//'
|
|
}
|
|
|
|
GITEA_API=$(parse_ini "$CONFIG" gitea api_url)
|
|
READER_USER=$(parse_ini "$CONFIG" reader username)
|
|
TOKEN=$(parse_ini "$CONFIG" reader token)
|
|
|
|
if [[ -z "$TOKEN" ]]; then
|
|
echo "ERROR: No token found in config.ini. Run setup-reader.sh first."
|
|
exit 1
|
|
fi
|
|
|
|
echo "=== Repositories accessible by '$READER_USER' ==="
|
|
echo ""
|
|
|
|
REPOS=$(curl -s \
|
|
-H "Authorization: token $TOKEN" \
|
|
"$GITEA_API/user/repos?limit=50")
|
|
|
|
# Parse JSON with grep/sed (no jq dependency)
|
|
echo "$REPOS" | grep -o '"full_name":"[^"]*"' | sed 's/"full_name":"//;s/"//' | while read -r repo; do
|
|
echo " - $repo"
|
|
done
|
|
|
|
COUNT=$(echo "$REPOS" | grep -o '"full_name":"[^"]*"' | wc -l)
|
|
echo ""
|
|
echo "Total: $COUNT repositories"
|