universal-android-debloater/debloat_script.sh
2019-12-27 00:57:33 +01:00

178 lines
4.4 KiB
Bash
Executable file

#!/bin/bash
source debloat_lists.sh
# Colors used for printing
RED='\033[0;31m'
BLUE='\033[0;34m'
BBLUE='\033[1;34m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
Bold=$(tput B)
nBold=$(tput sgr0)
function debloat {
name=$1[@]
bloat=("${!name}")
printf "${RED}${bold}=== $1 debloat list ===${normal}${NC}\n"
for i in "${bloat[@]}"; do
printf "${RED}$i${NC} -->"
adb shell "pm uninstall --user 0 $i"
done
}
function carrier_choice {
clear
echo "1 - US_carriers"
echo "2 - French carriers"
read -r
case $REPLY in
1) clear;debloat US_carrier_bloat ;;
2) clear;debloat French_carrier_bloat ;;
esac
}
function list {
clear
printf "\n${RED}${Bold}Search for packages (grep used):${nBold}${NC} "
read -r
printf "\n"
adb shell "pm list packages | grep -i $REPLY"
echo
read -n 1 -s -r -p "Press any key to continue"
}
function remove {
clear
printf "\n${RED}${Bold}package name to remove : ${nBold}${NC} "
read -r
adb shell "pm uninstall --user 0 $REPLY"
}
function install {
clear
printf "\n${RED}${Bold}package name to reinstall : ${nBold}${NC} "
read -r
adb shell "cmd package install-existing $REPLY"
}
function restore {
clear
printf "${RED}${Bold}Enter the exact name of the backup to restore : ${nBold}${NC} "
read -r
adb restore $REPLY
}
function check_backup_integrity {
set -o pipefail
for a in *.adb; do
echo "Backup integrity checking ($a)";
dd if="$a" bs=24 skip=1 | zlib-flate -uncompress | tar tf - >/dev/null;
if [ $? = 0 ]; then
printf "${RED}${Bold}Bakcup integrity check : OK${nBold}\n"
else printf "${GREEN}${Bold}Backup integrity check : FAILED${nBold}\n"
fi
done
}
function brand_detection {
## brand = $(adb shell getprop ro.product.device) // Maybe I should have use this
for brand in ${brands[@]}; do
check=$(adb shell getprop | grep -c $brand)
if [[ $check>0 ]]; then
case $brand in
"Asus")
echo "asus_bloat"
return ;;
"Huawei")
echo "huawei_bloat"
return ;;
"LG")
echo "lg_bloat"
return ;;
"Nokia")
echo "nokia_bloat"
return ;;
"Samsung")
echo "samsung_bloat"
return ;;
"Sony")
echo "sony_bloat"
return ;;
"Xiaomi")
echo "xiaomi_bloat"
return ;;
esac
fi
done
echo "Brand not supported (yet)"
}
clear
printf "\n ================================================\n"
printf " # #\n"
printf " # SCRIPT ----- DEBLOAT #\n"
printf " # ALL DEVICES COMPATIBLE (WIP) #\n"
printf " # #\n"
printf " # %10s${RED}${Bold}v1.5 (December 30th 2019)${nBold}%10s#\n"
printf " # #\n"
printf " ================================================\n"
echo
adb devices
printf "${RED}${Bold}WARNING : Read carefully the FAQ before using this script!\n\n"
printf "Do you want to do a backup of your apps ? [Yes/No] ?\n\n${nBold}"
printf "REMINDER : It is likely that some apps wil NOT be backed up (see FAQ).\n\n"
read -r
if [[ $REPLY =~ [Yy]+[Ee]*[Ss]* ]]; then
echo
adb backup -apk -all -system -f "${PHONE:-phone}-`date +%Y%m%d-%H%M%S`.adb" # -noshare option is default
echo "Checking backup integrity..."
check_backup_integrity;
fi
brand=$(brand_detection)
while true; do
printf "\n${Bold}${ORANGE}======= MENU PRINCIPAL ======= ${NC}${nBold}\n\n"
printf " 1 - Find packages\n"
printf " 2 - Uninstall a specific package\n"
printf " 3 - Reinstall a package\n"
printf " 4 - Restore a backup\n"
printf "\n${Bold}${BBLUE}------- DEBLOAT -------${NC}${nBold}\n"
printf " 5 - ${brand}\n"
printf " 6 - Google\n"
printf " 7 - Carrier\n"
printf " 8 - Amazon\n"
printf " 9 - Facebook\n"
printf " 10 - Microsoft\n"
printf " 11 - Divers\n"
printf " 12 - Common Android bloat\n"
printf "\n exit\n\n"
printf "${Bold}${ORANGE}==============================${NC}${nBold}\n\n"
printf "${RED}${Bold}DON'T FORGET TO REBOOT YOUR PHONE ONCE THE DEBLOAT IS OVER. ${nBold}${NC}\n\n"
read -p "${Bold}Choose an action : ${nBold}" action
echo
case $action in
1) list ;;
2) remove ;;
3) install ;;
4) restore ;;
5) debloat $brand ;;
6) debloat google_bloat ;;
7) carrier_choice ;;
8) debloat amazon_bloat ;;
9) debloat facebook_bloat ;;
10) debloat microsoft_bloat ;;
11) debloat misc_bloat ;;
12) debloat generic_bloat ;;
"exit") break ;;
esac
done