2476667510
The owner copies infra/pi/ to the Kvitt Pi and runs it there (D-100); nothing
on the Mac connects to the Pis. compose stack of SPEC §10.2 with images
${KVITT_REGISTRY}/kvitt-{server,cert-sync,backup}, Caddyfile §10.5.2 verbatim,
.env.example with the OQ-3 values as CHANGE_ME placeholders, install.sh,
deploy.sh (backup before every deploy), bootstrap.sh, backup-now.sh,
install-apk.sh. cert-sync image and sync.sh (§10.5.1, tar stream for both
authorized_keys variants); backup.sh uploads with rclone copy --immutable and
deletes local files once both are confirmed on Drive (D-002); both sidecars
schedule with supercronic because busybox crond runs no jobs as non-root;
backup runs as uid 10001. .gitea/workflows/build-images.yaml from the owner's
example (not yet run); infra/build-images.sh and infra/publish-apk.sh (R8
mapping kept, version per §10.6) on the Mac; README checklist and RESTORE.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B
86 lines
4.2 KiB
Bash
Executable File
86 lines
4.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build the release APK on the Mac and stage it for the Pi (SPEC §10.6, D-100).
|
|
# Usage, from the main checkout: infra/publish-apk.sh
|
|
# 1. refuses a dirty working tree (the version is derived from HEAD)
|
|
# 2. version (SPEC §10.6): version_code = `git rev-list --count HEAD`, version_name = YYYY.MM.DD-<short sha> of
|
|
# HEAD's commit date (Europe/Stockholm), passed as -Pkvitt.versionCode / -Pkvitt.versionName
|
|
# 3. :app:assembleRelease through tools/gradle-serial.sh (JDK 25 from Homebrew on PATH, JAVA_HOME untouched)
|
|
# 4. writes into infra/pi/out/apk/: kvitt-<version_code>.apk, kvitt-<version_code>.mapping.txt (R8 mapping, for
|
|
# reading stack traces; never served), and latest.json (written to a temp file, then renamed)
|
|
# 5. keeps the newest 5 APKs (and their mappings) in infra/pi/out/apk/
|
|
# Then the owner copies the folder to the Pi and runs /opt/kvitt/install-apk.sh there (infra/README.md).
|
|
# Refuses an unsigned build: without the kvitt.release.* keys in android/local.properties the APK cannot be
|
|
# installed over an earlier release (D-024, D-101).
|
|
set -euo pipefail
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$repo_root"
|
|
|
|
[[ -z "$(git status --porcelain)" ]] || { echo "publish-apk.sh: the working tree is dirty; commit or stash first." >&2; exit 1; }
|
|
|
|
version_code="$(git rev-list --count HEAD)"
|
|
short_sha="$(git rev-parse --short=7 HEAD)"
|
|
commit_day="$(TZ=Europe/Stockholm git show -s --date=format-local:%Y.%m.%d --format=%cd HEAD)"
|
|
version_name="$commit_day-$short_sha"
|
|
echo "Release $version_name (version_code $version_code)"
|
|
|
|
PATH="/opt/homebrew/opt/openjdk@25/bin:$PATH" tools/gradle-serial.sh :app:assembleRelease \
|
|
"-Pkvitt.versionCode=$version_code" "-Pkvitt.versionName=$version_name"
|
|
|
|
out_dir="$repo_root/android/app/build/outputs/apk/release"
|
|
apk="$out_dir/app-release.apk"
|
|
mapping="$repo_root/android/app/build/outputs/mapping/release/mapping.txt"
|
|
if [[ ! -f "$apk" ]]; then
|
|
if [[ -f "$out_dir/app-release-unsigned.apk" ]]; then
|
|
echo "publish-apk.sh: the build is unsigned (no kvitt.release.* keys in android/local.properties); not published." >&2
|
|
else
|
|
echo "publish-apk.sh: no APK in $out_dir" >&2
|
|
fi
|
|
exit 1
|
|
fi
|
|
# The APK must be the one just built: output-metadata.json carries the version code Gradle used.
|
|
python3 - "$out_dir/output-metadata.json" "$version_code" <<'PY'
|
|
import json, sys
|
|
meta = json.load(open(sys.argv[1]))
|
|
codes = {str(e.get("versionCode")) for e in meta.get("elements", [])}
|
|
if sys.argv[2] not in codes:
|
|
sys.exit(f"publish-apk.sh: output-metadata.json has version codes {sorted(codes)}, expected {sys.argv[2]}")
|
|
PY
|
|
[[ -f "$mapping" ]] || { echo "publish-apk.sh: no R8 mapping at $mapping" >&2; exit 1; }
|
|
|
|
dest="$repo_root/infra/pi/out/apk"
|
|
mkdir -p "$dest"
|
|
file_name="kvitt-$version_code.apk"
|
|
cp "$apk" "$dest/.$file_name.tmp" && mv -f "$dest/.$file_name.tmp" "$dest/$file_name"
|
|
cp "$mapping" "$dest/kvitt-$version_code.mapping.txt"
|
|
size_bytes="$(wc -c < "$dest/$file_name" | tr -d ' ')"
|
|
sha256="$(shasum -a 256 "$dest/$file_name" | cut -d' ' -f1)"
|
|
released_at="$(python3 -c 'import datetime; t=datetime.datetime.now(datetime.timezone.utc); print(t.strftime("%Y-%m-%dT%H:%M:%S.") + f"{t.microsecond // 1000:03d}Z")')"
|
|
|
|
tmp="$(mktemp "$dest/.latest.json.XXXXXX")"
|
|
cat > "$tmp" <<JSON
|
|
{
|
|
"version_code": $version_code,
|
|
"version_name": "$version_name",
|
|
"file_name": "$file_name",
|
|
"size_bytes": $size_bytes,
|
|
"sha256": "$sha256",
|
|
"released_at": "$released_at"
|
|
}
|
|
JSON
|
|
chmod 0644 "$tmp"
|
|
mv -f "$tmp" "$dest/latest.json"
|
|
|
|
# Keep the newest 5 APKs by version code, with their mappings.
|
|
for f in "$dest"/kvitt-*.apk; do
|
|
[[ -f "$f" ]] || continue
|
|
basename "$f" | sed -n 's/^kvitt-\([0-9]*\)\.apk$/\1/p'
|
|
done | sort -n -r | tail -n +6 | while read -r old; do
|
|
rm -f "$dest/kvitt-$old.apk" "$dest/kvitt-$old.mapping.txt"
|
|
echo "removed kvitt-$old.apk and its mapping"
|
|
done
|
|
|
|
echo "Staged in infra/pi/out/apk/: $file_name ($size_bytes bytes, sha256 $sha256) and latest.json."
|
|
echo "Copy to the Pi and install (infra/README.md, Publishing an APK):"
|
|
echo " scp infra/pi/out/apk/latest.json infra/pi/out/apk/$file_name infra/pi/out/apk/kvitt-$version_code.mapping.txt <ssh user>@<Kvitt Pi address>:/opt/kvitt/apk/"
|
|
echo " ssh <ssh user>@<Kvitt Pi address> /opt/kvitt/install-apk.sh"
|