Add Android client, packaging, Makefile entrypoint and handover docs

Why: the set has to be installable and publishable, not just buildable, and
the next person needs the reasoning, not only the code.

What:
- android/: Kotlin client with no third-party dependencies. A
  DocumentsProvider publishes the mirrored databases to every file picker, so
  KeePassDX opens them as ordinary documents; closing a file it wrote
  triggers a sync. A foreground service holds the event stream open.
  Mirror.decide transcribes the Go merge table, so both platforms resolve a
  conflict identically.
- Makefile as the single entrypoint, with file targets so only what changed
  is rebuilt: host and cross builds, both .deb packages, the macOS DMG with
  its /Applications symlink, the Windows zip, the APK under its F-Droid
  publishing name, and manual-only android-publish.
- versions.mk holds one version per platform plus the Android versionCode;
  `make bump` and `make changelog` move them. Debian changelog is tracked.
- systemd units (hardened system unit for the server, user unit for the
  agent), macOS bundle and launch agent, Windows Task Scheduler job.
- docs/HANDOVER.md on architecture and every decision that shaped it,
  docs/PROTOCOL.md for the API, README for the quick start.

Proved: make check and make test-race both pass; built both .deb packages and
inspected their contents, built the Windows zip, cross-compiled all five
desktop targets, and exercised make bump. The Android module is written but
not compiled: no JDK or Android SDK in this environment, which HANDOVER.md
states plainly.
This commit is contained in:
2026-10-29 16:26:33 +01:00
parent 4d0d53ff04
commit 0e83acb9b1
40 changed files with 2563 additions and 24 deletions
+83
View File
@@ -0,0 +1,83 @@
#!/bin/sh
# Build one Debian package.
# build-deb.sh <client|server> <version> <arch> <output.deb>
set -eu
kind=$1
version=$2
arch=$3
out=$4
root=$(cd "$(dirname "$0")/.." && pwd)
stage=$root/build/deb-$kind-$arch
rm -rf "$stage"
case $kind in
client)
pkg=keeporg
binary=keeporg
mkdir -p "$stage/usr/bin" "$stage/usr/lib/systemd/user"
install -m 0755 "$root/build/linux-$arch/keeporg" "$stage/usr/bin/keeporg"
install -m 0644 "$root/packaging/systemd/keeporg.service" \
"$stage/usr/lib/systemd/user/keeporg.service"
;;
server)
pkg=keeporgd
binary=keeporgd
mkdir -p "$stage/usr/bin" "$stage/usr/lib/systemd/system" "$stage/etc/keeporg"
install -m 0755 "$root/build/linux-$arch/keeporgd" "$stage/usr/bin/keeporgd"
install -m 0644 "$root/packaging/systemd/keeporgd.service" \
"$stage/usr/lib/systemd/system/keeporgd.service"
"$root/build/linux-$arch/keeporgd" -write-config "$stage/etc/keeporg/server.json" >/dev/null
chmod 0640 "$stage/etc/keeporg/server.json"
;;
*)
echo "build-deb.sh: unknown package kind $kind" >&2
exit 2
;;
esac
mkdir -p "$stage/DEBIAN" "$stage/usr/share/doc/$pkg"
sed -e "s/@VERSION@/$version/" -e "s/@ARCH@/$arch/" \
"$root/packaging/deb/$kind/control.in" > "$stage/DEBIAN/control"
install -m 0644 "$root/packaging/deb/copyright" "$stage/usr/share/doc/$pkg/copyright"
gzip -9nc "$root/packaging/deb/changelog" > "$stage/usr/share/doc/$pkg/changelog.Debian.gz"
chmod 0644 "$stage/usr/share/doc/$pkg/changelog.Debian.gz"
if [ "$kind" = server ]; then
cat > "$stage/DEBIAN/conffiles" <<'CONF'
/etc/keeporg/server.json
CONF
cat > "$stage/DEBIAN/postinst" <<'POST'
#!/bin/sh
set -e
if [ "$1" = configure ]; then
if ! getent passwd keeporg >/dev/null; then
adduser --system --group --home /var/lib/keeporg \
--gecos "KeepOrg synchronization server" keeporg
fi
install -d -o keeporg -g keeporg -m 0700 /var/lib/keeporg
chgrp keeporg /etc/keeporg/server.json || true
chmod 0640 /etc/keeporg/server.json || true
if [ -d /run/systemd/system ]; then
systemctl daemon-reload || true
echo "keeporgd: edit /etc/keeporg/server.json, then" \
"systemctl enable --now keeporgd" >&2
fi
fi
exit 0
POST
cat > "$stage/DEBIAN/prerm" <<'PRERM'
#!/bin/sh
set -e
if [ "$1" = remove ] && [ -d /run/systemd/system ]; then
systemctl stop keeporgd || true
fi
exit 0
PRERM
chmod 0755 "$stage/DEBIAN/postinst" "$stage/DEBIAN/prerm"
fi
mkdir -p "$(dirname "$out")"
fakeroot dpkg-deb --root-owner-group --build "$stage" "$out" >/dev/null
printf 'built %s (%s %s %s)\n' "$out" "$binary" "$version" "$arch"
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
# Build the macOS disk image: an application bundle beside a symlink to
# /Applications, which is what a user expects to drag.
# build-dmg.sh <version> <arch> <appid> <output.dmg>
set -eu
version=$1
arch=$2
appid=$3
out=$4
if [ "$(uname -s)" != Darwin ]; then
echo "build-dmg.sh: a DMG can only be built on macOS (hdiutil is required)" >&2
echo "the binary itself cross-compiles: make build/darwin-$arch/keeporg" >&2
exit 1
fi
root=$(cd "$(dirname "$0")/.." && pwd)
stage=$root/build/dmg-$arch
app=$stage/KeepOrg.app
rm -rf "$stage"
mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
install -m 0755 "$root/build/darwin-$arch/keeporg" "$app/Contents/MacOS/keeporg"
sed -e "s/@VERSION@/$version/" -e "s/@APPID@/$appid/" \
"$root/packaging/macos/Info.plist.in" > "$app/Contents/Info.plist"
install -m 0755 "$root/packaging/macos/launcher.sh" "$app/Contents/MacOS/KeepOrg"
sed -e "s/@APPID@/$appid/" "$root/packaging/macos/launch-agent.plist.in" \
> "$app/Contents/Resources/$appid.plist"
cp "$root/docs/HANDOVER.md" "$stage/Read me first.md" 2>/dev/null || true
# The symlink every macOS DMG carries, so installing is one drag.
ln -s /Applications "$stage/Applications"
mkdir -p "$(dirname "$out")"
rm -f "$out"
hdiutil create -volname "KeepOrg $version" -srcfolder "$stage" \
-ov -fs HFS+ -format UDZO "$out" >/dev/null
printf 'built %s\n' "$out"
+54
View File
@@ -0,0 +1,54 @@
#!/bin/sh
# Bump one platform's semantic version in versions.mk.
# bump.sh <server|linux|macos|windows|bsd|android|all> <major|minor|patch>
# Bumping android also increments its monotonic versionCode.
set -eu
platform=${1:-}
part=${2:-patch}
root=$(cd "$(dirname "$0")/.." && pwd)
file=$root/versions.mk
case $platform in
server|linux|macos|windows|bsd|android|all) ;;
*)
echo "usage: make bump PLATFORM=<server|linux|macos|windows|bsd|android|all> PART=<major|minor|patch>" >&2
exit 2
;;
esac
case $part in
major|minor|patch) ;;
*)
echo "bump.sh: PART must be major, minor or patch" >&2
exit 2
;;
esac
bump_one() {
key=VERSION_$(echo "$1" | tr 'a-z' 'A-Z')
current=$(sed -n "s/^$key[[:space:]]*:=[[:space:]]*\([0-9.]*\).*/\1/p" "$file")
[ -n "$current" ] || { echo "bump.sh: $key not found in versions.mk" >&2; exit 1; }
major=$(echo "$current" | cut -d. -f1)
minor=$(echo "$current" | cut -d. -f2)
patch=$(echo "$current" | cut -d. -f3)
case $part in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
next=$major.$minor.$patch
sed -i.bak "s/^$key[[:space:]]*:=.*/$(printf '%-16s := %s' "$key" "$next")/" "$file"
printf '%s %s -> %s\n' "$1" "$current" "$next"
if [ "$1" = android ]; then
code=$(sed -n 's/^ANDROID_VERSION_CODE[[:space:]]*:=[[:space:]]*\([0-9]*\).*/\1/p' "$file")
sed -i.bak "s/^ANDROID_VERSION_CODE[[:space:]]*:=.*/ANDROID_VERSION_CODE := $((code + 1))/" "$file"
printf 'android versionCode %s -> %s\n' "$code" "$((code + 1))"
fi
}
if [ "$platform" = all ]; then
for p in server linux macos windows bsd android; do bump_one "$p"; done
else
bump_one "$platform"
fi
rm -f "$file.bak"
+26
View File
@@ -0,0 +1,26 @@
#!/bin/sh
# Prepend an entry to the Debian changelog.
# changelog.sh <version> "what changed"
set -eu
version=${1:-}
message=${2:-}
root=$(cd "$(dirname "$0")/.." && pwd)
file=$root/packaging/deb/changelog
if [ -z "$version" ] || [ -z "$message" ]; then
echo 'usage: make changelog MSG="what changed"' >&2
exit 2
fi
author=${DEBFULLNAME:-tiredsysadmin}
email=${DEBEMAIL:-rcmd@garage.rcmd.space}
tmp=$(mktemp)
{
printf 'keeporg (%s) unstable; urgency=medium\n\n' "$version"
printf ' * %s\n\n' "$message"
printf ' -- %s <%s> %s\n\n' "$author" "$email" "$(date -R)"
cat "$file"
} > "$tmp"
mv "$tmp" "$file"
printf 'added %s to %s\n' "$version" "$file"