Last active
August 29, 2015 13:58
-
-
Save scottyab/9951327 to your computer and use it in GitHub Desktop.
From article http://www.vkalchev.co.uk/content/quickinstallapk/ Spoke to Val and he clarified the Licensed under the Apache License, Version 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Licensed under the Apache License, Version 2.0 (the "License"); | |
#you may not use this file except in compliance with the License. | |
#You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | |
#Copyright 2013 Valentin Kalchev | |
#Date: 26/02/2013 | |
#Target: Mac OS X Terminal + Android ADB + AAPT | |
sharePackageName="" | |
#Called when user selects the Install (1) | |
function Install | |
{ | |
echo -------------------------------------------- | |
echo -------------------------------------------- | |
echo Select .apk to Install it on all devices... | |
echo -------------------------------------------- | |
a=`ls *.apk` | |
INSTALL_OPTIONS="Back $a" | |
select install_opt in $INSTALL_OPTIONS; do | |
for item in $a;do | |
case $install_opt in | |
"$item") | |
#Uninstall app before installing | |
echo -------------------------------------------- | |
echo $item is being uninstalled from all devices... | |
echo -------------------------------------------- | |
UninstallApp $item | |
echo -------------------------------------------- | |
echo $item is being installed on all devices... | |
echo -------------------------------------------- | |
#Install the app | |
InstallApp $item | |
echo -------------------------------------------- | |
echo $item is being launched on all devices... | |
echo -------------------------------------------- | |
#Find the Launch Activity and start the app on all devices | |
FindLaunchableActivity $item | |
break;; | |
"Back") | |
MainMenu | |
break;; | |
esac | |
done | |
done | |
} | |
#Function to be called to install the app on the device | |
function InstallApp | |
{ | |
for device in `./adb devices | awk 'NR>1 {print $1}'` ;do | |
./adb -s $device install $item | |
done | |
} | |
#Called when user selects the Uninstall (2) | |
function Replace | |
{ | |
echo -------------------------------------------- | |
echo -------------------------------------------- | |
echo Select .apk to Replace it on all devices... | |
echo -------------------------------------------- | |
a=`ls *.apk` | |
REPLACE_OPTIONS="Back $a" | |
select replace_opt in $REPLACE_OPTIONS; do | |
for item in $a;do | |
case $replace_opt in | |
"$item") | |
echo -------------------------------------------- | |
echo $item is being replaced on all devices... | |
echo -------------------------------------------- | |
ReplaceApp $item | |
break;; | |
"Back") | |
MainMenu | |
break;; | |
esac | |
done | |
done | |
} | |
function FindActivity | |
{ | |
a=`ls *.apk` | |
FINDACTIVITY_OPTIONS="Back $a" | |
select replace_opt in $FINDACTIVITY_OPTIONS; do | |
for item in $a;do | |
case $replace_opt in | |
"$item") | |
FindLaunchableActivity $item | |
break;; | |
"Back") | |
MainMenu | |
break;; | |
esac | |
done | |
done | |
} | |
function FindLaunchableActivity | |
{ | |
#Create string with name of the command and .adb inside it | |
aaptCommand="./aapt d badging " | |
grepCommand=" | grep 'pack'" | |
packageName=${aaptCommand}${item}${grepCommand} | |
recordingPackageName="" | |
startRecordingBoolean=false | |
loopString=`$packageName` | |
incrementLoop="0" | |
record=false | |
#Trim the amount of text that needs scanning | |
for packageChar in $loopString;do | |
#If the line equals package name - store into the variable | |
if($record);then | |
recordingPackageName=$packageChar | |
record=false | |
fi | |
case "$packageChar" in | |
"launchable-activity:") | |
record=true | |
;; | |
esac | |
incrementLoop=$[incrementLoop+1] | |
done | |
#String to look for starting the expression | |
compString="'" | |
#String that will store the package name | |
packageName="" | |
#Check each character | |
for (( i=0; i<${#recordingPackageName}; i++ )); do | |
curString=${recordingPackageName:$i:1} | |
if($startRecordingBoolean);then | |
#When recording if character hits the second ' - exit the if statement | |
case "$curString" in | |
"$compString") | |
startRecordingBoolean=true | |
break | |
;; | |
esac | |
#Save each character between both ' | |
packageName=$packageName${recordingPackageName:$i:1} | |
fi | |
#Start recording if character equal ' | |
case "$curString" in | |
"$compString") | |
startRecordingBoolean=true | |
;; | |
esac | |
done | |
for device in `./adb devices | awk 'NR>1 {print $1}'` ;do | |
./adb -s $device shell am start -n $sharePackageName/$packageName | |
done | |
} | |
function ReplaceApp | |
{ | |
for device in `./adb devices | awk 'NR>1 {print $1}'` ;do | |
./adb -s $device install -r $item | |
done | |
} | |
#Called when user selects the Uninstall (3) | |
function Uninstall | |
{ | |
echo -------------------------------------------- | |
echo -------------------------------------------- | |
echo Select .apk to Uninstall it on all devices... | |
echo -------------------------------------------- | |
a=`ls` | |
UNINSTALL_OPTIONS="Back $a" | |
echo -------------------------------------------- | |
select uninstal_opt in $UNINSTALL_OPTIONS; do | |
for item in $a;do | |
case $uninstal_opt in | |
"$item") | |
echo -------------------------------------------- | |
echo $item is being uninstalled from all devices... | |
echo -------------------------------------------- | |
UninstallApp $item | |
break;; | |
"Back") | |
MainMenu | |
break;; | |
esac | |
done | |
done | |
} | |
function UninstallApp | |
{ | |
#Create string with name of the command and .adb inside it | |
aaptCommand="./aapt d badging " | |
grepCommand=" | grep 'pack'" | |
packageName=${aaptCommand}${item}${grepCommand} | |
recordingPackageName="" | |
startRecordingBoolean=false | |
loopString=`$packageName` | |
incrementLoop="0" | |
#Trim the amount of text that needs scanning | |
for packageChar in $loopString;do | |
#If the line equals package name - store into the variable | |
if [[ $incrementLoop -eq 1 ]];then | |
recordingPackageName=$packageChar | |
fi | |
incrementLoop=$[incrementLoop+1] | |
done | |
#String to look for starting the expression | |
compString="'" | |
#String that will store the package name | |
packageName="" | |
#Check each character | |
for (( i=0; i<${#recordingPackageName}; i++ )); do | |
curString=${recordingPackageName:$i:1} | |
if($startRecordingBoolean);then | |
#When recording if character hits the second ' - exit the if statement | |
case "$curString" in | |
"$compString") | |
startRecordingBoolean=true | |
break | |
;; | |
esac | |
#Save each character between both ' | |
packageName=$packageName${recordingPackageName:$i:1} | |
fi | |
#Start recording if character equal ' | |
case "$curString" in | |
"$compString") | |
startRecordingBoolean=true | |
;; | |
esac | |
done | |
sharePackageName=$packageName | |
#Uninstall from each device using the package name | |
for device in `./adb devices | awk 'NR>1 {print $1}'` ;do | |
recordModel=false | |
model="" | |
deviceModel=`./adb -s $device shell cat /system/build.prop | grep "model"` | |
for (( i=0; i<${#deviceModel}; i++ )); do | |
curString=${deviceModel:$i:1} | |
if($recordModel);then | |
model=$model$curString | |
fi | |
case "$curString" in | |
"=") | |
recordModel=true | |
;; | |
esac | |
done | |
echo "Uninstall status for" $model... | |
./adb -s $device uninstall $packageName | |
done | |
} | |
function InstallAll | |
{ | |
a=`ls *.apk` | |
for item in $a;do | |
echo -------------------------------------------- | |
echo $item is being installed on all devices... | |
echo -------------------------------------------- | |
#Uninstall app before installing | |
UninstallApp $item | |
#Install the app | |
InstallApp $item | |
done | |
#Go back to the Main Menu | |
MainMenu | |
} | |
function UninstallAll | |
{ | |
a=`ls *.apk` | |
for item in $a;do | |
echo -------------------------------------------- | |
echo $item is being uninstalled from all devices... | |
echo -------------------------------------------- | |
#Uninstall app before installing | |
UninstallApp $item | |
done | |
#Go back to the Main Menu | |
MainMenu | |
} | |
function ReplaceAll | |
{ | |
a=`ls *.apk` | |
for item in $a;do | |
echo -------------------------------------------- | |
echo $item is being replaced on all devices... | |
echo -------------------------------------------- | |
#Uninstall app before installing | |
ReplaceApp $item | |
done | |
#Go back to the Main Menu | |
MainMenu | |
} | |
#Create Main Menu function with options to choose from | |
function MainMenu | |
{ | |
OPTIONS="Install Replace Uninstall InstallAll ReplaceAll UninstallAll Quit" | |
echo -------------------------------------------- | |
echo Main Menu - Select one of the options... | |
echo -------------------------------------------- | |
select opt in $OPTIONS; do | |
if [ "$opt" = "Quit" ]; then | |
exit | |
elif [ "$opt" = "Replace" ]; then | |
Replace | |
elif [ "$opt" = "Install" ]; then | |
Install | |
elif [ "$opt" = "Uninstall" ]; then | |
Uninstall | |
elif [ "$opt" = "InstallAll" ]; then | |
InstallAll | |
elif [ "$opt" = "ReplaceAll" ]; then | |
ReplaceAll | |
elif [ "$opt" = "UninstallAll" ]; then | |
UninstallAll | |
elif [ "$opt" = "Test" ]; then | |
Test | |
else | |
clear | |
echo bad option | |
fi | |
done | |
} | |
function Test | |
{ | |
for device in `./adb devices | awk 'NR>1 {print $1}'`;do | |
echo $device | |
done | |
} | |
#Call the Main Menu function | |
MainMenu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment