Files
julian 64b2588dd2 Move docker creation over to devenv
This is not ideal, since devenv is more for creating development
environments, but it works
2026-06-13 14:55:37 +02:00

79 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# ==========================================
# CONFIGURATION
# ==========================================
GITEA_URL="https://gitlab.julian-mutter.de"
REPO_OWNER="julian"
REPO_NAME="sheetless"
APP_NAME="de.frajul.sheetless"
TARGET_ASSET_NAME="app-release.apk"
FDROID_REPO_DIR="./fdroid/repo"
FDROID_ARCHIVE_DIR="./fdroid/archive"
# ==========================================
# SETUP & API CALL
# ==========================================
mkdir -p "$FDROID_REPO_DIR"
API_URL="${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases"
echo "Fetching releases from Gitea..."
RELEASES_JSON=$(curl -sL "$API_URL")
# Check if Gitea returned a valid JSON array
if ! echo "$RELEASES_JSON" | jq -e 'type == "array"' >/dev/null; then
echo "Error: Failed to fetch releases. Check your URL, Repo names, or Token."
exit 1
fi
# ==========================================
# SYNC LOGIC
# ==========================================
UPDATE_TRIGGERED=false
echo "Processing versioned releases for asset: $TARGET_ASSET_NAME"
# Single jq command to:
# 1. Ignore "latest" releases
# 2. Extract ONLY the matching asset URL
# 3. Output as Tab-Separated Values (TSV) for safe bash reading
while IFS=$'\t' read -r TAG DOWNLOAD_URL; do
# Skip empty lines if jq returns nothing
[[ -z "$TAG" ]] && continue
LOCAL_FILE="$FDROID_REPO_DIR/${APP_NAME}_${TAG}.apk"
ARCHIVE_FILE="$FDROID_ARCHIVE_DIR/${APP_NAME}_${TAG}.apk"
echo "Checking release: $TAG..."
if [[ -f "$LOCAL_FILE" ]]; then
echo " -> Already exists locally. Skipping."
else
echo " -> Downloading new version: $LOCAL_FILE"
curl -sL -o "$LOCAL_FILE" "$DOWNLOAD_URL"
UPDATE_TRIGGERED=true
fi
# Feed the jq output into the loop from the bottom
done < <(echo "$RELEASES_JSON" | jq -r --arg target "$TARGET_ASSET_NAME" '
.[]
| select(.tag_name != "latest")
| .tag_name as $tag
| .assets[]
| select(.name == $target)
| "\($tag)\t\(.browser_download_url)"
')
if [ "$UPDATE_TRIGGERED" = true ]; then
echo "Sync complete. New updates were downloaded."
exit 10
else
echo "Sync complete. No new updates found."
exit 0
fi