fdroid-publish: require a /repo URL and recover from a failed update

fdroidserver refuses a repo_url that doesn't end in /repo, but only at
`fdroid update`, after the APK was already copied in. The leftover APK
then made every retry think that version was published. Check the URL
up front, and take the APK back out if the update fails.

FDROID_REPO_URL now also updates repo_url in an existing repo, instead
of being read only when the repo is created.
This commit is contained in:
2026-10-13 21:29:19 -05:00
parent cec61b886e
commit 348a950489

View File

@@ -15,7 +15,8 @@
#
# Environment:
# MTGC_FDROID_DIR repo directory, if not given as an argument
# FDROID_REPO_URL public address of <dir>/repo; only needed the first time, to create the repo
# FDROID_REPO_URL public address of <dir>/repo, ending in /repo; needed the first time,
# and changes the repo's address if set later
# MTGC_ANDROID_KEYSTORE where --init-keystore puts the key (default ~/.local/share/mtgc/android-release.jks)
#
# Serve <dir>/repo (and <dir>/archive if you like), never <dir> itself: it holds
@@ -25,7 +26,7 @@
set -euo pipefail
usage() {
sed -n '3,23p' "$0" | sed 's/^# \{0,1\}//'
sed -n '3,24p' "$0" | sed 's/^# \{0,1\}//'
exit "${1:-0}"
}
@@ -120,8 +121,14 @@ fi
# --- 4. The repo, the first time --------------------------------------------
repo_url="${FDROID_REPO_URL%/}"
case "$repo_url" in
"" | */repo) ;;
*) err "FDROID_REPO_URL must end in /repo (fdroidserver requires it), e.g. $repo_url/repo"; exit 1 ;;
esac
if [ ! -f "$dir/config.yml" ]; then
if [ -z "${FDROID_REPO_URL:-}" ]; then
if [ -z "$repo_url" ]; then
err "no F-Droid repo in $dir yet; set FDROID_REPO_URL to the address $dir/repo will be served at"
exit 1
fi
@@ -129,7 +136,7 @@ if [ ! -f "$dir/config.yml" ]; then
(cd "$dir" && fdroid init --android-home "$ANDROID_HOME" --no-prompt -q)
cat >>"$dir/config.yml" <<EOF
repo_url: ${FDROID_REPO_URL%/}
repo_url: $repo_url
repo_name: mtgc
repo_description: >-
Releases of mtgc, a personal Magic: The Gathering library catalog.
@@ -138,6 +145,11 @@ EOF
# `fdroid update` copies this into repo/icons/ itself.
cp src-tauri/icons/icon.png "$dir/icon.png"
fi
# A later FDROID_REPO_URL moves the repo to a new address.
if [ -n "$repo_url" ] && ! grep -qxF "repo_url: $repo_url" "$dir/config.yml"; then
info "setting repo_url to $repo_url"
sed -i "s|^repo_url:.*|repo_url: $repo_url|" "$dir/config.yml"
fi
if [ ! -f "$dir/metadata/$APP_ID.yml" ]; then
mkdir -p "$dir/metadata"
@@ -198,9 +210,15 @@ esac
# --- 7. Publish -------------------------------------------------------------
cp "$apk" "$dir/repo/${APP_ID}_${version_code}.apk"
published="$dir/repo/${APP_ID}_${version_code}.apk"
cp "$apk" "$published"
info "updating the repo index"
(cd "$dir" && fdroid update -q)
if ! (cd "$dir" && fdroid update -q); then
# Take the APK back out, or the next run would think it's already published.
rm -f "$published"
err "fdroid update failed; nothing was published"
exit 1
fi
# --- 8. Where to point F-Droid ----------------------------------------------