Skip to content

Instantly share code, notes, and snippets.

@groupsky
Last active December 10, 2015 22:28
Show Gist options
  • Save groupsky/4501932 to your computer and use it in GitHub Desktop.
Save groupsky/4501932 to your computer and use it in GitHub Desktop.
deploy only release apps to all connected devices and use watchdog if adb hangs
# Timeout.
declare -i timeout=60
# Interval between checks if the process is still alive.
declare -i interval=1
# Delay between posting the SIGTERM signal and destroying the process by SIGKILL.
declare -i delay=1
function watchdog {
# $# should be at least 1 (the command to execute), however it may be strictly
# greater than 1 if the command itself has options.
if (($# == 0 || interval <= 0)); then
return 1
fi
# start the command in the background and take it's pid
$@ &
pid=$!
# kill -0 pid Exit code indicates if a signal may be sent to $pid process.
(
((t = timeout))
while ((t > 0)); do
sleep $interval
kill -0 $pid || return 0
((t -= interval))
done
# Be nice, post SIGTERM first.
# The 'exit 0' below will be executed if any preceding command fails.
echo "killing nicely $pid"
kill -s SIGTERM $pid && kill -0 $pid || return 0
sleep $delay
echo "killing hard $pid"
kill -s SIGKILL $pid
) 2> /dev/null
}
for APK in `find $WORKSPACE -type f -name '*-release*.apk'`; do
if [[ "$APK" != *unaligned* ]]; then
if [[ "$APK" != *unsigned* ]]; then
for DEVICE in `adb devices | tail -n+2 | cut -f1`; do
echo "installing $APK on $i"
watchdog adb -s $DEVICE install -rs $APK
done
fi
fi
done
echo "done deploying"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment