Newer
Older
navi-1 / android-client / tools / publish-apk.sh
#!/usr/bin/env bash
# Build the signed release APK and publish it for download from the web client.
#
#   ./tools/publish-apk.sh
#
# The APK lands in the webclient's public directory, which the backend serves
# at /download/ (see navi/main.py) — so it ships with the next git pull on the
# server, exactly like the icons do. The JSON next to it is what the App
# settings panel reads, so the version and checksum on that page can never
# drift from the file the user actually downloads.
set -euo pipefail

cd "$(dirname "$0")/.."
DEST="../webclient/public/download"
APK="app/build/outputs/apk/release/app-release.apk"

if [ ! -f keystore.properties ]; then
    echo "keystore.properties отсутствует — APK будет неподписанным." >&2
    echo "См. комментарий в app/build.gradle.kts." >&2
    exit 1
fi

./gradlew --quiet assembleRelease

mkdir -p "$DEST"
cp "$APK" "$DEST/navi-android.apk"

version_code=$(grep -m1 'versionCode' app/build.gradle.kts | tr -dc '0-9')
version_name=$(grep -m1 'versionName' app/build.gradle.kts | sed -E 's/.*"([^"]+)".*/\1/')
size=$(stat -c%s "$DEST/navi-android.apk")
sha=$(sha256sum "$DEST/navi-android.apk" | cut -d' ' -f1)

printf '{\n  "versionCode": %s,\n  "versionName": "%s",\n  "size": %s,\n  "sha256": "%s",\n  "builtAt": "%s"\n}\n' \
    "$version_code" "$version_name" "$size" "$sha" "$(date -Iseconds)" \
    > "$DEST/navi-android.json"

echo "Готово: $DEST/navi-android.apk ($((size / 1024)) КиБ, версия $version_name)"
echo "Не забудьте пересобрать webclient и закоммитить оба файла."