2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-11-07 15:20:36 +00:00
NanoDroid/uninstaller/META-INF/com/google/android/update-binary

288 lines
6.9 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"
2019-07-28 19:02:21 +00:00
VERSION=22.2.20190728
2018-01-23 20:11:52 +00:00
detect_bootmode () {
[ -z ${BOOTMODE} ] && BOOTMODE=false
${BOOTMODE} || ps | grep zygote | grep -qv grep && BOOTMODE=true
2019-05-05 10:25:07 +00:00
${BOOTMODE} || ps -A 2>/dev/null | grep zygote | grep -qv grep && BOOTMODE=true
${BOOTMODE} && error "NanoDroid Uninstaller can't be run from Magisk Manager!"
}
2018-01-23 20:11:52 +00:00
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() {
REGEX="${1}"
2018-01-23 20:11:52 +00:00
shift
FILES="${@}"
[ -z "${@}" ] && FILES='/system/build.prop'
sed -n "s/^${REGEX}=//p" ${FILES} | \
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
}
is_mounted() {
if [ ! -z "$2" ]; then
cat /proc/mounts | grep $1 | grep $2, >/dev/null
else
cat /proc/mounts | grep $1 >/dev/null
fi
return $?
}
set_perm () {
chown ${2}:${3} ${1} || error "failed change owner for ${1}"
chmod ${4} ${1} || error "failed to change mode for ${1}"
if [ ! -z "${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
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 )
2019-04-25 18:49:26 +00:00
unzip -oq "${ZIP}" busybox.arm -d "/dev/tmp"
2018-08-26 16:59:34 +00:00
BUSY=/dev/tmp/busybox.arm
;;
x86 | x86_64 )
2019-04-25 18:49:26 +00:00
unzip -oq "${ZIP}" busybox.x86 -d "/dev/tmp"
2018-08-26 16:59:34 +00:00
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}"
}
2018-01-23 20:11:52 +00:00
error () {
ui_print " !!"
ui_print " !! ${@}"
ui_print " !!"
2018-01-23 20:11:52 +00:00
exit 1
}
# taken from Magisk, with minor modifications for NanoDroid
mount_partitions () {
2018-07-08 17:29:06 +00:00
SLOT=$(grep_cmdline androidboot.slot_suffix)
if [ -z ${SLOT} ]; then
SLOT=_$(grep_cmdline androidboot.slot)
[ "${SLOT}" = "_" ] && SLOT=
fi
2018-09-04 18:07:06 +00:00
is_mounted /data || mount /data || error "failed to mount /data!"
2019-01-12 09:23:18 +00:00
mount -o bind /dev/urandom /dev/random
! is_mounted /system && mount -o rw /system || mount -o rw,remount /system
if [ ! -f /system/build.prop ]; then
SYSTEMBLOCK=$(find /dev/block -iname system${SLOT} | head -n 1)
2019-04-03 20:19:30 +00:00
mount -o rw ${SYSTEMBLOCK} /system
fi
2019-04-03 20:20:04 +00:00
if [ -f /system/init.rc ]; then
2019-07-27 18:25:31 +00:00
[ -L /system_root ] && rm -f /system_root
mkdir /system_root 2>/dev/null
mount --move /system /system_root
mount -o bind /system_root/system /system
fi
[ ! -f /system/build.prop ] && error "failed to mount /system (unsupported A/B device?)"
2019-01-12 09:23:18 +00:00
if [ -L /system/vendor ]; then
! is_mounted /vendor && mount /vendor
if ! is_mounted /vendor; then
VENDORBLOCK=$(find /dev/block -iname vendor${SLOT} | head -n 1)
2019-04-03 20:19:30 +00:00
mount -o ro ${VENDORBLOCK} /vendor
2019-01-12 09:23:18 +00:00
fi
elif [ -d /system/vendor ]; then
### XXX work-around required for some ROMs
echo " xxx compat /vendor link created!"
ln -sf /system/vendor /vendor >/dev/null
fi
if [ ! -d /system/xbin ]; then
NANODROID_BINDIR=/system/bin
else NANODROID_BINDIR=/system/xbin
fi
}
2018-01-23 20:11:52 +00:00
# check for configuration files
config_locations="/data/media/0 /external_sd /sdcard1 /data $(dirname ${ZIP}))"
config_files=".nanodroid-setup .nanodroid-apps .nanodroid-overlay"
2018-01-23 20:11:52 +00:00
restore_apps () {
2019-05-05 10:25:07 +00:00
backup_path="${BACKUP_DIR}/$(grep_prop ro.build.flavor)_$(grep_prop ro.build.id)"
if [ -d ${backup_path}/app/ ]; then
for app in ${backup_path}/app/*; do
_app=$(basename ${app})
if [ -d /system/app/${_app} ]; then
ui_print " << removing backup: app:{_app}"
rm -rf "${app}"
else
ui_print " << restoring: app:${_app}"
mv "${app}" "/system/app/${_app}"
set_perm_data -r "/system/app/${_app}"
fi
done
rmdir ${backup_path}/app
fi
if [ -d ${backup_path}/priv-app/ ]; then
for app in ${backup_path}/priv-app/*; do
_app=$(basename ${app})
if [ -d /system/priv-app/${_app} ]; then
ui_print " << removing backup: priv-app:{_app}"
rm -rf "${app}"
else
ui_print " << restoring: priv-app:${_app}"
mv "${app}" "/system/priv-app/${_app}"
set_perm_data -r "/system/priv-app/${_app}"
fi
done
rmdir ${backup_path}/priv-app
fi
}
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
if test -h /system/fonts/Roboto-Regular.ttf; then
CUSTOM_FONT="$(basename $(readlink /system/fonts/Roboto-Regular.ttf) .ttf)"
ui_print " << Detected NanoDroid-Font (${CUSTOM_FONT})"
ui_print " < Restoring original Font"
${NANODROID_BINDIR}/nanodroid-font -r
fi
restore_apps
xargs rm < ${system_list} || error "failed to remove files"
2018-01-23 20:11:52 +00:00
# remove empty directories
# (find -empty not available on Android)
for dir in app priv-app; do
find /system/${dir} -type d | xargs rmdir -p
2018-01-23 20:11:52 +00:00
done
rm -f "${system_list}"
}
2018-01-23 20:11:52 +00:00
2018-09-08 08:39:07 +00:00
patcher_uninstall () {
if [ -f /data/adb/NanoDroid_Patched ]; then
services_name="services.jar_$(grep_prop ro.build.flavor)_$(grep_prop ro.build.id)"
2019-05-05 10:25:07 +00:00
if [ -f ${BACKUP_DIR}/${services_name} ]; then
2018-09-08 08:39:07 +00:00
ui_print " << restoring: unpatched services.jar"
2019-05-05 10:25:07 +00:00
mv "${BACKUP_DIR}/${services_name}" /system/framework/services.jar
set_perm_data /system/framework/services.jar
2018-09-08 08:39:07 +00:00
else ui_print " << can't restore unpatched services.jar"
fi
fi
[ -d /data/adb/nanodroid_patcher ] && rm -rf /data/adb/nanodroid_patcher
[ -f /system/addon.d/70-nanodroidpatcher.sh ] && rm -f ${addonsh}
[ -f /data/adb/NanoDroid_Patched ] && rm -f ${pfile}
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
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
# old format
rm -f /data/adb/NanoDroid_log*
rm -f /data/adb/NanoDroid_twrp*
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
2018-09-08 08:39:07 +00:00
patcher_uninstall
2018-01-23 20:11:52 +00:00
2019-06-10 17:42:38 +00:00
for module in NanoDroid NanoDroid_microG NanoDroid_FDroid \
NanoDroid_BromiteWebView NanoDroid_OsmAnd; do
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"
umount /system
ui_print " "
ui_print " > Done!"
ui_print " "
ui_print "Thanks for giving NanoDroid a try"
ui_print " "
exit 0