Adjust scripts
This commit is contained in:
parent
a1a2c52409
commit
9b4ae8fcc5
@ -29,24 +29,6 @@
|
|||||||
# Functions
|
# Functions
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
# Call ui_print_wrap if exists, or else simply use echo
|
|
||||||
# Useful when wrapped in flashable zip
|
|
||||||
ui_print_wrap() {
|
|
||||||
type ui_print >/dev/null 2>&1 && ui_print "$1" || echo "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Call abort if exists, or else show error message and exit
|
|
||||||
# Essential when wrapped in flashable zip
|
|
||||||
abort_wrap() {
|
|
||||||
type abort >/dev/null 2>&1
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
ui_print_wrap "$1"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
abort "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pure bash dirname implementation
|
# Pure bash dirname implementation
|
||||||
dirname_wrap() {
|
dirname_wrap() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -65,16 +47,6 @@ basename_wrap() {
|
|||||||
echo ${1##*/}
|
echo ${1##*/}
|
||||||
}
|
}
|
||||||
|
|
||||||
grep_prop() {
|
|
||||||
REGEX="s/^$1=//p"
|
|
||||||
shift
|
|
||||||
FILES=$@
|
|
||||||
if [ -z "$FILES" ]; then
|
|
||||||
FILES='/system/build.prop'
|
|
||||||
fi
|
|
||||||
cat $FILES 2>/dev/null | sed -n "$REGEX" | head -n 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# --cpio-add <incpio> <mode> <entry> <infile>
|
# --cpio-add <incpio> <mode> <entry> <infile>
|
||||||
cpio_add() {
|
cpio_add() {
|
||||||
./magiskboot --cpio-add ramdisk.cpio $1 $2 $3
|
./magiskboot --cpio-add ramdisk.cpio $1 $2 $3
|
||||||
@ -94,14 +66,9 @@ cpio_mkdir() {
|
|||||||
# Initialization
|
# Initialization
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
[ -z $1 ] && abort_wrap "This script requires a boot image as a parameter"
|
BOOTIMAGE="$1"
|
||||||
|
|
||||||
cwd=`pwd`
|
[ -e "$BOOTIMAGE" ] || (echo "$BOOTIMAGE does not exist!" && exit 1)
|
||||||
cd "`dirname_wrap $1`"
|
|
||||||
BOOTIMAGE="`pwd`/`basename_wrap $1`"
|
|
||||||
cd $cwd
|
|
||||||
|
|
||||||
[ -e "$BOOTIMAGE" ] || abort_wrap "$BOOTIMAGE does not exist!"
|
|
||||||
|
|
||||||
# Presets
|
# Presets
|
||||||
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
||||||
@ -129,23 +96,23 @@ migrate_boot_backup
|
|||||||
|
|
||||||
CHROMEOS=false
|
CHROMEOS=false
|
||||||
|
|
||||||
ui_print_wrap "- Unpacking boot image"
|
ui_print "- Unpacking boot image"
|
||||||
./magiskboot --unpack "$BOOTIMAGE"
|
./magiskboot --unpack "$BOOTIMAGE"
|
||||||
|
|
||||||
case $? in
|
case $? in
|
||||||
1 )
|
1 )
|
||||||
abort_wrap "! Unable to unpack boot image"
|
abort "! Unable to unpack boot image"
|
||||||
;;
|
;;
|
||||||
2 )
|
2 )
|
||||||
CHROMEOS=true
|
CHROMEOS=true
|
||||||
;;
|
;;
|
||||||
3 )
|
3 )
|
||||||
ui_print_wrap "! Sony ELF32 format detected"
|
ui_print "! Sony ELF32 format detected"
|
||||||
abort_wrap "! Please use BootBridge from @AdrianDC to flash Magisk"
|
abort "! Please use BootBridge from @AdrianDC to flash Magisk"
|
||||||
;;
|
;;
|
||||||
4 )
|
4 )
|
||||||
ui_print_wrap "! Sony ELF64 format detected"
|
ui_print "! Sony ELF64 format detected"
|
||||||
abort_wrap "! Stock kernel cannot be patched, please use a custom kernel"
|
abort "! Stock kernel cannot be patched, please use a custom kernel"
|
||||||
esac
|
esac
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
@ -153,12 +120,12 @@ esac
|
|||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
|
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
|
||||||
ui_print_wrap "- Checking ramdisk status"
|
ui_print "- Checking ramdisk status"
|
||||||
./magiskboot --cpio-test ramdisk.cpio
|
./magiskboot --cpio-test ramdisk.cpio
|
||||||
case $? in
|
case $? in
|
||||||
0 ) # Stock boot
|
0 ) # Stock boot
|
||||||
ui_print_wrap "- Stock boot image detected!"
|
ui_print "- Stock boot image detected!"
|
||||||
ui_print_wrap "- Backing up stock boot image"
|
ui_print "- Backing up stock boot image"
|
||||||
SHA1=`./magiskboot --sha1 "$BOOTIMAGE" 2>/dev/null`
|
SHA1=`./magiskboot --sha1 "$BOOTIMAGE" 2>/dev/null`
|
||||||
STOCKDUMP=stock_boot_${SHA1}.img
|
STOCKDUMP=stock_boot_${SHA1}.img
|
||||||
dd if="$BOOTIMAGE" of=$STOCKDUMP
|
dd if="$BOOTIMAGE" of=$STOCKDUMP
|
||||||
@ -166,22 +133,22 @@ case $? in
|
|||||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||||
;;
|
;;
|
||||||
1 ) # Magisk patched
|
1 ) # Magisk patched
|
||||||
ui_print_wrap "- Magisk patched image detected!"
|
ui_print "- Magisk patched image detected!"
|
||||||
# Find SHA1 of stock boot image
|
# Find SHA1 of stock boot image
|
||||||
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio-stocksha1 ramdisk.cpio 2>/dev/null`
|
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio-stocksha1 ramdisk.cpio 2>/dev/null`
|
||||||
OK=false
|
OK=false
|
||||||
./magiskboot --cpio-restore ramdisk.cpio
|
./magiskboot --cpio-restore ramdisk.cpio
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
ui_print_wrap "- Ramdisk restored from internal backup"
|
ui_print "- Ramdisk restored from internal backup"
|
||||||
OK=true
|
OK=true
|
||||||
else
|
else
|
||||||
# Restore failed
|
# Restore failed
|
||||||
ui_print_wrap "! Cannot restore from internal backup"
|
ui_print "! Cannot restore from internal backup"
|
||||||
# If we are root and SHA1 known, we try to find the stock backup
|
# If we are root and SHA1 known, we try to find the stock backup
|
||||||
if $ROOT && [ ! -z $SHA1 ]; then
|
if $ROOT && [ ! -z $SHA1 ]; then
|
||||||
STOCKDUMP=/data/stock_boot_${SHA1}.img
|
STOCKDUMP=/data/stock_boot_${SHA1}.img
|
||||||
if [ -f ${STOCKDUMP}.gz ]; then
|
if [ -f ${STOCKDUMP}.gz ]; then
|
||||||
ui_print_wrap "- Stock boot image backup found"
|
ui_print "- Stock boot image backup found"
|
||||||
./magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
|
./magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
|
||||||
./magiskboot --unpack stock_boot.img
|
./magiskboot --unpack stock_boot.img
|
||||||
rm -f stock_boot.img
|
rm -f stock_boot.img
|
||||||
@ -190,14 +157,14 @@ case $? in
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if ! $OK; then
|
if ! $OK; then
|
||||||
ui_print_wrap "! Ramdisk restoration incomplete"
|
ui_print "! Ramdisk restoration incomplete"
|
||||||
ui_print_wrap "! Will still try to continue installation"
|
ui_print "! Will still try to continue installation"
|
||||||
fi
|
fi
|
||||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||||
;;
|
;;
|
||||||
2 ) # Other patched
|
2 ) # Other patched
|
||||||
ui_print_wrap "! Boot image patched by other programs!"
|
ui_print "! Boot image patched by other programs!"
|
||||||
abort_wrap "! Please restore stock boot image"
|
abort "! Please restore stock boot image"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -205,7 +172,7 @@ esac
|
|||||||
# Ramdisk patches
|
# Ramdisk patches
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
ui_print_wrap "- Patching ramdisk"
|
ui_print "- Patching ramdisk"
|
||||||
|
|
||||||
if [ ! -z $SHA1 ]; then
|
if [ ! -z $SHA1 ]; then
|
||||||
cp init.magisk.rc init.magisk.rc.bak
|
cp init.magisk.rc init.magisk.rc.bak
|
||||||
@ -257,8 +224,8 @@ A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
|
|||||||
736B69705F696E697472616D6673 \
|
736B69705F696E697472616D6673 \
|
||||||
77616E745F696E697472616D6673
|
77616E745F696E697472616D6673
|
||||||
|
|
||||||
ui_print_wrap "- Repacking boot image"
|
ui_print "- Repacking boot image"
|
||||||
./magiskboot --repack "$BOOTIMAGE" || abort_wrap "! Unable to repack boot image!"
|
./magiskboot --repack "$BOOTIMAGE" || abort "! Unable to repack boot image!"
|
||||||
|
|
||||||
# Sign chromeos boot
|
# Sign chromeos boot
|
||||||
$CHROMEOS && sign_chromeos
|
$CHROMEOS && sign_chromeos
|
||||||
|
@ -31,7 +31,7 @@ umask 022
|
|||||||
OUTFD=$2
|
OUTFD=$2
|
||||||
ZIP=$3
|
ZIP=$3
|
||||||
|
|
||||||
if [ ! -d "$COMMONDIR" ]; then
|
if [ ! -f $COMMONDIR/util_functions.sh ]; then
|
||||||
echo "! Unable to extract zip file!"
|
echo "! Unable to extract zip file!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -31,8 +31,16 @@ if [ ! -f $MAGISKBIN/magiskboot -o ! -f $MAGISKBIN/util_functions.sh ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load utility functions
|
if $BOOTMODE; then
|
||||||
. $MAGISKBIN/util_functions.sh
|
# Load utility functions
|
||||||
|
. $MAGISKBIN/util_functions.sh
|
||||||
|
boot_actions
|
||||||
|
mount_partitions
|
||||||
|
else
|
||||||
|
recovery_actions
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $MAGISKBIN
|
||||||
|
|
||||||
# Find the boot image
|
# Find the boot image
|
||||||
find_boot_image
|
find_boot_image
|
||||||
@ -40,7 +48,7 @@ find_boot_image
|
|||||||
|
|
||||||
ui_print "- Found Boot Image: $BOOTIMAGE"
|
ui_print "- Found Boot Image: $BOOTIMAGE"
|
||||||
|
|
||||||
cd $MAGISKBIN
|
migrate_boot_backup
|
||||||
|
|
||||||
ui_print "- Unpacking boot image"
|
ui_print "- Unpacking boot image"
|
||||||
./magiskboot --unpack "$BOOTIMAGE"
|
./magiskboot --unpack "$BOOTIMAGE"
|
||||||
@ -61,9 +69,8 @@ case $? in
|
|||||||
abort "! Stock kernel cannot be patched, please use a custom kernel"
|
abort "! Stock kernel cannot be patched, please use a custom kernel"
|
||||||
esac
|
esac
|
||||||
|
|
||||||
migrate_boot_backup
|
|
||||||
|
|
||||||
# Detect boot image state
|
# Detect boot image state
|
||||||
|
ui_print "- Checking ramdisk status"
|
||||||
./magiskboot --cpio-test ramdisk.cpio
|
./magiskboot --cpio-test ramdisk.cpio
|
||||||
case $? in
|
case $? in
|
||||||
0 ) # Stock boot
|
0 ) # Stock boot
|
||||||
@ -109,6 +116,6 @@ rm -rf /cache/magisk.log /cache/last_magisk.log /cache/magiskhide.log /cache/.d
|
|||||||
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh \
|
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh \
|
||||||
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img /data/magisk_debug.log \
|
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img /data/magisk_debug.log \
|
||||||
/data/busybox /data/magisk /data/custom_ramdisk_patch.sh /data/property/*magisk* \
|
/data/busybox /data/magisk /data/custom_ramdisk_patch.sh /data/property/*magisk* \
|
||||||
/data/app/com.topjohnwu.magisk* /data/user/*/com.topjohnwu.magisk 2>/dev/null
|
/data/app/com.topjohnwu.magisk* /data/user*/*/com.topjohnwu.magisk 2>/dev/null
|
||||||
|
|
||||||
$BOOTMODE && reboot
|
$BOOTMODE && reboot || recovery_cleanup
|
||||||
|
@ -24,7 +24,7 @@ OUTFD=$2
|
|||||||
ZIP=$3
|
ZIP=$3
|
||||||
|
|
||||||
if [ ! -f $INSTALLER/util_functions.sh ]; then
|
if [ ! -f $INSTALLER/util_functions.sh ]; then
|
||||||
echo "! Failed: Unable to extract zip file!"
|
echo "! Unable to extract zip file!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -40,13 +40,8 @@ ui_print "************************"
|
|||||||
ui_print " Magisk Uninstaller "
|
ui_print " Magisk Uninstaller "
|
||||||
ui_print "************************"
|
ui_print "************************"
|
||||||
|
|
||||||
ui_print "- Mounting /system, /vendor, /cache, /data"
|
is_mounted /data || mount /data
|
||||||
mount -o ro /system 2>/dev/null
|
mount_partitions
|
||||||
mount -o ro /vendor 2>/dev/null
|
|
||||||
mount /cache 2>/dev/null
|
|
||||||
mount /data 2>/dev/null
|
|
||||||
|
|
||||||
[ -f /system/build.prop ] || abort "! /system could not be mounted!"
|
|
||||||
|
|
||||||
api_level_arch_detect
|
api_level_arch_detect
|
||||||
|
|
||||||
@ -61,15 +56,15 @@ BINDIR=$INSTALLER/$ARCH
|
|||||||
MAGISKBIN=/data/magisk
|
MAGISKBIN=/data/magisk
|
||||||
|
|
||||||
if is_mounted /data; then
|
if is_mounted /data; then
|
||||||
|
# Save our stock boot image dump before removing it
|
||||||
|
[ -f $MAGISKBIN/stock_boot* ] && mv $MAGISKBIN/stock_boot* /data
|
||||||
# Copy the binaries to /data/magisk, in case they do not exist
|
# Copy the binaries to /data/magisk, in case they do not exist
|
||||||
rm -rf $MAGISKBIN 2>/dev/null
|
rm -rf $MAGISKBIN 2>/dev/null
|
||||||
mkdir -p $MAGISKBIN
|
mkdir -p $MAGISKBIN
|
||||||
cp -af $BINDIR/. $CHROMEDIR $TMPDIR/bin/busybox $INSTALLER/util_functions.sh $MAGISKBIN
|
cp -af $BINDIR/. $CHROMEDIR $TMPDIR/bin/busybox $INSTALLER/util_functions.sh $MAGISKBIN
|
||||||
chmod -R 755 $MAGISKBIN
|
chmod -R 755 $MAGISKBIN
|
||||||
# Run the acttual uninstallation
|
# Run the acttual uninstallation
|
||||||
recovery_actions
|
|
||||||
. $INSTALLER/magisk_uninstaller.sh
|
. $INSTALLER/magisk_uninstaller.sh
|
||||||
recovery_cleanup
|
|
||||||
else
|
else
|
||||||
ui_print "! Data unavailable"
|
ui_print "! Data unavailable"
|
||||||
ui_print "! Placing uninstall script to /cache"
|
ui_print "! Placing uninstall script to /cache"
|
||||||
|
@ -6,7 +6,7 @@ dirname_wrap() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
[ "$1" = "indep" ] && INDEP=true || INDEP=false
|
[ "$1" = "indep" ] && INDEP=true || INDEP=false
|
||||||
$INDEP && TMPDIR="`cd "\`dirname_wrap "${BASH_SOURCE:-$0}"\`" && pwd`" || TMPDIR=/dev/tmp
|
$INDEP && TMPDIR="`dirname_wrap "${BASH_SOURCE:-$0}"`" || TMPDIR=/dev/tmp
|
||||||
INSTALLER=$TMPDIR/install; BBDIR=$TMPDIR/bin
|
INSTALLER=$TMPDIR/install; BBDIR=$TMPDIR/bin
|
||||||
EXBIN=$BBDIR/b64xz; BBBIN=$BBDIR/busybox
|
EXBIN=$BBDIR/b64xz; BBBIN=$BBDIR/busybox
|
||||||
$INDEP || rm -rf $TMPDIR 2>/dev/null;
|
$INDEP || rm -rf $TMPDIR 2>/dev/null;
|
||||||
|
Loading…
Reference in New Issue
Block a user