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

355 lines
9.2 KiB
Plaintext
Raw Normal View History

2018-01-23 20:11:52 +00:00
#!/sbin/sh
OUTFD=$2
ZIP=$3
BACKUP_DIR="/data/media/0/nanodroid_backups"
2021-03-04 19:48:34 +00:00
VERSION=23.2.99999999
2018-01-23 20:11:52 +00:00
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
}
2018-01-23 20:11:52 +00:00
ui_print() {
2021-01-17 17:38:31 +00:00
echo -e "ui_print $1" >> /proc/self/fd/$OUTFD
echo -e "ui_print" >> /proc/self/fd/$OUTFD
2018-01-23 20:11:52 +00:00
}
grep_prop() {
2020-10-20 16:45:09 +00:00
sed -n "s/^${1}=//p" /system/build.prop ${2} | head -n 1
}
grep_cmdline() {
local REGEX="s/^${1}=//p"
sed -E 's/ +/\n/g' /proc/cmdline | \
sed -n "${REGEX}" 2>/dev/null
2018-01-23 20:11:52 +00:00
}
2020-10-18 07:39:48 +00:00
is_mounted () {
grep -q " $(readlink -f ${1}) " /proc/mounts 2>/dev/null
2018-01-23 20:11:52 +00:00
return $?
}
set_perm () {
chown ${2}:${3} ${1} || error "failed change owner for ${1}"
chmod ${4} ${1} || error "failed to change mode for ${1}"
2020-10-04 16:22:13 +00:00
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
}
2018-08-26 16:59:34 +00:00
setup_busybox () {
mkdir /dev/tmp
unzip -oq "${ZIP}" busybox.arm -d "/dev/tmp"
unzip -oq "${ZIP}" busybox.x86 -d "/dev/tmp"
2018-08-26 16:59:34 +00:00
case $(uname -m) in
2021-01-17 12:40:37 +00:00
arm* | aarch* ) local bb_arch=arm ;;
x86* ) local bb_arch=x86 ;;
* ) error "arch \"$(uname -m)\" is not supported"
esac
2018-08-26 16:59:34 +00:00
mkdir -p /dev/tmp/busybox
ln -s /dev/tmp/busybox.${bb_arch} /dev/tmp/busybox/busybox
2018-08-26 16:59:34 +00:00
chmod 0755 /dev/tmp/busybox.${bb_arch}
/dev/tmp/busybox.${bb_arch} --install -s /dev/tmp/busybox/
2018-08-26 16:59:34 +00:00
OLD_PATH=${PATH}
export PATH=/dev/tmp/busybox:/system/bin:/vendor/bin
2018-08-26 16:59:34 +00:00
}
2018-01-23 20:11:52 +00:00
error () {
ui_print " !!"
ui_print " !! ${@}"
ui_print " !!"
2020-10-17 19:49:38 +00:00
${BOOTMODE} || umount_partitions
2018-01-23 20:11:52 +00:00
exit 1
}
2020-08-11 19:25:48 +00:00
2020-10-17 19:49:38 +00:00
##########################################################################################
# taken from Magisk, with minor modifications for NanoDroid
# mount partitions
##########################################################################################
2020-08-11 19:25:48 +00:00
2021-01-12 20:53:59 +00:00
toupper() {
echo "$@" | tr '[:lower:]' '[:upper:]'
}
find_block () {
2021-01-17 17:38:31 +00:00
local block partname devname device
2021-01-12 20:53:59 +00:00
block=${1}${SLOT}
device=$(find /dev/block \( -type b -o -type c -o -type l \) -name ${block} | head -n 1)
2021-01-17 17:38:31 +00:00
if [ -n "$device" ]; then
readlink -f "$device"
2021-01-12 20:53:59 +00:00
return 0
fi
2021-01-12 20:53:59 +00:00
for uevent in /sys/dev/block/*/uevent; do
partname=$(awk -F= '/PARTNAME/{print $2}' ${uevent})
devname=$(awk -F= '/DEVNAME/{print $2}' ${uevent})
if [ "$(toupper ${block})" = "$(toupper ${partname})" ]; then
echo /dev/block/${devname}
return 0
fi
done
device=$(find /dev \( -type b -o -type c -o -type l \) -maxdepth 1 -iname ${block} | head -n 1)
2021-01-17 17:38:31 +00:00
if [ -n "$device" ]; then
readlink -f "$device"
2021-01-12 20:53:59 +00:00
return 0
fi
return 1
}
2020-10-17 19:49:38 +00:00
mount_partitions () {
if ! ${BOOTMODE}; then
VENDOR_COMPAT=FALSE
SYSTEM_AS_ROOT=FALSE
SLOT=$(grep_cmdline androidboot.slot_suffix)
if [ -z ${SLOT} ]; then
SLOT=$(grep_cmdline androidboot.slot)
2021-01-12 20:53:59 +00:00
[ -z ${SLOT} ] || SLOT=_${SLOT}
2020-10-17 19:49:38 +00:00
fi
2021-01-12 20:53:59 +00:00
[ -z ${SLOT} ] && DEVICE_AB=FALSE || DEVICE_AB=TRUE
2021-01-18 17:52:55 +00:00
echo " INFO: #1 [SLOT] ${SLOT}"
2020-08-11 19:25:48 +00:00
2021-01-18 17:52:55 +00:00
is_mounted /data || mount /data || echo "failed to mount /data!"
2020-08-11 19:25:48 +00:00
2020-10-17 19:49:38 +00:00
mount -o bind /dev/urandom /dev/random
SYSTEM_BLOCK=$(find_block system)
2021-01-18 17:52:55 +00:00
echo " INFO: #5 [SYSTEM_BLOCK] ${SYSTEM_BLOCK}"
2021-01-12 20:53:59 +00:00
if is_mounted /system_root; then
umount /system 2&>/dev/null
umount /system_root 2&>/dev/null
fi
mkdir -p /system /system_root
mount -o rw ${SYSTEM_BLOCK} /system
if [ -f /system/build.prop ]; then
SYSTEM=/system
elif [ -f /system/system/build.prop -o -f /system/init -o -L /system/init ]; then
SYSTEM_AS_ROOT=true
SYSTEM=/system/system
if ! mount --move /system /system_root; then
umount /system
umount -l /system
2021-01-12 20:53:59 +00:00
mount -o rw ${SYSTEM_BLOCK} /system_root
2020-08-11 19:25:48 +00:00
fi
mount -o bind /system_root/system /system
2019-10-12 18:00:52 +00:00
fi
2020-08-11 19:25:48 +00:00
VENDOR_BLOCK=$(find_block vendor)
2020-10-17 19:49:38 +00:00
echo " INFO: #7 [VENDOR_BLOCK] ${VENDOR_BLOCK}"
2019-10-08 18:48:47 +00:00
2020-10-17 19:49:38 +00:00
! is_mounted /vendor && mount -o ro /vendor
! is_mounted /vendor && mount -o ro ${VENDOR_BLOCK} /vendor
2019-10-08 18:48:47 +00:00
2020-10-17 19:49:38 +00:00
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
2020-08-11 19:25:48 +00:00
2020-10-17 19:49:38 +00:00
echo " "
mount | sed -e '/magisk/d' | awk '{print $1 " on " $3 " params: " $6}'
echo " "
2020-08-11 19:25:48 +00:00
2020-10-17 19:49:38 +00:00
echo " INFO: #8 [prop]"
ls -l /system/*.prop
2020-08-11 19:25:48 +00:00
2020-10-17 19:49:38 +00:00
[ -d /system/apex ] && mount_apex
fi
2020-08-18 08:43:47 +00:00
2020-10-20 16:45:09 +00:00
[ ! -f /system/build.prop ] && error "failed to mount /system (unsupported A/B device?)"
2020-08-11 19:25:48 +00:00
2020-10-17 19:49:38 +00:00
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
2020-08-11 19:25:48 +00:00
export ANDROID_RUNTIME_ROOT=/apex/com.android.runtime
2019-10-08 18:48:47 +00:00
fi
2020-08-11 19:25:48 +00:00
2020-10-17 19:49:38 +00:00
export ANDROID_TZDATA_ROOT=/apex/com.android.tzdata
2020-10-17 20:01:14 +00:00
export ANDROID_I18N_ROOT=/apex/com.android.i18n
}
2020-10-17 19:49:38 +00:00
##########################################################################################
# taken from Magisk, with minor modifications for NanoDroid
2020-10-17 19:49:38 +00:00
# mount APEX directories or images
##########################################################################################
mount_apex () {
mkdir -p /apex
2020-10-17 19:49:38 +00:00
for apex in /system/apex/*; do
apex_mount="/apex/$(basename ${apex} .apex)"
apex_loop="/dev/loop_apex_$(basename ${apex} .apex)"
2020-10-17 19:49:38 +00:00
[ "${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
2019-10-08 18:48:47 +00:00
2020-10-17 19:49:38 +00:00
mkdir -p "${apex_mount}"
2020-09-30 19:21:41 +00:00
2020-10-17 19:49:38 +00:00
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
2020-10-17 19:49:38 +00:00
done
2020-10-17 19:49:38 +00:00
echo " INFO: #10 [APEX [ALL]] $(ls /system/apex/*)"
}
2019-10-29 18:38:41 +00:00
2020-10-17 19:49:38 +00:00
##########################################################################################
# taken from Magisk, with minor modifications for NanoDroid
# helper function for mounting APEX directories or images
##########################################################################################
2019-10-08 18:48:47 +00:00
2020-10-17 19:49:38 +00:00
mount_apex_loop () {
local number=0
local minorx=1
local loop
2019-10-29 18:38:41 +00:00
2020-10-17 19:49:38 +00:00
[ -e /dev/block/loop1 ] && minorx=$(stat -Lc '%T' /dev/block/loop1)
2019-01-12 09:23:18 +00:00
2020-10-17 19:49:38 +00:00
apex_mount="${1}"
2020-10-17 19:49:38 +00:00
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
}
2020-10-17 19:49:38 +00:00
##########################################################################################
# unmount partitions
##########################################################################################
umount_partitions () {
umount -l /system_root 2>/dev/null
umount -l /system 2>/dev/null
2020-10-17 19:49:38 +00:00
umount -l /system/vendor 2>/dev/null
umount -l /vendor 2>/dev/null
umount -l /dev/random 2>/dev/null
2020-10-17 19:49:38 +00:00
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
2020-10-17 19:49:38 +00:00
rm -rf /apex
unset ANDROID_RUNTIME_ROOT
unset ANDROID_TZDATA_ROOT
}
2018-01-23 20:11:52 +00:00
# check for configuration files
2020-11-02 19:47:03 +00:00
config_locations="/data/media/0 /external_sd /sdcard1 /data $(dirname ${ZIP})) /system/addon.d /tmp"
config_files=".nanodroid-setup .nanodroid-apps .nanodroid-overlay"
2018-01-23 20:11:52 +00:00
system_mode_uninstall () {
ui_print " << uninstalling: NanoDroid (System)"
ui_print " << using: ${1}"
system_list=${1}
2018-01-23 20:11:52 +00:00
xargs rm < ${system_list} || error "failed to remove files"
2018-01-23 20:11:52 +00:00
rm -f "${system_list}"
}
2018-01-23 20:11:52 +00:00
ui_print " "
ui_print "**********************"
ui_print " NanoDroid "
ui_print " Uninstaller "
ui_print " ${VERSION} "
ui_print "**********************"
2018-01-23 20:11:52 +00:00
ui_print " "
detect_bootmode
setup_busybox
mount_partitions
2018-01-23 20:11:52 +00:00
ui_print " << Removing installation logs (if any)"
2019-05-11 19:33:15 +00:00
# new format
rm -rf /data/media/0/nanodroid_logs
2018-01-23 20:11:52 +00:00
# System Mode uninstallation
[ -f /data/adb/NanoDroid_FileList ] && system_mode_uninstall /data/adb/NanoDroid_FileList
2020-10-17 21:48:48 +00:00
[ -f /system/addon.d/NanoDroid_FileList ] && system_mode_uninstall /system/addon.d/NanoDroid_FileList
2020-10-09 18:10:47 +00:00
# remove Patcher
rm -rf /data/adb/nanodroid_patcher
rm -f /system/addon.d/70-nanodroidpatcher.sh
rm -f /data/adb/NanoDroid_Patched
2018-01-23 20:11:52 +00:00
2019-06-10 17:42:38 +00:00
for module in NanoDroid NanoDroid_microG NanoDroid_FDroid \
2020-10-09 18:10:47 +00:00
NanoDroid_BromiteWebView NanoDroid_OsmAnd \
NanoDroid_Google NanoDroid_Pather; do
2019-06-10 17:42:38 +00:00
if [ -d /data/adb/modules/${module} ]; then
ui_print " << uninstalling: ${module}"
rm -rf /data/adb/modules/${module}
fi
done
2019-04-03 20:13:38 +00:00
2018-01-23 20:11:52 +00:00
ui_print " >> clean up"
${BOOTMODE} || umount_partitions
2018-01-23 20:11:52 +00:00
ui_print " "
ui_print " > Done!"
ui_print " "
ui_print "Thanks for giving NanoDroid a try"
ui_print " "
exit 0