universal-android-debloater/debloat_script.sh

193 lines
6.8 KiB
Bash
Raw Normal View History

2019-03-31 02:55:40 +13:00
#!/bin/bash
2020-02-05 11:04:26 +13:00
# BASH 4.3 or newer is needed ! (use of locale -n)
2020-01-10 03:23:21 +13:00
for file in ./lists/* ; do
2020-02-05 11:04:26 +13:00
if [ -f "$file" ] ; then . "$file"; fi
2020-01-10 03:23:21 +13:00
done
2019-03-31 04:54:13 +13:00
2019-12-16 11:21:39 +13:00
# Colors used for printing
2019-03-31 02:55:40 +13:00
RED='\033[0;31m'
2019-12-16 11:21:39 +13:00
BLUE='\033[0;34m'
BBLUE='\033[1;34m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
2019-03-31 02:55:40 +13:00
NC='\033[0m' # No Color
2020-01-10 03:23:21 +13:00
Bold=$(tput bold)
2019-12-16 11:21:39 +13:00
nBold=$(tput sgr0)
2019-03-31 02:55:40 +13:00
function debloat {
2020-02-05 11:04:26 +13:00
local option_needed=""
if [[ $(adb shell getprop ro.build.version.sdk) > 20 ]]; then option_needed="--user 0"; fi
local -n list=$1 # list is a nameref. Array is passed by reference.
clear
printf "\n${RED}${Bold}=== $1 debloat list ===${nBold}${NC}\n"
for package in "${list[@]}"; do
printf "${RED}$package${NC} --> "
output=$([[ $2 = 'r' ]] && adb shell "cmd package install-existing $package" || adb shell "pm uninstall $option_needed $package")
echo "$output"
if [[ "$output" != "Failure" ]]; then echo "$package" >> "debloated_packages.txt"; fi
2019-03-31 02:55:40 +13:00
done
}
2019-12-27 12:57:33 +13:00
function carrier_choice {
clear
echo "1 - US_carriers"
echo "2 - French carriers"
2020-02-05 11:04:26 +13:00
echo "3 - German carriers"
printf "\n${RED}${Bold}Your choice : ${nBold}${NC}"
read -n 1
2019-12-27 12:57:33 +13:00
case $REPLY in
2020-02-05 11:04:26 +13:00
1) [[ $1 = 'r' ]] && debloat us_carriers_bloat 'r' || debloat us_carriers_bloat ;;
2) [[ $1 = 'r' ]] && debloat french_carriers_bloat 'r' || debloat french_carriers_bloat ;;
3) [[ $1 = 'r' ]] && debloat german_carriers_bloat 'r' || debloat german_carriers_bloat ;;
2019-12-27 12:57:33 +13:00
esac
}
2019-03-31 02:55:40 +13:00
function list {
2019-12-27 12:57:33 +13:00
clear
printf "\n${RED}${Bold}Search for packages (grep used):${nBold}${NC} "
2020-02-05 11:04:26 +13:00
read
2019-03-31 02:55:40 +13:00
printf "\n"
2020-02-05 11:04:26 +13:00
adb shell "pm list packages | grep -i $REPLY" | sed -r 's/package://g' | sort
2019-12-27 12:57:33 +13:00
echo
2020-02-05 11:04:26 +13:00
printf "\e[5mPress any key to continue\033[0m"
read -n 1 -s
2019-03-31 02:55:40 +13:00
}
2020-02-05 11:04:26 +13:00
function remove_or_install_one {
[[ $1 = 'r' ]] && choice="restore" || choice="uninstall"
2019-12-27 12:57:33 +13:00
clear
2020-02-05 11:04:26 +13:00
printf "\n${RED}${Bold}Package name to $choice : ${nBold}${NC} "
read
[[ $1 = 'r' ]] && adb shell "pm uninstall --user 0 $REPLY" || adb shell "cmd package install-existing $REPLY";
2019-03-31 02:55:40 +13:00
}
function restore {
2019-12-27 12:57:33 +13:00
clear
2020-02-05 11:04:26 +13:00
printf "${RED}${Bold}Enter the path of the backup to restore : ${nBold}${NC} "
read
${integrity} = "$(check_backup_integrity)"
[[ "${integrity}" = "${GREEN}${Bold}OK${nBold}${NC}\n" ]] && adb restore $REPLY || printf "${RED}${Bold}The backup is corrupted${nBold}${NC}\n"
2019-03-31 02:55:40 +13:00
}
2019-04-01 01:33:44 +13:00
function check_backup_integrity {
2019-03-31 07:39:12 +13:00
set -o pipefail
2020-02-05 11:04:26 +13:00
printf "\n${BBLUE}\n[($1)] Backup integrity checking : \n${NC}";
dd if="$1" bs=24 skip=1 | zlib-flate -uncompress | tar tf - >/dev/null;
[[ $? = 0 ]] && printf "${GREEN}${Bold}OK${nBold}${NC}\n\n" || printf "${RED}${Bold}FAILED${nBold}${NC}\n\n"
printf "\e[5m Press any key to continue\033[0m"
read -n 1 -s
2019-04-01 01:33:44 +13:00
}
function brand_detection {
2020-02-05 11:04:26 +13:00
local brand=$(adb shell getprop ro.product.brand)
2020-01-10 03:23:21 +13:00
if [[ $brand>0 ]]; then
case $brand in
"asus")
echo "asus_bloat" ;;
"huawei")
echo "huawei_bloat" ;;
"lg")
echo "lg_bloat" ;;
"motorola")
2020-01-27 13:51:27 +13:00
echo "motorola_bloat" ;;
2020-01-10 03:23:21 +13:00
"nokia")
echo "nokia_bloat" ;;
"oneplus")
echo "oneplus_bloat" ;;
2020-01-10 03:23:21 +13:00
"samsung")
echo "samsung_bloat" ;;
"sony")
echo "sony_bloat" ;;
"xiaomi")
echo "xiaomi_bloat" ;;
*)
echo "Brand not supported (yet)" ;;
esac
fi
2019-03-31 07:39:12 +13:00
}
2019-03-31 02:55:40 +13:00
clear
printf "\n ================================================\n"
printf " # #\n"
2020-02-05 11:04:26 +13:00
printf " # UNIVERSAL ANDROID DEBLOAT SCRIPT #\n"
2019-03-31 02:55:40 +13:00
printf " # #\n"
2020-02-05 11:04:26 +13:00
printf " # %10s${RED}${Bold}v2.0 (February 4th 2020)${nBold}%11s#\n"
2019-03-31 02:55:40 +13:00
printf " # #\n"
printf " ================================================\n"
echo
2019-04-01 01:33:44 +13:00
2019-03-31 02:55:40 +13:00
adb devices
2020-02-05 11:04:26 +13:00
printf "${RED}${Bold}Please carefully read the FAQ before using this script!\n\n${NC}"
printf "Do you want to do an ADB backup ? [Yes/No] ?\n\n${nBold}"
2019-12-27 12:57:33 +13:00
read -r
2019-03-31 08:32:07 +13:00
if [[ $REPLY =~ [Yy]+[Ee]*[Ss]* ]]; then
2020-02-05 11:04:26 +13:00
clear;
backup=$(date +%Y-%m-%d-%H:%M:%S)
adb backup -apk -all -system -f "${PHONE:-phone}-${backup}.adb" # -noshare option is default
2019-03-31 07:39:12 +13:00
echo
2020-02-05 11:04:26 +13:00
read -n 1 -s -p "Press a key when the backup is done (your phone will tell you)"
check_backup_integrity "${PHONE:-phone}-${backup}.adb";
2019-03-31 07:39:12 +13:00
fi
2019-12-16 11:21:39 +13:00
brand=$(brand_detection)
2020-02-05 11:04:26 +13:00
space=$((25-${#brand}))
if [[ $space =~ "-" ]]; then space="0"; fi
2019-12-16 11:21:39 +13:00
2019-03-31 02:55:40 +13:00
while true; do
2020-02-05 11:04:26 +13:00
clear;
printf "\n${Bold}${ORANGE}=================== MAIN MENU ===================\n"
printf "# ${ORANGE} #\n"
printf "#${nBold}${NC}%12s 0 - List packages ${ORANGE} #\n"
printf "#${NC} 1 - Restore packages ${ORANGE} #\n"
printf "#${NC} 2 - Restore a save ${ORANGE} #\n"
printf "#${NC} 3 - Debloat packages ${ORANGE} #\n"
printf "#${NC} ${ORANGE} #\n"
printf "${Bold}===================================================${NC}${nBold}\n\n"
2019-12-16 11:21:39 +13:00
2019-12-27 12:57:33 +13:00
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
2019-03-31 02:55:40 +13:00
echo
2020-02-05 11:04:26 +13:00
if [[ $action = 0 ]]; then list; fi
if [[ $action = 2 ]]; then restore; fi
if [[ $action = 1 || $action = 3 ]]; then
clear
title="DEBLOAT"
action_arg=''
if [[ $action = 1 ]]; then title="RESTORE"; fi
printf "\n${Bold}${ORANGE}==================== $title ====================\n"
printf "# ${ORANGE} #\n"
printf "#${NC} 1 - $title a package ${ORANGE} %-6s#\n" | awk '{print tolower($0)}'
printf "#${nBold}${NC}%12s 2 - ${brand} %${space}s ${ORANGE} #\n"
printf "#${NC} 3 - GFAM ${ORANGE} #\n"
printf "#${NC} 4 - Carriers ${ORANGE} #\n"
printf "#${NC} 5 - Others ${ORANGE} #\n"
printf "#${NC} 6 - AOSP ${ORANGE} #\n"
printf "#${NC} ${ORANGE} #\n"
printf "#${NC} -1 - Pending list /!\\ %4s ${ORANGE} #\n"
printf "#${NC} ${ORANGE} #\n"
printf "${Bold}===================================================${NC}${nBold}\n\n"
read -p "${Bold}Your selection (e.g: 2 3 4 5 6): ${nBold}" action
echo
if [[ "$action" =~ 4 ]]; then carrier_choice $action_arg; fi
if [[ "$action" =~ -1 ]]; then debloat pending $action_arg; fi
if [[ "$action" =~ 1 ]]; then remove_or_install_one $action_arg; fi
if [[ "$action" =~ 2 ]]; then debloat $brand $action_arg; fi
if [[ "$action" =~ 3 ]]; then
debloat google_bloat $action_arg && debloat microsoft_bloat $action_arg &&
debloat amazon_bloat $action_arg && debloat facebook_bloat $action_arg
fi
if [[ "$action" =~ 5 ]]; then debloat misc_bloat $action_arg; fi
if [[ "$action" =~ 6 ]]; then debloat aosp_bloat $action_arg; fi
fi
adb shell 'pm list packages' | sed -r 's/package://g' | sort > packages_list.txt
done