2020-06-20 12:10:44 +12:00
#!/usr/bin/env bash
2021-01-11 07:59:33 +13:00
# BASH 4.4 or newer is needed!
if ( ( " ${ BASH_VERSINFO [0] } " < 5 ) ) ; then printf "\n%s\n\n" "Please upgrade to a bash version >= 4.4" && exit 1; fi
2020-03-12 10:46:16 +13:00
2020-09-12 10:20:06 +12:00
if ! adb get-state & >/dev/null; then printf "\n%s\n\n" "Your phone is not detected by ADB." && exit 1; fi
2020-08-16 05:47:59 +12:00
2021-01-11 07:59:33 +13:00
set -Eeuo pipefail # Safer bash script
2020-05-21 11:28:37 +12:00
2020-06-16 04:37:44 +12:00
readonly BRED = '\033[1;31m' # Bold + Red
readonly BBLUE = '\033[0;34m' # Bold + Blue
2020-08-17 10:49:31 +12:00
readonly BGREEN = '\033[1;32m'
2020-06-16 04:37:44 +12:00
readonly BORANGE = '\033[1;33m'
readonly NC = '\033[0m' # No Color
readonly Bold = $( tput bold)
readonly nBold = $( tput sgr0)
# Trap error
2021-01-11 07:59:33 +13:00
trap 'catch $LINENO' ERR
2020-06-16 04:37:44 +12:00
catch( ) {
2020-09-12 10:20:06 +12:00
( ( $? = = 0 ) ) && exit 0;
2021-01-11 07:59:33 +13:00
printf " \n\n ${ BRED } %s\n " " [EXIT TRAP] Hum... something is wrong. Error on line $1 "
2020-09-12 10:20:06 +12:00
printf "\n%s\n" "If you think this is a bug. Please report it :)"
printf " %s ${ NC } \n\n " "==> https://gitlab.com/W1nst0n/universal-android-debloater/-/issues"
2020-06-16 04:37:44 +12:00
}
2020-05-21 11:28:37 +12:00
# Include debloat lists
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
2020-07-17 05:02:02 +12:00
############################################### MAIN SCRIPT ##########################################################
2020-05-21 11:28:37 +12:00
2020-07-17 05:02:02 +12:00
main( ) {
2021-01-12 06:33:03 +13:00
readonly VERSION = "v2.8.2 (January 11th 2021)"
2020-07-17 05:02:02 +12:00
readonly PAD = $(( ( 48 - ${# VERSION } ) / 2 ))
2020-03-18 04:24:39 +13:00
2020-07-17 05:02:02 +12:00
readonly BRAND = " $( get_brand) "
readonly BRAND_SUPPORTED = $( declare -p " $BRAND " & >/dev/null && echo "1" || echo "0" )
2021-01-11 07:59:33 +13:00
readonly OLDER_THAN_ANDROID_8 = $(( $( adb shell getprop ro.build.version.sdk | tr -d '\r' ) < 26 ))
2020-09-19 08:27:25 +12:00
readonly OLDER_THAN_ANDROID_5 = $(( $( adb shell getprop ro.build.version.sdk | tr -d '\r' ) < 21 ))
2020-09-12 10:20:06 +12:00
2021-01-11 07:59:33 +13:00
declare -a CUSTOM_LIST = ( ) # Trimed APK/package list from the debloat lists only containing packages/APK on the device (populated by generate_custom_list())
declare -a EXTERNAL_LIST = ( ) # APK/package list provided by the user (populated by import_external_list())
declare -a USERS = ( ) # User list (populated by debloat_or_restore())
declare -ra LISTS = ( us_carriers french_carrier german_carriers " $BRAND " google facebook amazon microsoft \
qualcomm mediatek misc aosp pending)
2020-07-17 05:02:02 +12:00
2021-01-11 07:59:33 +13:00
declare -i FORCE_UNINSTALL = 0
declare -i RESTORE = 0
declare -i ROOT = 0
2020-05-21 11:28:37 +12:00
clear
2021-01-11 07:59:33 +13:00
printf " \n ${ BORANGE } %s\n " "================================================"
printf "%s\n" "# #"
printf " %-8s ${ NC } %s ${ BORANGE } %8s\n " "#" "UNIVERSAL ANDROID DEBLOAT SCRIPT" "#"
printf "%s\n" "# #"
printf " %- ${ PAD } s ${ BRED } %s ${ BORANGE } % ${ PAD } s\n " "#" " ${ VERSION } " "#"
printf "%s\n" "# #"
printf " %s ${ NC } \n\n " "================================================"
2020-06-16 04:37:44 +12:00
printf " ${ Bold } %s\n\n " "Please carefully read the FAQ before using this script!"
2020-09-19 08:27:25 +12:00
2021-01-11 07:59:33 +13:00
if [ [ $( adb get-state) = "recovery" ] ] ; then uad_recovery_mode || exit; fi
printf " %s ${ nBold } " "Do you want to do an ADB backup ? [Y/N]"
2020-05-21 11:28:37 +12:00
read -r
if [ [ $REPLY = ~ [ Yy] +[ Ee] *[ Ss] * ] ] ; then backup; fi
2021-01-11 07:59:33 +13:00
if ( ( OLDER_THAN_ANDROID_8 ) ) ; then
2020-05-21 11:28:37 +12:00
clear
printf " \n ${ BRED } %s " "WARNING : Your android version is too old (< 8.0)."
printf " %s ${ NC } \n\n " "Uninstalled packages can't be restored."
printf "%s" "The script will force-disable the apps instead of uninstalling them"
printf "%s\n\n" "so that you can restore them if needed"
printf "%s " "If you still want to force-uninstall the apps, type '1' ('0' otherwise):"
read -r -n 1 FORCE_UNINSTALL
fi
while true; do
2020-09-12 10:20:06 +12:00
2020-10-05 10:25:48 +13:00
adb shell 'pm list packages -s' | sed 's/package://g' > remaining_packages.txt &
2020-09-12 10:20:06 +12:00
2021-01-11 07:59:33 +13:00
clear -x
printf " \n ${ BORANGE } %s\n " "================== MAIN MENU =================="
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BORANGE } %16s\n " "#" "0 - Packages search" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %15s\n " "#" "1 - Restore a backup" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %15s\n " "#" "2 - Restore packages" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %15s\n " "#" "3 - Debloat packages" "#"
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BORANGE } %12s\n " "#" "4 - Restore APKs (Root)" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %12s\n " "#" "5 - Debloat APKs (Root)" "#"
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BORANGE } %6s\n " "#" "X - Exit and reboot the phone" "#"
printf "%s\n" "# #"
printf " %s ${ NC } \n\n " "================================================="
2020-05-21 11:28:37 +12:00
2020-09-12 10:20:06 +12:00
printf " ${ BRED } %s ${ NC } \n\n " "DON'T FORGET TO REBOOT YOUR PHONE ONCE THE DEBLOAT IS OVER."
2020-05-21 11:28:37 +12:00
read -r -p "Choose an action : "
2020-09-12 10:20:06 +12:00
if [ [ $REPLY = 0 ] ] ; then list_installed_packages;
2020-05-21 11:28:37 +12:00
2020-09-12 10:20:06 +12:00
elif [ [ $REPLY = 1 ] ] ; then restore_backup;
2020-05-21 11:28:37 +12:00
2021-01-11 07:59:33 +13:00
elif [ [ $REPLY = 2 || $REPLY = 3 || $REPLY = 4 || $REPLY = 5 ] ] ; then
clear -x
2020-05-21 11:28:37 +12:00
( ( !BRAND_SUPPORTED ) ) && printf " \n ${ BRED } %s\n " " No $BRAND debloat list found. Feel free to contribute ! :) "
2021-01-11 07:59:33 +13:00
case $REPLY in
2) { title = "RESTORE" ; RESTORE = 1; } ; ;
3) { title = "DEBLOAT" ; RESTORE = 0; } ; ;
4) { title = "RESTORE" ; RESTORE = 1; ROOT = 1; } ; ;
5) { title = "DEBLOAT" ; RESTORE = 0; ROOT = 1; } ; ;
esac
( ( !ROOT) ) && printf " \n ${ BORANGE } %s\n " " =================== $title =================== "
( ( ROOT ) ) && printf " \n ${ BORANGE } %s\n " " ================ $title (ROOT) =============== "
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BORANGE } %14s\n " "#" " 1 - $title a package " "#" | awk '{print tolower($0)}'
( ( BRAND_SUPPORTED ) ) && printf " # ${ NC } %8s 2 - ${ BRAND } % $(( 25 - ${# BRAND } )) s ${ BORANGE } #\n "
printf " %-12s ${ NC } %s ${ BORANGE } %27s\n " "#" "3 - GFAM" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %23s\n " "#" "4 - Carriers" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %25s\n " "#" "5 - Others" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %27s\n " "#" "6 - AOSP" "#"
printf " %-12s ${ NC } %s ${ BORANGE } %18s\n " "#" "7 - External list" "#"
( ( ROOT && !RESTORE ) ) && printf " # ${ NC } %7s 8 - Create a flashable zip ${ BORANGE } %7s #\n "
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BORANGE } %15s\n " "#" "0 - Pending list /!\\" "#"
printf "%s\n" "# #"
printf " %s\n ${ NC } \n " "================================================="
read -r -p "Your selection (e.g: 2 3 4 5): "
if [ [ " $REPLY " = ~ 7 ] ] ; then import_external_list && debloat_or_restore EXTERNAL_LIST; fi
2020-05-21 11:28:37 +12:00
if [ [ " $REPLY " = ~ 4 ] ] ; then lists_selection us_carriers french_carriers german_carriers; fi
if [ [ " $REPLY " = ~ 3 ] ] ; then lists_selection google facebook amazon microsoft; fi
if [ [ " $REPLY " = ~ 1 ] ] ; then debloat_or_restore; fi
2021-01-11 07:59:33 +13:00
if [ [ " $REPLY " = ~ 2 ] ] ; then debloat_or_restore " $BRAND " ; fi
if [ [ " $REPLY " = ~ 5 ] ] ; then lists_selection qualcomm mediatek misc; fi
if [ [ " $REPLY " = ~ 6 ] ] ; then debloat_or_restore aosp; fi
if [ [ " $REPLY " = ~ 8 ] ] ; then create_flashable_zip; fi
if [ [ " $REPLY " = ~ 0 ] ] ; then debloat_or_restore pending; fi
2020-09-19 08:27:25 +12:00
elif [ [ " $REPLY " = ~ [ Xx] ] ] ; then adb reboot && exit 0;
2020-05-21 11:28:37 +12:00
2020-09-12 10:20:06 +12:00
fi
2020-05-21 11:28:37 +12:00
done
2019-03-31 02:55:40 +13:00
}
2020-05-21 11:28:37 +12:00
############################################ END OF MAIN SCRIPT ######################################################
2020-03-18 04:24:39 +13:00
2021-01-11 07:59:33 +13:00
import_external_list( ) {
2020-10-05 10:25:48 +13:00
local path = ""
2021-01-11 07:59:33 +13:00
while true; do
printf " \n ${ BRED } %s ${ NC } " "Path to the list: "
read -r path
if readarray -t EXTERNAL_LIST < " $path " ; then break; fi
done
for i in " ${ EXTERNAL_LIST [@] } " ; do
if [ [ ROOT -eq 1 && $i = ~ ^/.*\. apk$ ] ] ; then
printf " \n ${ BRED } %s ${ NC } \n\n " "Please use a package list, not an APK list"
exit 1
elif [ [ ROOT -eq 0 && ! $i = ~ ^[ a-z] [ a-zA-Z0-9_] *( \. [ a-zA-Z0-9_] +) +[ 0-9a-zA-Z_] $ ] ] ; then
printf " \n ${ BRED } %s ${ NC } %s ${ BRED } %s ${ NC } %s\n\n " " $i " " is not a package (format is" " com.android.bips" ")"
exit 1
fi
done
}
associate_path_with_package( ) {
local -n ASSOCIATE = " $1 "
declare -a PACKAGES = ( )
readarray -t PACKAGES < <( adb shell 'pm list packages -s -u -f' | sed -r 's/package://g' | sort -i)
for i in " ${ PACKAGES [@] } " ; do
ASSOCIATE[ " ${ i ##*= } " ] = " ${ i %%=* } "
done
2020-10-05 10:25:48 +13:00
}
2021-01-11 07:59:33 +13:00
generate_custom_list( ) {
local -n list = " $1 "
[ [ $# -eq 2 ] ] && local user_id = " $2 "
CUSTOM_LIST = ( )
2020-10-05 10:25:48 +13:00
2021-01-11 07:59:33 +13:00
if ( ( ROOT ) ) ; then
declare -A PACKAGE_AND_PATH = ( ) # PACKAGE_AND_PATH[package]=path/to/apk
declare -a TEMP = ( )
associate_path_with_package PACKAGE_AND_PATH
readarray -t TEMP < <( comm -12 <( for p in " ${ list [@] } " ; do echo " ${ p } " ; done | sort -i) \
<( for p in " ${ !PACKAGE_AND_PATH[@] } " ; do echo " $p " ; done | sort -i) )
for p in " ${ TEMP [@] } " ; do
CUSTOM_LIST += ( " ${ PACKAGE_AND_PATH [ $p ] } " )
done
2020-09-12 10:20:06 +12:00
2021-01-11 07:59:33 +13:00
[ [ RESTORE -eq 1 ] ] && readarray -t CUSTOM_LIST < <( comm -12 <( for p in " ${ CUSTOM_LIST [@] } " ; do echo " ${ p } " ; done | sort -i) \
<( sort -i deleted_apks.txt) )
2020-09-12 11:05:57 +12:00
else
2021-01-11 07:59:33 +13:00
if ( ( RESTORE ) ) ; then
readarray -t CUSTOM_LIST < <( comm -12 <( for p in " ${ list [@] } " ; do echo " ${ p } " ; done | sort -i) \
<( adb shell " pm list packages -s -u $user_id " | sed -r 's/package://g' | sort -i) )
else
readarray -t CUSTOM_LIST < <( comm -12 <( for p in " ${ list [@] } " ; do echo " ${ p } " ; done | sort -i) \
<( adb shell " pm list packages -s $user_id " | sed 's/package://g' | sort -i) )
fi
2020-09-12 11:05:57 +12:00
fi
2021-01-11 07:59:33 +13:00
return 0
2020-09-12 10:20:06 +12:00
}
2020-03-18 04:24:39 +13:00
2020-05-21 11:28:37 +12:00
debloat_or_restore( ) {
local action = "" # restore or debloat
local output = ""
2021-01-11 07:59:33 +13:00
local title = $( echo " $title " | tr '[:upper:]' '[:lower:]' )
2020-05-21 11:28:37 +12:00
# Android 7.1 and older can't reinstall packages
2021-01-11 07:59:33 +13:00
if ( ( OLDER_THAN_ANDROID_8 ) ) ; then
( ( RESTORE ) ) && action = 'pm enable $package' || action = 'am force-stop $package && pm disable-user $package && pm clear $package'
2020-05-21 11:28:37 +12:00
fi
2021-01-11 07:59:33 +13:00
( ( RESTORE && FORCE_UNINSTALL = = 1 ) ) && action = 'cmd package install-existing $package' || action = 'pm uninstall $user $package'
2020-05-21 11:28:37 +12:00
2021-01-11 07:59:33 +13:00
# parse user list on the phone
readarray -t USERS < <( adb shell pm list users | grep -o "{[0-9]*" | grep -o "[0-9]*" )
clear -x
2020-07-17 05:02:02 +12:00
if [ [ $# -gt 0 ] ] ; then
2021-01-11 07:59:33 +13:00
local list = " $1 "
printf " \n ${ BORANGE } %s ${ NC } \n " " ==== $list debloat list ==== "
if ( ( ROOT ) ) ; then
generate_custom_list " $list "
if ( ( RESTORE ) ) ; then restore_apks " $list " ; else root_debloat " $list " ; fi
return
fi
2019-12-27 12:57:33 +13:00
2021-01-11 07:59:33 +13:00
for u in " ${ USERS [@] } " ; do
local user = $( ( ( OLDER_THAN_ANDROID_5) ) && echo "" || echo " --user $u " )
generate_custom_list " $list " " $user "
2020-09-12 10:20:06 +12:00
2021-01-11 07:59:33 +13:00
if [ [ ${# CUSTOM_LIST [@] } -eq 0 ] ] ; then
printf " ${ BBLUE } %s ${ NC } %s " " [user $u ] " " Nothing to $title :) " && sleep 1 && continue
fi
2020-07-17 05:02:02 +12:00
2021-01-11 07:59:33 +13:00
for package in " ${ CUSTOM_LIST [@] } " ; do
do_package_action_and_log " $package " " $action " " $u "
done
2020-05-21 11:28:37 +12:00
done
2021-01-11 07:59:33 +13:00
sleep 1
2020-05-21 11:28:37 +12:00
else
2021-01-11 07:59:33 +13:00
if ( ( ROOT ) ) ; then
if ( ( RESTORE ) ) ; then restore_apks; else root_debloat; fi
return
fi
printf " \n ${ BRED } %s ${ NC } " " Package name to $title : "
2020-05-21 11:28:37 +12:00
read -r package
2021-01-11 07:59:33 +13:00
for u in " ${ USERS [@] } " ; do
local user = $( ( ( OLDER_THAN_ANDROID_5) ) && echo "" || echo " --user $u " )
do_package_action_and_log " $package " " $action " " $u "
done
sleep 1
fi
}
do_package_action_and_log( ) {
local package = " $1 "
local action = " $2 "
local user = " $3 "
printf " ${ BBLUE } %s ${ BRED } %s ${ NC } %s " " [user $user ] " " $package --> "
output = " $( eval adb shell " $action " ) " && echo " $output "
if [ [ ! " $output " = ~ Failure| Error ] ] ; then
if [ [ $RESTORE -eq 0 ] ] ; then
grep -qxF " $package " debloated_packages.txt || echo " $package " >> "debloated_packages.txt"
else
grep -qFv " $package " debloated_packages.txt > temp.tmp || touch temp.tmp; mv temp.tmp debloated_packages.txt
fi
fi
}
backup_apks( ) {
printf " \n%s ${ BRED } %s ${ NC } %s\n\n " "Your apks are beeing backed-up in" " apks_backup/" " (in case you mess up)"
local -n apks = " $1 "
mkdir -p apks_backup
for apk in " ${ apks [@] } " ; do
adb pull " $apk " apks_backup/
done
printf " \n ${ BRED } %s ${ NC } \n\n " "Backup done!"
}
create_flashable_zip( ) {
clear -x
declare -a selection = ( )
2021-01-11 13:33:31 +13:00
local UPDATE_BINARY = "META-INF/com/google/android/update-binary"
2021-01-11 07:59:33 +13:00
echo
for i in " ${ !LISTS[@] } " ; do
printf "%-2s%s\n" " $i " " - ${ LISTS [ $i ] } "
done
printf " \n ${ BRED } %s ${ NC } " "Your choice (e.g 1 2 3) :"
read -r -a selection
2021-01-11 13:33:31 +13:00
mkdir -p META-INF/com/google/android/
echo "#!/sbin/sh" > " $UPDATE_BINARY "
echo "echo 'ui_print --- Universal Android Debloater ---' > /proc/self/fd/\$2" >> " $UPDATE_BINARY "
echo "mount /system" >> " $UPDATE_BINARY "
2021-01-11 07:59:33 +13:00
declare -i is_empty = 1
for list in " ${ selection [@] } " ; do
if ( ( list > ${# LISTS [@] } ) ) || ( ( list < 1 ) ) ; then continue ; fi
generate_custom_list " ${ LISTS [ $list ] } "
2021-01-11 13:33:31 +13:00
backup_apks CUSTOM_LIST
2021-01-11 07:59:33 +13:00
for package in " ${ CUSTOM_LIST [@] } " ; do
2021-01-12 06:33:03 +13:00
echo " rm -rf $package " >> " $UPDATE_BINARY "
2021-01-11 07:59:33 +13:00
done
[ [ $is_empty -eq 1 && ${# CUSTOM_LIST [@] } -gt 0 ] ] && is_empty = 0
done
if [ [ $is_empty -eq 1 ] ] ; then
printf " \n ${ BRED } %s ${ NC } \n " "Nothing to debloat!"
2021-01-11 13:33:31 +13:00
rm -rf META-INF/
else
echo "umount /system" >> " $UPDATE_BINARY "
echo "echo 'ui_print ----- ALL DONE -----' > /proc/self/fd/\$2" >> " $UPDATE_BINARY "
zip -rm flashable_zip_UAD_v2.8.zip META-INF/ 1>/dev/null
printf " \n ${ BRED } %s ${ NC } %s\n " "flashable_zip_UAD_v2.8.zip" " has been generated."
2021-01-11 07:59:33 +13:00
fi
sleep 2
}
restore_apks( ) {
declare -a path = ( )
if [ [ $# -eq 1 ] ] ; then
[ [ ${# CUSTOM_LIST [@] } -eq 0 ] ] && echo "Nothing to restore" && sleep 1 && return 0
printf " \n%s ${ BBLUE } %s ${ NC } %s ${ BBLUE } %s ${ NC } \n\n " "Deleted apks from " " $list " " will be restored from " "apks_backups/"
printf " \n ${ BRED } %s ${ NC } \n\n " "Check your phone: Magisk Manager is probably asking you to grand root permissions for ADB"
else
printf " \n%s ${ BRED } %s ${ NC } %s " "Android Path of the APK to restore (the APK will be restored from " "apks_backups/" "): "
read -r path
if [ [ ! $path = ~ ^/.*\. apk$ ] ] ; then
printf " \n ${ BRED } %s ${ NC } %s ${ BRED } %s ${ NC } %s\n " " $path " "doesn't look like a valid APK path"
sleep 2 && return 0
fi
CUSTOM_LIST = ( " $path " )
fi
adb shell "su -c 'mount -o rw,remount /system'"
for p in " ${ CUSTOM_LIST [@] } " ; do # $p = path/to/app.apk
local apk = $( echo " $p " | sed -r 's/.*\///g' ) # app.apk
local dir = $( dirname " $p " ) # path/to
if adb push " apks_backup/ $apk " /sdcard && adb shell " su -c 'mkdir -p \" $dir \"; mv \"/sdcard/ $apk \" \" $dir \"; chmod 644 \" $p \"' " ; then
grep -Fqv " $p " deleted_apks.txt > temp.tmp || touch temp.tmp; mv temp.tmp deleted_apks.txt
fi
done
adb shell "su -c 'mount -o ro,remount /system'"
printf " \n ${ BRED } %s ${ NC } %s\n " "Reboot your phone and Android will reinstall the app(s)"
printf "\n\e[5m%s\033[0m" "Press any key to continue"
read -n 1 -r -s
}
root_debloat( ) {
if [ [ $# -eq 1 ] ] ; then
[ [ ${# CUSTOM_LIST [@] } -eq 0 ] ] && echo "Nothing to debloat :)" && sleep 1 && return 0
2020-07-17 05:02:02 +12:00
2021-01-11 07:59:33 +13:00
backup_apks CUSTOM_LIST
else
printf " \n ${ BRED } %s ${ NC } " "Android Path of the APK to delete: "
read -r path
if [ [ ! $path = ~ ^/.*\. apk$ ] ] ; then
printf " \n ${ BRED } %s ${ NC } %s ${ BRED } %s ${ NC } %s\n " " $path " " doesn't look like a valid APK path"
sleep 2 && return 0
fi
CUSTOM_LIST = ( " $path " )
fi
read -r -p "Type YES if you want to physically delete the apks: "
if [ [ $REPLY = "YES" ] ] ; then
local commandes = "mount -o rw,remount /system;"
for apk in " ${ CUSTOM_LIST [@] } " ; do
grep -qxF " $apk " deleted_apks.txt || echo " $apk " >> "deleted_apks.txt"
commandes += " echo \"rm -rf $apk \"; rm -rf \" $apk \"; "
done
commandes += "mount -o ro,remount /system"
printf " \n ${ BRED } %s ${ NC } \n\n " "Check your phone: Magisk Manager is probably asking you to grand root permissions for ADB"
adb shell " su -c ' $commandes ' "
printf " \n ${ BRED } %s ${ NC } \n " "DONE"
printf " \n%s ${ BRED } %s ${ NC } \n " "A list of deleted apks has been backed-up in " "deleted_apks.txt"
printf "\n\e[5m%s\033[0m" "Press any key to continue"
read -n 1 -r -s
2020-05-21 11:28:37 +12:00
fi
2019-03-31 02:55:40 +13:00
}
2020-05-21 11:28:37 +12:00
lists_selection( ) {
2021-01-11 07:59:33 +13:00
clear -x
declare -a selection = ( )
2020-05-21 11:28:37 +12:00
for ( ( i = 1; i<= $# ; i++) ) ; do
2021-01-11 07:59:33 +13:00
printf "%-2s%s\n" " $i " " - ${ !i } "
2020-05-21 11:28:37 +12:00
done
2021-01-11 07:59:33 +13:00
printf " \n ${ BRED } %s ${ NC } " "Your choice (e.g 1 2 3) :"
2020-06-16 04:37:44 +12:00
read -r -a selection
for list in " ${ selection [@] } " ; do
2020-05-21 11:28:37 +12:00
if ( ( list > $# ) ) || ( ( list < 1 ) ) ; then continue ; fi
2021-01-11 07:59:33 +13:00
debloat_or_restore " ${ !list } "
2020-05-21 11:28:37 +12:00
done
2019-03-31 02:55:40 +13:00
}
2020-05-21 11:28:37 +12:00
list_installed_packages( ) {
2021-01-11 07:59:33 +13:00
clear -x
2020-05-21 11:28:37 +12:00
printf " \n ${ BRED } %s ${ NC } " "Search for packages (regex accepted): "
read -r
echo
2020-10-05 10:25:48 +13:00
adb shell " pm list packages | grep -i $REPLY " | sed 's/package://g' | sort || true
2020-05-21 11:28:37 +12:00
printf "\n\e[5m%s\033[0m" "Press any key to continue"
read -n 1 -r -s
2019-03-31 02:55:40 +13:00
}
2020-05-21 11:28:37 +12:00
restore_backup( ) {
2021-01-11 07:59:33 +13:00
clear -x
2020-05-21 11:28:37 +12:00
printf " ${ BRED } %s ${ NC } " "Enter the path of the backup to restore : "
read -r
check_backup_integrity " $REPLY " && adb restore " $REPLY " || printf " \n ${ BRED } %s ${ NC } \n " "The backup is corrupted. Abort!"
echo
printf "\e[5m%s\033[0m" "Press any key to continue"
read -n 1 -r -s
2019-04-01 01:33:44 +13:00
}
2020-05-21 11:28:37 +12:00
backup( ) {
2021-01-11 07:59:33 +13:00
clear -x
2020-05-21 11:28:37 +12:00
local backup = $( date +%Y-%m-%d-%H:%M:%S)
2020-03-12 10:46:16 +13:00
2020-05-21 11:28:37 +12:00
adb backup -apk -all -system -f " ${ PHONE :- phone } - ${ backup } .adb " # -noshare option is default
echo
printf "\n\e[5m%s\033[0m" "Press a key when the backup is done (your phone will tell you) "
read -n 1 -r -s
check_backup_integrity " ${ PHONE :- phone } - ${ backup } .adb " ;
2020-09-19 08:27:25 +12:00
}
2020-05-21 11:28:37 +12:00
check_backup_integrity( ) {
printf " \n\n ${ BBLUE } %s ${ NC } " " [( $1 )] Backup integrity checking : "
2020-09-19 08:27:25 +12:00
2020-06-16 04:37:44 +12:00
! [ [ -f $1 ] ] && printf " ${ BRED } %s ${ NC } \n\n " "Backup not found" && return 1
2020-05-21 11:28:37 +12:00
# first 24 bytes are skipped (adb backup are modified compressed tar files with a 24B custom header)
2020-10-05 10:25:48 +13:00
if ! dd if = " $1 " bs = 128k skip = 24 iflag = skip_bytes 2>/dev/null | zlib-flate -uncompress | tar tf - & >/dev/null; then
2020-06-16 04:37:44 +12:00
printf " ${ BRED } %s ${ NC } \n\n " "FAILED" && return 1
2020-09-19 08:27:25 +12:00
2020-06-16 04:37:44 +12:00
else printf " ${ BGREEN } %s ${ NC } \n\n " "OK"
fi
2020-05-21 11:28:37 +12:00
}
2019-03-31 02:55:40 +13:00
2020-07-17 05:02:02 +12:00
get_brand( ) {
local brand
brand = $( adb shell getprop ro.product.brand | tr -d '\r' | awk '{print tolower($0)}' )
# Support for alternative name
case " $brand " in
"redmi" ) echo "xiaomi" ; ;
*) echo " $brand "
esac
}
2021-01-11 07:59:33 +13:00
uad_recovery_mode( ) {
ROOT = 1
while true; do
2021-01-11 13:33:31 +13:00
printf " \n ${ BBLUE } %s\n " "========== MAIN MENU (RECOVERY MODE) =========="
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BBLUE } %12s\n " "#" "1 - Restore APKs (Root)" "#"
printf " %-12s ${ NC } %s ${ BBLUE } %12s\n " "#" "2 - Debloat APKs (Root)" "#"
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BBLUE } %6s\n " "#" "X - Exit and reboot the phone" "#"
printf "%s\n" "# #"
printf " %s ${ NC } \n\n " "================================================="
2021-01-11 07:59:33 +13:00
read -r -p "Choose an action : "
case $REPLY in
1) { title = "RESTORE" ; RESTORE = 1; } ; ;
2) { title = "DEBLOAT" ; RESTORE = 0; } ; ;
[ Xx] ) { adb reboot && exit 0; } ; ;
*) exit
esac
clear -x
2021-01-11 13:33:31 +13:00
printf " \n ${ BBLUE } %s\n " " ================ $title (ROOT) =============== "
printf "%s\n" "# #"
printf " %-12s ${ NC } %s ${ BBLUE } %17s\n " "#" " 1 - $title an APK " "#" | awk '{print tolower($0)}'
printf " %-12s ${ NC } %s ${ BBLUE } %18s\n " "#" "2 - External list" "#"
( ( RESTORE) ) && printf " # ${ NC } %9s 3 - deleted_apks.txt ${ BBLUE } %11s#\n "
printf "%s\n" "# #"
printf " %s\n ${ NC } " "================================================="
2021-01-11 07:59:33 +13:00
read -r -p "Choose an action : "
if [ [ $REPLY = 1 ] ] ; then
printf " \n ${ BRED } %s ${ NC } " " Android path of the APK to $title : "
read -r path
if [ [ ! $path = ~ ^/.*\. apk$ ] ] ; then
printf " \n ${ BRED } %s ${ NC } %s ${ BRED } %s ${ NC } %s\n " " $path " " doesn't look like a valid APK path"
sleep 3 && return 0
fi
CUSTOM_LIST = ( " $path " )
fi
if [ [ $REPLY = 2 ] ] ; then import_external_list && CUSTOM_LIST = ( " ${ EXTERNAL_LIST [@] } " ) ; fi
if [ [ $REPLY = 3 && $RESTORE -eq 1 ] ] ; then readarray -t CUSTOM_LIST < "deleted_apks.txt" ; fi
if [ [ RESTORE -eq 0 ] ] ; then
backup_apks CUSTOM_LIST
printf " \n%s ${ BRED } %s ${ NC } %s\n\n " "Your apks has been backed-up in" " apks_backup/" " (in case you messed up)"
fi
for p in " ${ CUSTOM_LIST [@] } " ; do # $p = path/to/app.apk
local apk = $( echo " $p " | sed -r 's/.*\///g' ) # app.apk
local dir = $( dirname " $p " ) # path/to
if [ [ $RESTORE -eq 0 ] ] ; then
adb shell " rm -rf $p " && echo " rm -rf $p "
grep -qxF " $p " deleted_apks.txt || echo " $p " >> "deleted_apks.txt"
else
echo " adb push apks_backup/ $apk /\" $p \" "
if adb shell " mkdir -p $dir " && adb push " apks_backup/ $apk " " / $p " ; then
grep -qFv " $p " deleted_apks.txt > temp.tmp || touch temp.tmp; mv temp.tmp deleted_apks.txt
fi
fi
done
sleep 2
done
}
2020-05-21 11:28:37 +12:00
main " $@ " ; exit