Add busybox to uninstaller and bug fixes

This commit is contained in:
topjohnwu 2017-02-14 07:03:24 +08:00
parent 3e2e171407
commit c6e9270590
3 changed files with 44 additions and 25 deletions

View File

@ -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,24 +330,22 @@ 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
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 /cache/data_bin
cp -af $INSTALLER/common/magisk.apk /cache/magisk.apk
chmod -R 755 /cache/data_bin
fi
$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
@ -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=

View File

@ -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

View File

@ -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