Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script for uninstalling and installing apk on multiple connected devices at once
#!/bin/bash
clear
START=$(date +"%s")
function ShowElapsedTime {
echo ''
end=$(date +"%s")
elapsed=$(($end-$START))
echo "$(($elapsed / 60)) minutes $(($elapsed % 60)) seconds"
echo ''
}
echo ''
echo ''
echo ''
echo '|||||||||||||||||||||||||||||||'
echo '| |'
echo '| Mopsicus |'
echo '| Test tools |'
echo '| |'
echo '|||||||||||||||||||||||||||||||'
echo ''
echo ''
echo ''
echo ''
echo '1 – Uninstall app'
echo '2 – Install app'
echo '3 – Uninstall & install app'
echo ''
echo ''
read -n 1 -s -r -p 'Select operation type, ESC to cancel...' key
echo ''
if [ "$key" == $'\e' ]; then
echo ''
echo ''
echo 'Operation canceled!'
echo ''
echo ''
exit 1
fi
clear
case $key in
1)
echo ''
echo ''
echo 'Enter app package name to uninstall, e.g. com.rstgames.XXX and press Enter, Ctrl+C to cancel...'
echo ''
read -p 'Package name: ' data
echo ''
echo 'Uninstall started'
echo '-------------------------'
adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} uninstall $data
;;
2)
echo ''
echo ''
echo 'Enter path to APK file to install, e.g. MyApp.apk and press Enter, Ctrl+C to cancel...'
echo ''
read -p 'Path to APK: ' data
echo ''
echo 'Install started'
echo '-------------------------'
adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} install $data
;;
3)
echo ''
echo ''
echo 'Enter app package name to uninstall, e.g. com.rstgames.XXX and press Enter, Ctrl+C to cancel...'
echo ''
read -p 'Package name: ' data
echo ''
echo 'Enter path to APK file to install, e.g. MyApp.apk and press Enter, Ctrl+C to cancel...'
echo ''
read -p 'Path to APK: ' data2
echo ''
echo 'Uninstall started'
echo '-------------------------'
adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} uninstall $data
echo ''
echo 'Install started'
echo '-------------------------'
adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} install $data2
;;
*)
echo ''
echo ''
echo 'Unknown operation type!'
echo ''
echo ''
exit 1
;;
esac
ShowElapsedTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.