forked from Blendman974/faceclaw
Unify Android and iOS config formats
This commit is contained in:
1 parent
35a4ae7064
commit
210b111e27
18 files changed
+1116
-427
No files matched your search
+52
-29
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
# Pull faceclaw's shared preferences off the attached device.
|
||||
# Export faceclaw's settings from the attached Android device as a JSON config
|
||||
# document (the same format as pull_config_ios.sh; see config-transfer.md).
|
||||
# Usage: pull_config.sh [output-file] [-f output-file] [adb-options...]
|
||||
#
|
||||
# Uses run-as on debuggable (dev) builds. On release builds, where run-as is
|
||||
# refused, falls back to the FaceclawSettingsPortReceiver broadcast, which
|
||||
# copies the settings file into the app's external files dir for adb to pull
|
||||
# (and which only the adb shell can trigger; see the receiver's javadoc).
|
||||
# The app's FaceclawSettingsPortReceiver writes the document into its external
|
||||
# files dir for adb to pull. Only the adb shell can trigger it (see the
|
||||
# receiver's javadoc), and it works on release builds, where run-as is refused.
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd "$(dirname "$0")" && pwd)/adbutil.sh"
|
||||
@@ -14,10 +14,12 @@ usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [output-file] [-f output-file] [adb-options...]
|
||||
|
||||
Pull faceclaw's shared preferences off the attached device into output-file
|
||||
(default: faceclaw_settings.xml). The output file may be given as a bare
|
||||
first argument or with -f anywhere. Any other arguments are passed through
|
||||
to adb, e.g. -s SERIAL or -t ID to pick one of several attached devices.
|
||||
Export faceclaw's settings from the attached device into output-file
|
||||
(default: faceclaw_settings.android.json), readable only by you. The output
|
||||
file may be given as a bare first argument or with -f anywhere. Any other
|
||||
arguments are passed through to adb, e.g. -s SERIAL or -t ID to pick one of
|
||||
several attached devices. Push the file to Android or iOS with push_config.sh
|
||||
or push_config_ios.sh.
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -28,26 +30,47 @@ if [ "$ADBUTIL_HELP" = 1 ]; then
|
||||
fi
|
||||
|
||||
PACKAGE=com.faceclaw.app
|
||||
PREFS=shared_prefs/faceclaw_settings.xml
|
||||
OUT="${ADBUTIL_FILE:-faceclaw_settings.xml}"
|
||||
EXPORT_REMOTE=/sdcard/Android/data/$PACKAGE/files/faceclaw-settings-export.xml
|
||||
OUT="${ADBUTIL_FILE:-faceclaw_settings.android.json}"
|
||||
EXPORT_REMOTE=/sdcard/Android/data/$PACKAGE/files/faceclaw-settings-export.json
|
||||
|
||||
MODE="$(adb_preflight "$PACKAGE")"
|
||||
|
||||
if [ "$MODE" = debug ]; then
|
||||
adb exec-out run-as "$PACKAGE" cat "$PREFS" > "$OUT"
|
||||
echo "Pulled $PREFS to $OUT"
|
||||
else
|
||||
echo "Release build installed; using settings-port broadcast..."
|
||||
RESULT="$(adb shell am broadcast -n "$PACKAGE/.FaceclawSettingsPortReceiver" \
|
||||
-a com.faceclaw.app.SETTINGS_EXPORT)"
|
||||
if ! printf '%s' "$RESULT" | grep -q 'data="exported:'; then
|
||||
printf '%s\n' "$RESULT" >&2
|
||||
echo "Error: export broadcast did not report success (old app version?)" >&2
|
||||
case "$OUT" in
|
||||
*.xml|*.XML)
|
||||
echo "Error: configs are exported as JSON; choose a .json filename" >&2
|
||||
exit 1
|
||||
fi
|
||||
adb pull "$EXPORT_REMOTE" "$OUT" >/dev/null
|
||||
# The export contains API tokens; don't leave it sitting on shared storage.
|
||||
adb shell rm "$EXPORT_REMOTE"
|
||||
echo "Pulled $PREFS to $OUT (via settings-port export)"
|
||||
;;
|
||||
esac
|
||||
|
||||
adb_preflight "$PACKAGE" >/dev/null
|
||||
|
||||
export_broadcast() {
|
||||
adb shell am broadcast --include-stopped-packages \
|
||||
-n "$PACKAGE/.FaceclawSettingsPortReceiver" -a com.faceclaw.app.SETTINGS_EXPORT
|
||||
}
|
||||
RESULT="$(export_broadcast)"
|
||||
if ! printf '%s' "$RESULT" | grep -q 'data='; then
|
||||
# No reply at all: the broadcast reached a process that was exiting (the
|
||||
# app exits just after an import). Try once more in a fresh one.
|
||||
adb shell sleep 1
|
||||
RESULT="$(export_broadcast)"
|
||||
fi
|
||||
if ! printf '%s' "$RESULT" | grep -q 'data="exported: .*\.json"'; then
|
||||
printf '%s\n' "$RESULT" >&2
|
||||
echo "Error: export broadcast did not report a JSON export (app predates JSON configs?)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The export contains API tokens: keep it private locally, and don't leave it
|
||||
# sitting on shared storage.
|
||||
umask 077
|
||||
TMP="$(mktemp "$OUT.XXXXXX")"
|
||||
trap 'rm -f "$TMP"' EXIT
|
||||
if ! OUTPUT="$(adb pull "$EXPORT_REMOTE" "$TMP" 2>&1)"; then
|
||||
adb shell rm -f "$EXPORT_REMOTE"
|
||||
printf '%s\n' "$OUTPUT" >&2
|
||||
echo "Error: could not pull $EXPORT_REMOTE" >&2
|
||||
exit 1
|
||||
fi
|
||||
adb shell rm -f "$EXPORT_REMOTE"
|
||||
mv "$TMP" "$OUT"
|
||||
trap - EXIT
|
||||
echo "Pulled settings to $OUT (mode 600)"
|
||||
Reference in new issue
Block a user