commit 13c54e54aee2fe60ddfe9f9570c90519cac28371 Author: Florian Schrofner Date: Sat Apr 16 16:53:36 2022 +0200 add wireless adb helper tool diff --git a/wireless-adb-helper-tool/readme.md b/wireless-adb-helper-tool/readme.md new file mode 100644 index 0000000..bff0316 --- /dev/null +++ b/wireless-adb-helper-tool/readme.md @@ -0,0 +1,9 @@ +# Wireless ADB Helper Tool +Allows you to quickly connect your device via adb wireless. +This will start an adb server, figure out the device's IP and then connect to it. +Optionally a port can be provided to the script via the `-p` option. + +## Example Usage +``` +waht.clj -p 4242 +``` diff --git a/wireless-adb-helper-tool/waht.clj b/wireless-adb-helper-tool/waht.clj new file mode 100755 index 0000000..68cc7c7 --- /dev/null +++ b/wireless-adb-helper-tool/waht.clj @@ -0,0 +1,21 @@ +#!/usr/bin/env bb + +(require '[clojure.tools.cli :refer [parse-opts]]) + +(def cli-options + [["-p" "--port PORT" "Port number" + :default 5555 + :parse-fn #(Integer/parseInt %) + :validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]]) + +(def options (:options (parse-opts *command-line-args* cli-options))) +(def port (:port options)) + +(def ip (->> (shell/sh "adb" "shell" "ip addr") + :out + (re-find #"inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/.* scope global") + last)) + +(shell/sh "adb" "tcpip" (str port)) +(def result (shell/sh "adb" "connect" (str ip ":" port))) +(println (:out result))