From 7e04941bccb2683f8a6e3ee38a99c50129234dd1 Mon Sep 17 00:00:00 2001 From: Lena Date: Thu, 1 Jan 2026 00:00:00 +0000 Subject: rsend: push phone folders to a home SSH host over rsync A small Android app for one-way folder backup, a KISS alternative to Syncthing. It bundles rsync (built from pinned source via the NDK) and a pure-Go SSH transport, both shipped in the APK as lib*.so and run from the native library directory. rsend pins the host key, stores the ed25519 identity Keystore-encrypted, pushes each folder additively or as a mirror, and runs on demand or on a WiFi-only schedule. The build is self-contained and reproducible: make setup provisions the toolchain, make builds rsync, rsh, and the APK. --- rsh/build.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 rsh/build.sh (limited to 'rsh/build.sh') diff --git a/rsh/build.sh b/rsh/build.sh new file mode 100755 index 0000000..88cdf9c --- /dev/null +++ b/rsh/build.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Build the rsh SSH transport for each Android ABI as a Bionic PIE executable +# named lib*.so (packaged inside the APK and exec'd from nativeLibraryDir), +# using the Android NDK. Also build a plain host binary for tests and manual +# debugging. +# +# Android needs PIE and the Bionic dynamic linker (/system/bin/linker64), so +# the on-device build is GOOS=android with cgo and the NDK clang. A GOOS=linux +# build targets glibc's linker and will not exec on a phone. +set -eu + +root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +. "$root/versions" + +# Locate the NDK toolchain. +ndk=${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}} +if [ -z "$ndk" ] && [ -n "${ANDROID_HOME:-}" ]; then + ndk="$ANDROID_HOME/ndk/$ANDROID_NDK" +fi +if [ -z "$ndk" ] || [ ! -d "$ndk" ]; then + echo "rsh: Android NDK not found; set ANDROID_NDK_HOME" >&2 + exit 1 +fi +tc="$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin" + +ldflags="-s -w -buildid=" + +cd "$root/rsh" + +for abi in $ABIS; do + case "$abi" in + arm64-v8a) goarch=arm64 goarm= cc="aarch64-linux-android${ANDROID_MIN_SDK}-clang" ;; + armeabi-v7a) goarch=arm goarm=7 cc="armv7a-linux-androideabi${ANDROID_MIN_SDK}-clang" ;; + x86_64) goarch=amd64 goarm= cc="x86_64-linux-android${ANDROID_MIN_SDK}-clang" ;; + x86) goarch=386 goarm= cc="i686-linux-android${ANDROID_MIN_SDK}-clang" ;; + *) echo "rsh: unknown ABI $abi" >&2; exit 1 ;; + esac + dest="$root/app/src/main/jniLibs/$abi" + mkdir -p "$dest" + echo "rsh: building $abi (android/$goarch)" + CGO_ENABLED=1 GOOS=android GOARCH="$goarch" GOARM="$goarm" \ + CC="$tc/$cc" GOFLAGS=-trimpath CGO_CFLAGS="-ffile-prefix-map=$root=." \ + go build -buildmode=pie -ldflags "$ldflags" -o "$dest/libxrsh.so" . +done + +# Host binary (no NDK, cgo off) for tests and manual debugging. +mkdir -p "$root/out" +echo "rsh: building host binary -> out/rsh" +CGO_ENABLED=0 GOFLAGS=-trimpath go build -ldflags "$ldflags" -o "$root/out/rsh" . -- cgit v1.2.3