diff --git a/scripts/fdroid-publish.sh b/scripts/fdroid-publish.sh
index 8fcc0a6..f053c0f 100755
--- a/scripts/fdroid-publish.sh
+++ b/scripts/fdroid-publish.sh
@@ -15,7 +15,8 @@
#
# Environment:
# MTGC_FDROID_DIR repo directory, if not given as an argument
-# FDROID_REPO_URL public address of
/repo; only needed the first time, to create the repo
+# FDROID_REPO_URL public address of /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 /repo (and /archive if you like), never 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" <-
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 ----------------------------------------------