Skip to content

Instantly share code, notes, and snippets.

@medvid
Created February 5, 2014 17:34
Show Gist options
  • Save medvid/8829109 to your computer and use it in GitHub Desktop.
Save medvid/8829109 to your computer and use it in GitHub Desktop.
#!/bin/bash
#set -x
adb="/home/vmm/dev/opt/android-sdk-linux/platform-tools/adb"
# enable logging
exec >> /var/log/tether.log 2>&1
echo
echo "-------------------------------------------------"
echo "Running tether script at `date`"
adb_check() {
for i in `seq 1 10`
do
$adb devices 2>/dev/null | grep device$ >/dev/null && return 0
sleep 1
done
return 1
}
tether_toggle() {
# go home
$adb shell input keyevent 3
# open tethering settings
$adb shell am start -a android.intent.action.MAIN -n com.android.settings/.TetherSettings
# toggle checkbox
$adb shell input keyevent 66
# sometimes it is needed to press return one more time
# sleep 1
# $adb shell input keyevent 66
# return home
sleep 1
$adb shell input keyevent 3
# turn off the screen
$adb shell input keyevent 26
}
wifi_enable() {
$adb shell svc wifi enable
}
wifi_disable() {
$adb shell svc wifi disable
}
error() {
echo $@
exit 1
}
if ! adb_check
then
error "No android devices found, exiting.."
fi
wifi_enable
if ! $adb shell getprop sys.usb.config | grep rndis >/dev/null
then
echo "RNDIS not enabled, running tethering.."
tether_toggle
else
echo "RNDIS already enabled"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment