From c6e927059076f3b85f1f8f8a5f7076310d40bac2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 14 Feb 2017 07:03:24 +0800 Subject: [PATCH] Add busybox to uninstaller and bug fixes --- scripts/flash_script.sh | 33 +++++++++---------- scripts/magisk_uninstaller.sh | 25 +++++++++++--- .../META-INF/com/google/android/update-binary | 11 ++++--- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/scripts/flash_script.sh b/scripts/flash_script.sh index 46e1cd7e2..d05b13e3f 100644 --- a/scripts/flash_script.sh +++ b/scripts/flash_script.sh @@ -175,7 +175,8 @@ repack_boot() { cd $UNPACKDIR LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --repack $BOOTIMAGE if [ -f chromeos ]; then - cp -af $CHROMEDIR /data/magisk + # Copy required tools + cp -af $CHROMEDIR/. $CPPATH/chromeos echo " " > config echo " " > bootloader LD_LIBRARY_PATH=$SYSTEMLIB $CHROMEDIR/futility vbutil_kernel --pack new-boot.img.signed --keyblock $CHROMEDIR/kernel.keyblock --signprivate $CHROMEDIR/kernel_data_key.vbprivk --version 1 --vmlinuz new-boot.img --config config --arch arm --bootloader bootloader --flags 0x1 @@ -329,25 +330,23 @@ fi ui_print "- Constructing environment" +CPPATH + if (is_mounted /data); then - rm -rf /data/magisk 2>/dev/null - mkdir -p /data/magisk - cp -af $BINDIR/busybox $BINDIR/sepolicy-inject $BINDIR/resetprop $BINDIR/bootimgtools \ - $INSTALLER/common/init.magisk.rc $INSTALLER/common/magic_mask.sh /data/magisk - cp -af $INSTALLER/common/magisk.apk /data/magisk.apk - chmod -R 755 /data/magisk - chcon -h u:object_r:system_file:s0 /data/magisk /data/magisk/* - PATH=/data/busybox:$PATH + CPPATH=/data/magisk else - rm -rf /cache/data_bin 2>/dev/null - mkdir -p /cache/data_bin - cp -af $BINDIR/busybox $BINDIR/sepolicy-inject $BINDIR/resetprop $BINDIR/bootimgtools \ - $INSTALLER/common/custom_ramdisk_patch.sh $INSTALLER/common/init.magisk.rc \ - $INSTALLER/common/magic_mask.sh /cache/data_bin - cp -af $INSTALLER/common/magisk.apk /cache/magisk.apk - chmod -R 755 /cache/data_bin + CPPATH=/cache/data_bin fi +# Copy required files +rm -rf $CPPATH 2>/dev/null +mkdir -p $CPPATH +cp -af $BINDIR/busybox $BINDIR/sepolicy-inject $BINDIR/resetprop $BINDIR/bootimgtools \ + $INSTALLER/common/custom_ramdisk_patch.sh $INSTALLER/common/init.magisk.rc \ + $INSTALLER/common/magic_mask.sh $CPPATH +chmod -R 755 $CPPATH +chcon -h u:object_r:system_file:s0 $CPPATH $CPPATH/* + # Temporary busybox for installation mkdir -p $TMPDIR/busybox $BINDIR/busybox --install -s $TMPDIR/busybox @@ -402,7 +401,7 @@ ui_print "- Unpacking boot image" unpack_boot $BOOTIMAGE if [ $? -ne 0 ]; then ui_print "! Unable to unpack boot image" - exit 1; + exit 1 fi ORIGBOOT= diff --git a/scripts/magisk_uninstaller.sh b/scripts/magisk_uninstaller.sh index fff5ddacd..6a95aa1ef 100644 --- a/scripts/magisk_uninstaller.sh +++ b/scripts/magisk_uninstaller.sh @@ -49,8 +49,10 @@ unpack_boot() { cd $UNPACKDIR LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --extract $1 + [ ! -f $UNPACKDIR/ramdisk.gz ] && return 1 + cd $RAMDISK - $BINDIR/busybox gunzip -c < $UNPACKDIR/ramdisk.gz | cpio -i + gunzip -c < $UNPACKDIR/ramdisk.gz | cpio -i } repack_boot() { @@ -79,8 +81,14 @@ repack_boot() { mv new-boot.img $NEWBOOT } +# Environments # Set permissions -chmod -R 755 $CHROMEDIR/futility $BINDIR +chmod -R 755 $CHROMEDIR/futility $BINDIR 2>/dev/null +# Temporary busybox for installation +mkdir -p $TMPDIR/busybox +$BINDIR/busybox --install -s $TMPDIR/busybox +rm -f $TMPDIR/busybox/su $TMPDIR/busybox/sh $TMPDIR/busybox/reboot +PATH=$TMPDIR/busybox:$PATH # Find the boot image find_boot_image @@ -121,13 +129,22 @@ fi # First unpack the boot image unpack_boot $BOOTIMAGE +if [ $? -ne 0 ]; then + ui_print "! Unable to unpack boot image" + exit 1 +fi +# Detect boot image state SUPERSU=false [ -f sbin/launch_daemonsu.sh ] && SUPERSU=true +if [ ! -f init.magisk.rc ]; then + ui_print "! Magisk is not installed!" + exit 1 +fi if ($SUPERSU); then ui_print "- SuperSU patched image detected" - rm -f magisk sbin/init.magisk.rc sbin/magic_mask.sh + rm -rf magisk init.magisk.rc sbin/magic_mask.sh repack_boot else if [ -f /data/stock_boot.img ]; then @@ -139,7 +156,7 @@ else ui_print "- Restoring ramdisk with backup" cp -af .backup/. . fi - rm -f magisk sbin/init.magisk.rc sbin/magic_mask.sh + rm -rf magisk init.magisk.rc sbin/magic_mask.sh .backup repack_boot fi fi diff --git a/uninstaller/META-INF/com/google/android/update-binary b/uninstaller/META-INF/com/google/android/update-binary index 72342cc0a..6302a0105 100644 --- a/uninstaller/META-INF/com/google/android/update-binary +++ b/uninstaller/META-INF/com/google/android/update-binary @@ -123,7 +123,7 @@ BINDIR=$INSTALLER/$ARCH # Copy the binaries to /data/magisk mkdir -p /data/magisk 2>/dev/null -cp -af $BINDIR/bootimgtools $CHROMEDIR /data/magisk +cp -af $BINDIR/* $CHROMEDIR /data/magisk ########################################################################################## # Detection all done, start installing @@ -134,18 +134,21 @@ ui_print "- Found Boot Image: $BOOTIMAGE" if (is_mounted /data); then ui_print "- Running uninstaller scripts" sh $INSTALLER/common/magisk_uninstaller.sh + if [ $? -ne 0 ]; then + ui_print "! Magisk is not installed or an error occurred" + exit 1 + fi else ui_print "! Data unavailable" ui_print "! Placing uninstall script to /cache" - ui_print "! The device will reboot multiple times" + ui_print "! The device might reboot multiple times" cp -af $INSTALLER/common/magisk_uninstaller.sh /cache/magisk_uninstaller.sh umount /system + ui_print "- Rebooting....." sleep 5 reboot fi -chmod 644 $NEWBOOT - umount /system ui_print "- Done" exit 0