From 9b43cee636498902798a075b0d5cd91351ca6b70 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Thu, 30 Apr 2015 12:18:47 +0200 Subject: [PATCH] Make adb-channel able to start/stop a SSH server app automatically. --- README.md | 5 +++-- adb-channel | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3593988..0b32402 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,8 @@ ADB Channel This package also contains a separate tool called adb-channel, which is a convenience wrapper to connect a networking socket on the Android device to -file descriptors on the PC side. +file descriptors on the PC side. It can even launch and shut down the given +application automatically! It is best used as a `ProxyCommand` for SSH (intall [SSHelper](https://play.google.com/store/apps/details?id=com.arachnoid.sshelper) @@ -104,7 +105,7 @@ first) using a configuration like: ``` Host sshhelper Port 2222 -ProxyCommand adb-channel tcp:%d +ProxyCommand adb-channel tcp:%d com.arachnoid.sshelper/.SSHelperActivity 1 ``` After adding this to `~/.ssh/config`, run `ssh-copy-id sshhelper`. diff --git a/adb-channel b/adb-channel index ce906d4..28f0a3e 100755 --- a/adb-channel +++ b/adb-channel @@ -4,11 +4,18 @@ set -e t=`mktemp -d -t adb-channel.XXXXXX` +remote=${1} +activity=${2} +delat=${3} + atexit() { + [ -z "${activity}" ] || adb shell am force-stop ${activity%%/*} adb forward --remove localfilesystem:"${t}/sock" rm -rf "${t}" } trap atexit EXIT +[ -z "${activity}" ] || adb shell am start -W ${activity} +[ -z "${delay}" ] || sleep "${delay}" adb forward localfilesystem:"${t}/sock" "${1}" socat stdio unix:"${t}/sock"