mirror of https://gitlab.com/Nanolx/NanoDroid
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
342 lines
7.8 KiB
Bash
342 lines
7.8 KiB
Bash
#!/sbin/sh
|
|
|
|
OUTFD=$2
|
|
ZIP=$3
|
|
|
|
GOOGLE_APPS="AMAPNetworkLocation
|
|
BaiduNetworkLocation
|
|
BlankStore
|
|
com.qualcomm.location
|
|
DejaVuBackend
|
|
DejaVuNlpBackend
|
|
FDroidPriv
|
|
GmsCoreSetupPrebuilt
|
|
GmsCore_update
|
|
GmsDroidGuard
|
|
GoogleFeedback
|
|
GoogleLoginService
|
|
GoogleOneTimeInitializer
|
|
GoogleServicesFramework
|
|
GoogleTTS
|
|
IchnaeaNlpBackend
|
|
LegacyNetworkLocation
|
|
MarketUpdater
|
|
MarkupGoogle
|
|
MozillaNlpBackend
|
|
NetworkLocation
|
|
NominatimGeocoderBackend
|
|
NominatimNlpBackend
|
|
PlayGames
|
|
PlayStore
|
|
PrebuiltGmsCore
|
|
UnifiedNlp
|
|
Velvet
|
|
Vending
|
|
WhisperPush
|
|
YouTube"
|
|
|
|
detect_bootmode () {
|
|
ps | grep zygote | grep -qv grep && BOOTMODE=true || BOOTMODE=false
|
|
${BOOTMODE} || ps -A | grep zygote | grep -qv grep && BOOTMODE=true
|
|
}
|
|
|
|
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}"
|
|
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
|
|
}
|
|
|
|
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 $?
|
|
}
|
|
|
|
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 -o "${ZIP}" busybox.arm -d "/dev/tmp"
|
|
BUSY=/dev/tmp/busybox.arm
|
|
;;
|
|
|
|
x86 | x86_64 )
|
|
unzip -o "${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 " !!"
|
|
exit 1
|
|
}
|
|
|
|
request_size_check() {
|
|
reqSizeM=`unzip -l "$1" 2>/dev/null | tail -n 1 | awk '{ print $1 }'`
|
|
reqSizeM=$((reqSizeM / 1048576 + 1))
|
|
}
|
|
|
|
image_size_check() {
|
|
e2fsck -yf $1
|
|
curBlocks=`e2fsck -n $1 2>/dev/null | grep $1 | cut -d, -f3 | cut -d\ -f2`;
|
|
curUsedM=`echo "$curBlocks" | cut -d/ -f1`
|
|
curSizeM=`echo "$curBlocks" | cut -d/ -f1`
|
|
curFreeM=$(((curSizeM - curUsedM) * 4 / 1024))
|
|
curUsedM=$((curUsedM * 4 / 1024 + 1))
|
|
curSizeM=$((curSizeM * 4 / 1024))
|
|
}
|
|
|
|
shrink_magisk_img () {
|
|
image_size_check /data/magisk.img
|
|
NEWDATASIZE=$((curUsedM / 32 * 32 + 32))
|
|
if [ "$curSizeM" -gt "$NEWDATASIZE" ]; then
|
|
resize2fs $IMG ${NEWDATASIZE}M
|
|
fi
|
|
}
|
|
|
|
mount_image() {
|
|
if [ ! -d "$2" ]; then
|
|
mount -o rw,remount rootfs /
|
|
mkdir -p "$2" 2>/dev/null
|
|
[ ! -d "$2" ] && return 1
|
|
fi
|
|
|
|
if ! is_mounted "$2"; then
|
|
LOOPDEVICE=
|
|
for LOOP in 0 1 2 3 4 5 6 7; do
|
|
if ! is_mounted "$2"; then
|
|
LOOPDEVICE=/dev/block/loop$LOOP
|
|
[ -e $LOOPDEVICE ] || mknod $LOOPDEVICE b 7 $LOOP 2>/dev/null
|
|
losetup $LOOPDEVICE "$1" && mount -t ext4 -o loop $LOOPDEVICE "$2"
|
|
if is_mounted "$2"; then
|
|
break;
|
|
fi
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
# taken from Magisk, with minor modifications for NanoDroid
|
|
mount_partitions () {
|
|
SLOT=$(grep_cmdline androidboot.slot_suffix)
|
|
if [ -z ${SLOT} ]; then
|
|
SLOT=_$(grep_cmdline androidboot.slot)
|
|
[ "${SLOT}" = "_" ] && SLOT=
|
|
fi
|
|
|
|
is_mounted /data || mount /data || error "failed to mount /data!"
|
|
|
|
! is_mounted /system && mount -o rw /system
|
|
|
|
if [ ! -f /system/build.prop ]; then
|
|
SYSTEMBLOCK=$(find /dev/block -iname system${SLOT} | head -n 1)
|
|
mount -t ext4 -o rw ${SYSTEMBLOCK} /system
|
|
fi
|
|
|
|
[ -f /system/build.prop ] || is_mounted /system || error "failed to mount /system (unsupported A/B device?)"
|
|
|
|
if [ -f /system/init ]; then
|
|
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?)"
|
|
|
|
if [ ! -d /system/xbin ]; then
|
|
NANODROID_BINDIR=/system/bin
|
|
else NANODROID_BINDIR=/system/xbin
|
|
fi
|
|
}
|
|
|
|
# check for configuration files
|
|
config_locations="/sdcard /external_sd /data $(dirname ${ZIP}))"
|
|
config_files=".nanodroid-setup .nanodroid-apps .nanodroid-overlay"
|
|
|
|
restore_gapps () {
|
|
for app in ${GOOGLE_APPS}; do
|
|
if [ -d /sdcard/nanodroid_backups/priv-app/${app} ]; then
|
|
appdir=priv-app
|
|
elif [ -d /sdcard/nanodroid_backups/app/${app} ]; then
|
|
appdir=app
|
|
else
|
|
continue
|
|
fi
|
|
|
|
if [ -d /system/${appdir}/${app} ]; then
|
|
ui_print " << removing backup: ${appdir} / ${app}"
|
|
rm -rf /sdcard/nanodroid_backups/${appdir}/${app}
|
|
else
|
|
ui_print " << restoring: ${appdir} / ${app}"
|
|
mv /sdcard/nanodroid_backups/${appdir}/${app} \
|
|
/system/${appdir}/ || error " failed to restore ${app}"
|
|
fi
|
|
done
|
|
}
|
|
|
|
system_mode_uninstall () {
|
|
ui_print " << uninstalling: NanoDroid (System)"
|
|
ui_print " << using: ${1}"
|
|
system_list=${1}
|
|
|
|
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_gapps
|
|
xargs rm -f < ${system_list} || error "failed to remove files"
|
|
|
|
# remove empty directories
|
|
# (find -empty not available on Android)
|
|
for dir in app priv-app share; do
|
|
find /system/${dir} -type d | \
|
|
xargs rmdir --ignore-fail-on-non-empty
|
|
done
|
|
|
|
rm -f "${system_list}"
|
|
}
|
|
|
|
patcher_uninstall () {
|
|
if [ -f /data/adb/.nanodroid-patcher -o -f /data/adb/NanoDroid_patched ]; then
|
|
if [ -f /sdcard/nanodroid_backups/services.jar ]; then
|
|
ui_print " << restoring: unpatched services.jar"
|
|
mv /sdcard/nanodroid_backups/services.jar /system/framework/services.jar \
|
|
|| error " failed to restore services.jar"
|
|
else ui_print " << can't restore unpatched services.jar"
|
|
fi
|
|
fi
|
|
|
|
[ -d /data/adb/nanodroid_patcher] && rm -rf ${addond}
|
|
|
|
for addonsh in /system/addon.d/999-nanodroidpatcher.sh \
|
|
/system/addon.d/70-nanodroidpatcher.sh \
|
|
/system/addon.d/91-nanodroid.sh; do
|
|
[ -f ${addonsh} ] && rm -f ${addonsh}
|
|
done
|
|
|
|
for pfile in /data/adb/.nanodroid-patcher /data/adb/NanoDroid_Patched; do
|
|
[ -f ${pfile} ] && rm -f ${pfile}
|
|
done
|
|
}
|
|
|
|
ui_print " "
|
|
ui_print "*****************************"
|
|
ui_print " NanoDroid 19.0.20181027 "
|
|
ui_print " created by Nanolx "
|
|
ui_print " Uninstaller "
|
|
ui_print "*****************************"
|
|
ui_print " "
|
|
|
|
detect_bootmode
|
|
${BOOTMODE} && error "NanoDroid Uninstaller needs to be run from TWRP"
|
|
|
|
mount_partitions
|
|
|
|
ui_print " << Removing configuration files (if any)"
|
|
|
|
for path in ${config_locations}; do
|
|
for file in ${config_files}; do
|
|
if [ -f "${path}/${file}" ]; then
|
|
rm -f "${path}/${file}"
|
|
ui_print " <<> removing ${path}/${file}"
|
|
fi
|
|
done
|
|
done
|
|
|
|
ui_print " << Removing installation logs (if any)"
|
|
|
|
# old format
|
|
rm -f /data/adb/.nanodroid_*
|
|
rm -f /data/adb/.recovery_*
|
|
|
|
# new format
|
|
rm -f /data/adb/NanoDroid_log*
|
|
rm -f /data/adb/NanoDroid_twrp*
|
|
|
|
# System Mode uninstallation
|
|
for install_info in /data/adb/.nanodroid-list /data/adb/NanoDroid_FileList; do
|
|
[ -f ${install_info} ] && system_mode_uninstall ${install_info}
|
|
done
|
|
|
|
patcher_uninstall
|
|
|
|
if [ -f /data/adb/magisk.img ]; then
|
|
mkdir -p /magisk
|
|
mount_image /data/adb/magisk.img /magisk || \
|
|
error " failed to mount /magisk"
|
|
fi
|
|
|
|
if (is_mounted /magisk); then
|
|
for module in NanoDroid NanoDroid_microG NanoDroid_FDroid; do
|
|
if [ -d /magisk/${module} ]; then
|
|
ui_print " << uninstalling: ${module}"
|
|
rm -rf /magisk/${module}
|
|
fi
|
|
done
|
|
fi
|
|
|
|
ui_print " >> clean up"
|
|
|
|
if (is_mounted /magisk); then
|
|
umount /magisk
|
|
losetup -d $LOOPDEVICE
|
|
rmdir /magisk
|
|
shrink_magisk_img || \
|
|
error " failed to shrink magisk.img"
|
|
fi
|
|
|
|
umount /system
|
|
|
|
ui_print " "
|
|
ui_print " > Done!"
|
|
ui_print " "
|
|
ui_print "Thanks for giving NanoDroid a try"
|
|
ui_print " "
|
|
|
|
exit 0
|