From e43eb1177872f52e949fb5f0f93396ed94b0d093 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 2 Aug 2026 14:48:29 +0200 Subject: move to chezmoi --- .../share/bin/executable_androidwifistore2pass | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 home/dot_local/share/bin/executable_androidwifistore2pass (limited to 'home/dot_local/share/bin/executable_androidwifistore2pass') diff --git a/home/dot_local/share/bin/executable_androidwifistore2pass b/home/dot_local/share/bin/executable_androidwifistore2pass new file mode 100644 index 0000000..b03eb9d --- /dev/null +++ b/home/dot_local/share/bin/executable_androidwifistore2pass @@ -0,0 +1,43 @@ +#!/bin/sh +# Use xmlstarlet and ADB to pull WifiConfigStore.xml from a (rooted) Android +# phone and import wifi network passwords into pass. Tested with a rooted pixel +# 4a (sunfish) running LineageOS 21 (Android 14) + +TAB="$(printf '\t')" + +get_wifi_cfg() { + adb shell cat /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml + if [ $? -ne 0 ] ; then + echo "note: try running \`adb root\` first" + exit 1 + fi +} + +parse_filter() { + xmlstarlet select --template \ + --match '/WifiConfigStoreData/NetworkList/Network' \ + --if './WifiConfiguration/string[@name="PreSharedKey"]' \ + --value-of './WifiConfiguration/string[@name="SSID"]' \ + --output "$TAB" \ + --value-of './WifiConfiguration/string[@name="PreSharedKey"]' \ + --nl +} + +cut_quotes() { + cut -c2- | rev | cut -c2- | rev +} + +import_pass() { + while read line; do + SSID="$(echo "$line" | cut -d"$TAB" -f1 | cut_quotes)" + PASSWD="$(echo "$line" | cut -d"$TAB" -f2 | cut_quotes)" + PASS_NAME="net/$(echo "$SSID" | tr '/' '-')/passwd" + + printf 'insert SSID "%s" as %s ...' "$SSID" "$PASS_NAME" + echo "$PASSWD" | pass insert --multiline "$PASS_NAME" 1>/dev/null 2>/dev/null + printf ' %s\n' "$([ $? -eq 0 ] && echo "OK" || echo "ERROR")" + done +} + +get_wifi_cfg | parse_filter | import_pass + -- cgit v1.2.3