Last active
September 20, 2019 08:35
-
-
Save Mercandj/65b053ccc9a042740bba8108f8005002 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
ANDROID_SERIAL_NUMBER=$1 | |
if [[ "$ANDROID_SERIAL_NUMBER" = "" ]] ; then | |
printf "Missing android serial number after the command. | |
To get it -> adb devices: \n" | |
adb devices | |
exit 0 | |
fi | |
print_pwd() { | |
PWD_OUTPUT="`pwd`" | |
print_key_value "PWD" "${PWD_OUTPUT}" | |
} | |
print_key_value() { | |
printf "[$1] $2\n" | |
} | |
contains_string() { | |
tmp_contains="CONTAINS" | |
tmp_not_contains="NOT_CONTAINS" | |
WORDS_TO_KEEP=("google" "mercandalli" "mwm") | |
for i in "${WORDS_TO_KEEP[@]}" | |
do | |
if [[ $2 = *"$i"* ]]; then | |
eval "$1=${tmp_contains}" | |
return 0 | |
fi | |
done | |
eval "$1=${tmp_not_contains}" | |
return 0 | |
} | |
printf "\n\n" | |
SCRIPT_PATH="`dirname \"$0\"`" | |
print_key_value "SCRIPT_PATH" "${SCRIPT_PATH}" | |
print_pwd | |
# Uninstall all apps | |
PACKAGES_STRING="`adb -s ${ANDROID_SERIAL_NUMBER} shell "pm list packages -3" | cut -f 2 -d ":"`" | |
IFS=$'\r\n' read -d '' -r -a PACKAGES <<< "$PACKAGES_STRING" | |
for i in "${PACKAGES[@]}" | |
do | |
CONTAINS="test" | |
PACKAGE=$i | |
contains_string CONTAINS $i | |
if [[ "$CONTAINS" = "NOT_CONTAINS" ]] && [[ ! -z ${PACKAGE} ]]; then | |
printf "TO_DELETE> $PACKAGE\n" | |
adb -s ${ANDROID_SERIAL_NUMBER} uninstall ${PACKAGE} | |
else | |
printf "TO_KEEP> $PACKAGE\n" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment