2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-10-31 09:20:23 +00:00
NanoDroid/uninstaller/META-INF/com/google/android/update-binary
2020-10-19 19:48:03 +02:00

338 lines
9.1 KiB
Bash

#!/sbin/sh
OUTFD=$2
ZIP=$3
BACKUP_DIR="/data/media/0/nanodroid_backups"
VERSION=22.90.99999999
detect_bootmode () {
[ -z ${BOOTMODE} ] && ps | grep zygote | grep -qv grep && BOOTMODE=true
[ -z ${BOOTMODE} ] && ps -A 2>/dev/null | grep zygote | grep -qv grep && BOOTMODE=true
[ -z ${BOOTMODE} ] && BOOTMODE=false
}
ui_print() {
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
}
grep_prop() {
sed -n "s/^${1}=//p" ${build_props} ${2} | head -n 1
}
grep_cmdline() {
local REGEX="s/^${1}=//p"
sed -E 's/ +/\n/g' /proc/cmdline | \
sed -n "${REGEX}" 2>/dev/null
}
is_mounted () {
grep -q " $(readlink -f ${1}) " /proc/mounts 2>/dev/null
return $?
}
set_perm () {
chown ${2}:${3} ${1} || error "failed change owner for ${1}"
chmod ${4} ${1} || error "failed to change mode for ${1}"
if [ -n "${5}" ]; then
chcon ${5} ${1} 2>/dev/null
else chcon 'u:object_r:system_file:s0' ${1} 2>/dev/null
fi
}
set_perm_recursive() {
find ${1} -type d 2>/dev/null | while read dir; do
set_perm ${dir} ${2} ${3} ${4} ${6}
done
find ${1} -type f 2>/dev/null | while read file; do
set_perm ${file} ${2} ${3} ${5} ${6}
done
}
set_perm_data () {
if [ "${1}" = "-r" ]; then
echo " perm: data [recursive] {${2}}"
set_perm_recursive ${2} 0 0 0755 0644
else
echo " perm: data [single] {${1}}"
set_perm ${1} 0 0 0644
fi
}
setup_busybox () {
mkdir /dev/tmp
ABI=$(grep_prop ro.product.cpu.abi | cut -c-3)
ABI2=$(grep_prop ro.product.cpu.abi2 | cut -c-3)
ABILONG=$(grep_prop ro.product.cpu.abi)
ARCH=arm
[ "$ABI" = "x86" ] && ARCH=x86
[ "$ABI2" = "x86" ] && ARCH=x86
[ "$ABILONG" = "arm64-v8a" ] && ARCH=arm64
[ "$ABILONG" = "x86_64" ] && ARCH=x86_64
case ${ARCH} in
arm | arm64 )
unzip -oq "${ZIP}" busybox.arm -d "/dev/tmp"
BUSY=/dev/tmp/busybox.arm
;;
x86 | x86_64 )
unzip -oq "${ZIP}" busybox.x86 -d "/dev/tmp"
BUSY=/dev/tmp/busybox.x86
;;
esac
OLD_PATH=${PATH}
chmod 0755 ${BUSY}
mkdir -p /dev/tmp/busybox
ln -s ${BUSY} /dev/tmp/busybox/busybox
${BUSY} --install -s /dev/tmp/busybox/
export PATH="/dev/tmp/busybox:${PATH}"
}
error () {
ui_print " !!"
ui_print " !! ${@}"
ui_print " !!"
${BOOTMODE} || umount_partitions
exit 1
}
##########################################################################################
# taken from Magisk, with minor modifications for NanoDroid
# mount partitions
##########################################################################################
mount_partitions () {
if ! ${BOOTMODE}; then
DEVICE_AB=FALSE
VENDOR_COMPAT=FALSE
SYSTEM_AS_ROOT=FALSE
SLOT=$(grep_cmdline androidboot.slot_suffix)
echo " INFO: #1 [SLOT] ${SLOT}"
if [ -z ${SLOT} ]; then
SLOT=$(grep_cmdline androidboot.slot)
echo " INFO: #2 [SLOT] ${SLOT}"
if [ -n ${SLOT} ]; then
SLOT=_${SLOT}
echo " INFO: #3 [SLOT] ${SLOT}"
DEVICE_AB=TRUE
fi
fi
system_tmp=$(find /dev/block \( -type b -o -type c -o -type l \) -name system${SLOT} | head -n 1)
echo " INFO: #4 [system_tmp] ${system_tmp}"
SYSTEM_BLOCK=$(readlink -f ${system_tmp})
echo " INFO: #5 [SYSTEM_BLOCK] ${SYSTEM_BLOCK}"
is_mounted /data || mount /data || error "failed to mount /data!"
mount -o bind /dev/urandom /dev/random
SYSTEM_AS_ROOT=$(grep_prop ro.build.ab_update /default.prop)
if [ -e /system_root -o ${SYSTEM_AS_ROOT} ]; then
[ -L /system_root ] && mv /system_root /system_root_link
if [ ! -d /system_root ]; then
rm -rf /system_root
mkdir -p /system_root
fi
! is_mounted /system_root && mount -o rw /system_root
! is_mounted /system_root && mount -o rw ${SYSTEM_BLOCK} /system_root
mount -o bind /system_root/system /system
else
! is_mounted /system && mount -o rw /system
! is_mounted /system && mount -o rw ${SYSTEM_BLOCK} /system
fi
vendor_tmp=$(find /dev/block \( -type b -o -type c -o -type l \) -name vendor${SLOT} | head -n 1)
echo " INFO: #6 [vendor_tmp] ${vendor_tmp}"
VENDOR_BLOCK=$(readlink -f ${vendor_tmp})
echo " INFO: #7 [VENDOR_BLOCK] ${VENDOR_BLOCK}"
! is_mounted /vendor && mount -o ro /vendor
! is_mounted /vendor && mount -o ro ${VENDOR_BLOCK} /vendor
if [[ ! $(is_mounted /vendor) && -d /system/vendor ]]; then
### XXX work-around required for some devices
VENDOR_COMPAT=TRUE
ln -sf /system/vendor /vendor >/dev/null
fi
echo " "
mount | sed -e '/magisk/d' | awk '{print $1 " on " $3 " params: " $6}'
echo " "
echo " INFO: #8 [prop]"
ls -l /system/*.prop
[ -d /system/apex ] && mount_apex
fi
build_props=$(find /system /system_root /vendor -type f -name build.prop)
[ -z "${build_props}" ] && error "failed to mount /system (unsupported A/B device?)"
if [ -d /apex/com.android.art ]; then
export ANDROID_ART_ROOT=/apex/com.android.art
export ANDROID_RUNTIME_ROOT=${ANDROID_ART_ROOT}
elif [ -d /apex/com.android.runtime ]; then
export ANDROID_RUNTIME_ROOT=/apex/com.android.runtime
fi
export ANDROID_TZDATA_ROOT=/apex/com.android.tzdata
export ANDROID_I18N_ROOT=/apex/com.android.i18n
}
##########################################################################################
# taken from Magisk, with minor modifications for NanoDroid
# mount APEX directories or images
##########################################################################################
mount_apex () {
mkdir -p /apex
for apex in /system/apex/*; do
apex_mount="/apex/$(basename ${apex} .apex)"
apex_loop="/dev/loop_apex_$(basename ${apex} .apex)"
[ "${apex_mount}" == /apex/com.android.runtime.release ] && apex_mount=/apex/com.android.runtime
[ "${apex_mount}" == /apex/com.android.runtime.debug ] && apex_mount=/apex/com.android.runtime
[ "${apex_mount}" == /apex/com.android.art.release ] && apex_mount=/apex/com.android.art
[ "${apex_mount}" == /apex/com.android.art.debug ] && apex_mount=/apex/com.android.art
mkdir -p "${apex_mount}"
if [ -f "${apex}" ]; then
unzip -oq "${apex}" apex_payload.img -d /apex
mount_apex_loop "${apex_mount}" || error "APEX loop setup failed!"
elif [ -d "${apex}" ]; then
mount -o bind "${apex}" "${apex_mount}"
fi
done
echo " INFO: #10 [APEX [ALL]] $(ls /system/apex/*)"
}
##########################################################################################
# taken from Magisk, with minor modifications for NanoDroid
# helper function for mounting APEX directories or images
##########################################################################################
mount_apex_loop () {
local number=0
local minorx=1
local loop
[ -e /dev/block/loop1 ] && minorx=$(stat -Lc '%T' /dev/block/loop1)
apex_mount="${1}"
echo " *** mount_apex_loop [apex_mount]: ${apex_mount}"
while [ ${number} -lt 64 ]; do
loop=/dev/block/loop${number}
[ -e ${loop} ] || mknod ${loop} b 7 $((number * minorx))
if losetup "${loop}" /apex/apex_payload.img 2>/dev/null; then
echo " *** mount_apex_loop [loop]: ${loop}"
if mount -text4 -oro,noatime "${loop}" "${apex_mount}"; then
rm -f /apex/apex_payload.img
break
fi
fi
number=$((number + 1))
done
}
##########################################################################################
# unmount partitions
##########################################################################################
umount_partitions () {
umount -l /system_root 2>/dev/null
umount -l /system 2>/dev/null
umount -l /system/vendor 2>/dev/null
umount -l /vendor 2>/dev/null
umount -l /dev/random 2>/dev/null
mount | awk '/ \/apex/{print $1 " " $3}' | while read apex_loop apex_mount; do
umount -l "${apex_mount}" 2>/dev/null
losetup -d "${apex_loop}" 2>/dev/null
done
rm -rf /apex
unset ANDROID_RUNTIME_ROOT
unset ANDROID_TZDATA_ROOT
}
# check for configuration files
config_locations="/data/media/0 /external_sd /sdcard1 /data $(dirname ${ZIP}))"
config_files=".nanodroid-setup .nanodroid-apps .nanodroid-overlay"
system_mode_uninstall () {
ui_print " << uninstalling: NanoDroid (System)"
ui_print " << using: ${1}"
system_list=${1}
xargs rm < ${system_list} || error "failed to remove files"
rm -f "${system_list}"
}
ui_print " "
ui_print "**********************"
ui_print " NanoDroid "
ui_print " Uninstaller "
ui_print " ${VERSION} "
ui_print "**********************"
ui_print " "
detect_bootmode
mount_partitions
ui_print " << Removing installation logs (if any)"
# new format
rm -rf /data/media/0/nanodroid_logs
# System Mode uninstallation
[ -f /data/adb/NanoDroid_FileList ] && system_mode_uninstall /data/adb/NanoDroid_FileList
[ -f /system/addon.d/NanoDroid_FileList ] && system_mode_uninstall /system/addon.d/NanoDroid_FileList
# remove Patcher
rm -rf /data/adb/nanodroid_patcher
rm -f /system/addon.d/70-nanodroidpatcher.sh
rm -f /data/adb/NanoDroid_Patched
for module in NanoDroid NanoDroid_microG NanoDroid_FDroid \
NanoDroid_BromiteWebView NanoDroid_OsmAnd \
NanoDroid_Google NanoDroid_Pather; do
if [ -d /data/adb/modules/${module} ]; then
ui_print " << uninstalling: ${module}"
rm -rf /data/adb/modules/${module}
fi
done
ui_print " >> clean up"
${BOOTMODE} || umount_partitions
ui_print " "
ui_print " > Done!"
ui_print " "
ui_print "Thanks for giving NanoDroid a try"
ui_print " "
exit 0