Skip to content

Commit

Permalink
More error handling for adb connections. No upgrade needed.
Browse files Browse the repository at this point in the history
By default we give adb a couple of seconds to succeed with the
connection.
  • Loading branch information
Jinna Kiisuo committed Feb 9, 2024
1 parent 937cb98 commit cafa075
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- The MitM is checked to have at least one outbound connection to the upstream websocket.

## Installation:
- The script is intended to be installed from a Unix/Linux like environment and depends on having `bash` & `adb` available.
- The script is intended to be installed from a Unix/Linux like environment and depends on having GNU coreutils, `bash` & `adb` available.
- All arguments to `nanny.sh` are interpreted as adb reachable addresses.
- `nanny.sh` handles the connection & installation for you and embeds the nanny script itself: `./nanny.sh host1 host2 host3 192.168.1.21`
- If you have a range of devices, you can use a bash/zsh range expansion: `./nanny.sh atv0{1..99}`
Expand Down Expand Up @@ -37,6 +37,7 @@ The script has a handful of variables set at the top you could customize, but th
- `log="/sdcard/nanny.log"` # log for all output, cleared for every run of nanny.
- `connection_min=1` # Number of upsteam ws connections to require. Could optimise to 1+workers.
- `mitm="com.gocheats.launcher"` # package name of mitm
- `adb_timeout=2` # Max connection timeout in seconds for ADB. May need to increase if your devices are over WAN

## Sample session log
```
Expand Down
9 changes: 8 additions & 1 deletion nanny.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ cooldown=60 # wait cooldown seconds for mitm before checking
log="/sdcard/nanny.log" # log for all output, cleared for every run of nanny.
connection_min=1 # Number of upsteam ws connections to require. Could optimise to 1+workers.
mitm="com.gocheats.launcher" # package name of mitm
adb_timeout=2 # Max connection timeout in seconds for ADB. May need to increase if your devices are over WAN

# Nothing to configure below here
targets=("$@")

for target in "${targets[@]}"; do
# The connect may or may not block until connected. No exit value we could use. ¯\_(ツ)_/¯
adb connect "$target"
# Wait until we have a connection to proceed, with a timeout.
timeout "$adb_timeout" adb -s "$target" wait-for-device
[[ "$?" -ne 0 ]] && >&2 echo "Failed to connect to $target, skipping." && continue
# Connected, render & push the script.
cat<<EOT | adb -s "$target" shell "su -c 'cat > /data/adb/service.d/nanny.sh && chmod +x /data/adb/service.d/nanny.sh'"
#!/system/bin/sh
# ^ says sh, but we assume it to be ash
Expand Down Expand Up @@ -86,6 +92,7 @@ while true; do
echo "RESUME_CHECKS at \$(date +%Y-%m-%dT%T)"
done
EOT

[[ "$?" -ne 0 ]] && >&2 echo "Failed to push script to $target." && continue
>&2 echo "Finished with $target."
done
>&2 echo "Reboot devices at your leisure to activate Nanny. Check $log to see what's going on."

0 comments on commit cafa075

Please sign in to comment.