diff --git a/debloat_script.sh b/debloat_script.sh index 6be84b1..a8e7648 100755 --- a/debloat_script.sh +++ b/debloat_script.sh @@ -1,6 +1,7 @@ #!/bin/bash # BASH 4.3 or newer is needed ! (use of locale -n) + for file in ./lists/* ; do if [ -f "$file" ] ; then . "$file"; fi done @@ -19,12 +20,12 @@ nBold=$(tput sgr0) function debloat { # user choice : restore/debloat - local user_choice="" - [[ $action_arg = 'r' ]] && user_choice='cmd package install-existing $package' || user_choice='pm uninstall $option_needed $package' + local action="" + (($restore)) && action='cmd package install-existing $package' || action='pm uninstall $option_needed $package' # Android 7.1 and older can't reinstall packages - if [[ $(adb shell getprop ro.build.version.release) < 8.0 && "$force_uninstall" = "0" ]]; then - [[ $action_arg = 'r' ]] && user_choice='pm enable $package' || user_choice='pm disable-user $package && am force-stop $package && pm clear $package' + if (( $(echo "$(adb shell getprop ro.build.version.release) < 8.0" | bc -l) && !$force_uninstall)); then + (($restore)) && action='pm enable $package' || action='pm disable-user $package && am force-stop $package && pm clear $package' fi local -n list=$1 # list is a nameref. Array is passed by reference. @@ -32,7 +33,7 @@ function debloat { printf "\n${RED}${Bold}=== $1 debloat list ===${nBold}${NC}\n" for package in "${list[@]}"; do printf "${RED}$package${NC} --> " - local output=$(eval adb shell $user_choice) + local output=$(eval adb shell $action) echo "$output" if [[ "$output" != "Failure" ]]; then echo "$package" >> "debloated_packages.txt"; fi done @@ -46,9 +47,9 @@ function carrier_choice { printf "\n${RED}${Bold}Your choice : ${nBold}${NC}" read -n 1 case $REPLY in - 1) [[ $action_arg = 'r' ]] && debloat us_carriers_bloat || debloat us_carriers_bloat ;; - 2) [[ $action_arg = 'r' ]] && debloat french_carriers_bloat || debloat french_carriers_bloat ;; - 3) [[ $action_arg = 'r' ]] && debloat german_carriers_bloat || debloat german_carriers_bloat ;; + 1) debloat us_carriers_bloat ;; + 2) debloat french_carriers_bloat ;; + 3) debloat german_carriers_bloat ;; esac } @@ -65,23 +66,25 @@ function list { function remove_or_install_one { local choice="" - local user_choice='' - if [[ $action_arg = 'r' ]]; - then choice="restore"; user_choice='cmd package install-existing $REPLY'; - else choice="uninstall"; user_choice='pm uninstall $option_needed $REPLY'; + local action='' + if (($restore)); then choice="restore"; action='cmd package install-existing $REPLY'; + else choice="uninstall"; action='pm uninstall $option_needed $REPLY'; fi # Android 7.1 and older can't reinstall packages - if [[ $(adb shell getprop ro.build.version.release) < 8.0 && "$force_uninstall" = "0" ]]; then - [[ $action_arg = 'r' ]] && user_choice='pm enable $REPLY' || user_choice='pm disable-user $REPLY && am force-stop $REPLY && pm clear $REPLY' + if (( $(echo "$(adb shell getprop ro.build.version.release) < 8.0" | bc -l) && !$force_uninstall )); then + (($restore)) && action='pm enable $REPLY' || action='pm disable-user $REPLY && am force-stop $REPLY && pm clear $REPLY' fi clear printf "\n${RED}${Bold}Package name to $choice :${nBold}${NC} " read - local output=$(eval adb shell $user_choice) + local output=$(eval adb shell $action) echo "$output" - if [[ "$output" != "Failure" ]]; then echo "$REPLY" >> "debloated_packages.txt"; fi + if [[ "$output" != "Failure" ]]; then echo "$REPLY" >> "debloated_packages.txt"; fi + echo + printf "\e[5mPress any key to continue\033[0m" + read -n 1 -s } function restore { @@ -100,45 +103,28 @@ function check_backup_integrity { read -n 1 -s } -function brand_detection { - local brand=$(adb shell getprop ro.product.brand) - if [[ $brand>0 ]]; then - case $brand in - "asus") - echo "asus_bloat" ;; - "huawei") - echo "huawei_bloat" ;; - "lg") - echo "lg_bloat" ;; - "motorola") - echo "motorola_bloat" ;; - "nokia") - echo "nokia_bloat" ;; - "oneplus") - echo "oneplus_bloat" ;; - "samsung") - echo "samsung_bloat" ;; - "sony") - echo "sony_bloat" ;; - "xiaomi") - echo "xiaomi_bloat" ;; - *) - echo "Brand not supported (yet)" ;; - esac - fi -} +####################################################################################################### -clear +adb shell exit +opcode=$? +if (( $opcode )); then printf "${RED}${Bold}Device not connected${NC}\n"; exit -1; fi + +brand=$(adb shell getprop ro.product.brand | awk '{print tolower($0)}') + +option_needed="" # '--user 0' option doesn't exist in Android SDK API version < 20 +if [[ $(adb shell getprop ro.build.version.sdk) > 20 ]]; then option_needed="--user 0"; fi + +#clear printf "\n ================================================\n" printf " # #\n" printf " # UNIVERSAL ANDROID DEBLOAT SCRIPT #\n" printf " # #\n" -printf " # %10s${RED}${Bold}v2.0 (February 4th 2020)${nBold}%11s#\n" +printf " # %10s${RED}${Bold}v2.2 (February 4th 2020)${nBold}%11s#\n" printf " # #\n" printf " ================================================\n" echo -adb devices +#adb devices 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}" read -r @@ -151,18 +137,10 @@ if [[ $REPLY =~ [Yy]+[Ee]*[Ss]* ]]; then check_backup_integrity "${PHONE:-phone}-${backup}.adb"; fi -brand=$(brand_detection) -space=$((25-${#brand})) -if [[ $space =~ "-" ]]; then space="0"; fi - -# --user 0 option doesn't exist in Android SDK API version < 20 -option_needed="" -if [[ $(adb shell getprop ro.build.version.sdk) > 20 ]]; then option_needed="--user 0"; fi - while true; do - clear; - if [[ $(adb shell getprop ro.build.version.release) < 8.0 ]]; then + + if (( $(echo "$(adb shell getprop ro.build.version.release) < 8.0" | bc -l) )); then printf "${RED}${Bold}WARNING : Your android version is too old (< 8.0). Uninstalled packages can't be restored.\n"; printf "By default the script will force-disable the apps instead of uninstalling them so that you can restore them if needed\n\n" printf "If you still want to force-uninstall the apps, type '1' ('0' otherwise): ${NC}" @@ -173,8 +151,8 @@ while true; do 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} 1 - Restore a save ${ORANGE} #\n" + printf "#${NC} 2 - Restore packages ${ORANGE} #\n" printf "#${NC} 3 - Debloat packages ${ORANGE} #\n" printf "#${NC} ${ORANGE} #\n" printf "${Bold}===================================================${NC}${nBold}\n\n" @@ -184,19 +162,18 @@ while true; do echo if [[ $action = 0 ]]; then list; fi + if [[ $action = 1 ]]; then restore; fi - if [[ $action = 2 ]]; then restore; fi - - if [[ $action = 1 || $action = 3 ]]; then + if [[ $action = 2 || $action = 3 ]]; then clear title="DEBLOAT" - action_arg='' - if [[ $action = 1 ]]; then title="RESTORE"; action_arg='r'; fi + restore=0 + if [[ $action = 1 ]]; then title="RESTORE"; restore=1; 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 "#${nBold}${NC}%12s 2 - ${brand} %$((25-${#brand}))s ${ORANGE} #\n" printf "#${NC} 3 - GFAM ${ORANGE} #\n" printf "#${NC} 4 - Carriers ${ORANGE} #\n" printf "#${NC} 5 - Others ${ORANGE} #\n" @@ -211,7 +188,7 @@ while true; do if [[ "$action" =~ 4 ]]; then carrier_choice; fi if [[ "$action" =~ -1 ]]; then debloat pending; fi if [[ "$action" =~ 1 ]]; then remove_or_install_one; fi - if [[ "$action" =~ 2 ]]; then debloat; fi + if [[ "$action" =~ 2 ]]; then debloat $brand; fi if [[ "$action" =~ 3 ]]; then debloat google_bloat && debloat microsoft_bloat && debloat amazon_bloat && debloat facebook_bloat; fi if [[ "$action" =~ 5 ]]; then debloat misc_bloat; fi if [[ "$action" =~ 6 ]]; then debloat aosp_bloat; fi