Skip to content

Instantly share code, notes, and snippets.

@mnexo
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnexo/10856009 to your computer and use it in GitHub Desktop.
Save mnexo/10856009 to your computer and use it in GitHub Desktop.
Installatron: bash script for installing an .apk on all connected devices.
#!/bin/bash
# Installatron: installs an Android APK-file provided onto all attached devices.
# IMPORTANT: This script assumes that `adb` and `aapt` are located on PATH.
# Require at least one argument
if [ -z "$1" ]
then
echo "usage: $(basename $0) [-u] apk_file"
exit 1
fi
# Parse arguments
if [ "$1" == '-u' ] || [ "$1" == '--uninstall' ]
then
APK="$2"
UNINSTALL=true
else
APK="$1"
fi
APK_NAME=$(basename "$APK")
# Fetch package name from .apk, error on failure.
PACKAGE=`aapt dump badging "$APK" | grep package | awk '{print $2}' | sed s/name=//g | sed s/\'//g`
if [ -z $PACKAGE ]
then
echo "$APK_NAME doesn't seem to be an Android binary."
exit 1
fi
# Grab device serial numbers
DEVICE_SERIALS=$(adb devices | tail -n +2 | cut -sf 1)
# Uninstall/install on all devices
INSTALL_COUNT=0
for SERIAL in $DEVICE_SERIALS
do
# Uninstall existing app, if asked
if [ "$UNINSTALL" = true ]
then
adb -s $SERIAL uninstall $PACKAGE > /dev/null
fi
# Install APK
adb -s $SERIAL install "$APK" > /dev/null
if [ $? -eq 0 ]
then
((INSTALL_COUNT++))
fi
done
echo "$APK_NAME ($PACKAGE) installed on $INSTALL_COUNT device(s)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment