mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
Update scripts
This commit is contained in:
parent
04538372c6
commit
2a86bc8695
@ -20,6 +20,7 @@ main() {
|
|||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
mount -o ro /system 2>/dev/null
|
mount -o ro /system 2>/dev/null
|
||||||
|
mount -o ro /vendor 2>/dev/null
|
||||||
mount /data 2>/dev/null
|
mount /data 2>/dev/null
|
||||||
|
|
||||||
if [ ! -d $MAGISKBIN ]; then
|
if [ ! -d $MAGISKBIN ]; then
|
||||||
@ -36,14 +37,7 @@ main() {
|
|||||||
ui_print "* MAGISK_VERSION_STUB"
|
ui_print "* MAGISK_VERSION_STUB"
|
||||||
ui_print "************************"
|
ui_print "************************"
|
||||||
|
|
||||||
# Check if system root is installed and remove
|
recovery_actions
|
||||||
remove_system_su
|
|
||||||
# Prefer bin in /system
|
|
||||||
export PATH=/system/bin:/system/xbin
|
|
||||||
# Clear out possible lib paths, let the binary find them itself
|
|
||||||
export LD_LIBRARY_PATH=
|
|
||||||
# Temporarily block out all custom recovery binaries/libs
|
|
||||||
mv /sbin /sbin_tmp
|
|
||||||
|
|
||||||
find_boot_image
|
find_boot_image
|
||||||
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
||||||
@ -53,7 +47,7 @@ main() {
|
|||||||
cd $MAGISKBIN
|
cd $MAGISKBIN
|
||||||
|
|
||||||
# Source the boot patcher
|
# Source the boot patcher
|
||||||
. $MAGISKBIN/boot_patch.sh $BOOTIMAGE
|
. $MAGISKBIN/boot_patch.sh "$BOOTIMAGE"
|
||||||
|
|
||||||
[ -f stock_boot* ] && rm -f /data/stock_boot* 2>/dev/null
|
[ -f stock_boot* ] && rm -f /data/stock_boot* 2>/dev/null
|
||||||
|
|
||||||
|
@ -23,24 +23,9 @@
|
|||||||
# image placed under /data we've created when previously installing
|
# image placed under /data we've created when previously installing
|
||||||
#
|
#
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
##########################################################################################
|
||||||
# Workaround for getting the full path of BOOTIMAGE
|
# Functions
|
||||||
CWD=`pwd`
|
##########################################################################################
|
||||||
cd `dirname $1`
|
|
||||||
BOOTIMAGE="`pwd`/`basename $1`"
|
|
||||||
cd "$CWD"
|
|
||||||
|
|
||||||
if [ -z "$BOOTIMAGE" ]; then
|
|
||||||
ui_print_wrap "This script requires a boot image as a parameter"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Presets
|
|
||||||
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
|
||||||
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
|
|
||||||
|
|
||||||
# Detect whether running as root
|
|
||||||
[ `id -u` -eq 0 ] && ROOT=true || ROOT=false
|
|
||||||
|
|
||||||
# Call ui_print_wrap if exists, or else simply use echo
|
# Call ui_print_wrap if exists, or else simply use echo
|
||||||
# Useful when wrapped in flashable zip
|
# Useful when wrapped in flashable zip
|
||||||
@ -60,6 +45,21 @@ abort_wrap() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Pure bash dirname implementation
|
||||||
|
dirname_wrap() {
|
||||||
|
if echo $1 | grep "/" >/dev/null 2>&1; then
|
||||||
|
RES=${1%/*}
|
||||||
|
[ -z $RES ] && echo "/" || echo $RES
|
||||||
|
else
|
||||||
|
echo "."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pure bash basename implementation
|
||||||
|
basename_wrap() {
|
||||||
|
echo ${1##*/}
|
||||||
|
}
|
||||||
|
|
||||||
grep_prop() {
|
grep_prop() {
|
||||||
REGEX="s/^$1=//p"
|
REGEX="s/^$1=//p"
|
||||||
shift
|
shift
|
||||||
@ -86,13 +86,34 @@ cpio_mkdir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Prework
|
# Initialization
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
|
CWD=`pwd`
|
||||||
|
cd "`dirname_wrap $1`"
|
||||||
|
BOOTIMAGE="`pwd`/`basename_wrap $1`"
|
||||||
|
cd "$CWD"
|
||||||
|
|
||||||
|
if [ -z "$BOOTIMAGE" ]; then
|
||||||
|
ui_print_wrap "This script requires a boot image as a parameter"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Presets
|
||||||
|
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
||||||
|
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
|
||||||
|
|
||||||
|
# Detect whether running as root
|
||||||
|
[ `id -u` -eq 0 ] && ROOT=true || ROOT=false
|
||||||
|
|
||||||
# Switch to the location of the script file
|
# Switch to the location of the script file
|
||||||
[ -z $SOURCEDMODE ] && cd "`dirname "${BASH_SOURCE:-$0}"`"
|
[ -z $SOURCEDMODE ] && cd "`dirname_wrap "${BASH_SOURCE:-$0}"`"
|
||||||
chmod +x ./*
|
chmod +x ./*
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# Unpack
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
ui_print_wrap "- Unpacking boot image"
|
ui_print_wrap "- Unpacking boot image"
|
||||||
./magiskboot --unpack "$BOOTIMAGE"
|
./magiskboot --unpack "$BOOTIMAGE"
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ $BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMO
|
|||||||
TMPDIR=/dev/tmp
|
TMPDIR=/dev/tmp
|
||||||
|
|
||||||
INSTALLER=$TMPDIR/magisk
|
INSTALLER=$TMPDIR/magisk
|
||||||
BUSYBOX=$TMPDIR/busybox
|
|
||||||
COMMONDIR=$INSTALLER/common
|
COMMONDIR=$INSTALLER/common
|
||||||
CHROMEDIR=$INSTALLER/chromeos
|
CHROMEDIR=$INSTALLER/chromeos
|
||||||
COREDIR=/magisk/.core
|
COREDIR=/magisk/.core
|
||||||
@ -49,13 +48,18 @@ if [ "$?" -eq "0" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf $TMPDIR 2>/dev/null
|
rm -rf $TMPDIR 2>/dev/null
|
||||||
mkdir -p $INSTALLER $BUSYBOX
|
mkdir -p $INSTALLER
|
||||||
unzip -o "$ZIP" -d $INSTALLER
|
unzip -o "$ZIP" -d $INSTALLER
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Detection
|
# Detection
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
|
if [ ! -d "$COMMONDIR" ]; then
|
||||||
|
echo "! Unable to extract zip file!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Load all fuctions
|
# Load all fuctions
|
||||||
. $COMMONDIR/util_functions.sh
|
. $COMMONDIR/util_functions.sh
|
||||||
|
|
||||||
@ -63,10 +67,9 @@ ui_print "************************"
|
|||||||
ui_print "* MAGISK_VERSION_STUB"
|
ui_print "* MAGISK_VERSION_STUB"
|
||||||
ui_print "************************"
|
ui_print "************************"
|
||||||
|
|
||||||
[ -d "$COMMONDIR" ] || abort "! Unable to extract zip file!"
|
ui_print "- Mounting /system(ro), /vendor(ro), /cache, /data"
|
||||||
|
|
||||||
ui_print "- Mounting /system(ro), /cache, /data"
|
|
||||||
mount -o ro /system 2>/dev/null
|
mount -o ro /system 2>/dev/null
|
||||||
|
mount -o ro /vendor 2>/dev/null
|
||||||
mount /cache 2>/dev/null
|
mount /cache 2>/dev/null
|
||||||
mount /data 2>/dev/null
|
mount /data 2>/dev/null
|
||||||
|
|
||||||
@ -87,10 +90,10 @@ ABILONG=`grep_prop ro.product.cpu.abi`
|
|||||||
|
|
||||||
ARCH=arm
|
ARCH=arm
|
||||||
BBPATH=armeabi-v7a
|
BBPATH=armeabi-v7a
|
||||||
if [ "$ABI" = "x86" ]; then ARCH=x86; BBPATH=x86; fi;
|
if [ "$ABI" = "x86" ]; then ARCH=x86; fi;
|
||||||
if [ "$ABI2" = "x86" ]; then ARCH=x86; BBPATH=x86; fi;
|
if [ "$ABI2" = "x86" ]; then ARCH=x86; fi;
|
||||||
if [ "$ABILONG" = "arm64-v8a" ]; then ARCH=arm64; fi;
|
if [ "$ABILONG" = "arm64-v8a" ]; then ARCH=arm64; fi;
|
||||||
if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; BBPATH=x86; fi;
|
if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; fi;
|
||||||
|
|
||||||
[ $API -lt 21 ] && abort "! Magisk is only for Lollipop 5.0+ (SDK 21+)"
|
[ $API -lt 21 ] && abort "! Magisk is only for Lollipop 5.0+ (SDK 21+)"
|
||||||
|
|
||||||
@ -108,21 +111,7 @@ find_boot_image
|
|||||||
|
|
||||||
ui_print "- Constructing environment"
|
ui_print "- Constructing environment"
|
||||||
|
|
||||||
if ! $BOOTMODE; then
|
$BOOTMODE || recovery_actions
|
||||||
# We are in custom recovery, don't trust anything in recovery, use those in /system
|
|
||||||
# Extract busybox from Magisk Manager, it's pure static binary so there will be no issues
|
|
||||||
unzip -o $COMMONDIR/magisk.apk lib/$BBPATH/libbusybox.so -d $BUSYBOX
|
|
||||||
mv $BUSYBOX/lib/*/libbusybox.so $BUSYBOX/busybox
|
|
||||||
rm -rf $BUSYBOX/lib
|
|
||||||
chmod +x $BUSYBOX/busybox
|
|
||||||
$BUSYBOX/busybox --install -s $BUSYBOX
|
|
||||||
# Prefer bin in /system, fallback to bundled busybox if a tool doesn't exist
|
|
||||||
export PATH=/system/bin:/system/xbin:$BUSYBOX
|
|
||||||
# Clear out possible lib paths, let the binary find them itself
|
|
||||||
export LD_LIBRARY_PATH=
|
|
||||||
# Temporarily block out all custom recovery binaries/libs
|
|
||||||
mv /sbin /sbin_tmp
|
|
||||||
fi
|
|
||||||
|
|
||||||
is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
|
is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
|
||||||
|
|
||||||
@ -147,7 +136,7 @@ fi
|
|||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
# Fix SuperSU.....
|
# Fix SuperSU.....
|
||||||
$BOOTMODE && $BINDIR/magiskpolicy --live "allow fsck * * *"
|
$BOOTMODE && $BINDIR/magisk magiskpolicy --live "allow fsck * * *"
|
||||||
|
|
||||||
if (is_mounted /data); then
|
if (is_mounted /data); then
|
||||||
IMG=/data/magisk.img
|
IMG=/data/magisk.img
|
||||||
@ -163,9 +152,11 @@ else
|
|||||||
$BINDIR/magisk --createimg $IMG 64M
|
$BINDIR/magisk --createimg $IMG 64M
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount_image $IMG /magisk
|
if ! is_mounted /magisk; then
|
||||||
|
ui_print "- Mounting $IMG to /magisk"
|
||||||
|
MAGISKLOOP=`$BINDIR/magisk --mountimg $IMG /magisk`
|
||||||
|
fi
|
||||||
is_mounted /magisk || abort "! Magisk image mount failed..."
|
is_mounted /magisk || abort "! Magisk image mount failed..."
|
||||||
MAGISKLOOP=$LOOPDEVICE
|
|
||||||
|
|
||||||
# Core folders
|
# Core folders
|
||||||
mkdir -p $COREDIR/props $COREDIR/post-fs-data.d $COREDIR/service.d 2>/dev/null
|
mkdir -p $COREDIR/props $COREDIR/post-fs-data.d $COREDIR/service.d 2>/dev/null
|
||||||
@ -222,12 +213,12 @@ rm -f new-boot.img
|
|||||||
cd /
|
cd /
|
||||||
|
|
||||||
if ! $BOOTMODE; then
|
if ! $BOOTMODE; then
|
||||||
mv /sbin_tmp /sbin
|
|
||||||
ui_print "- Unmounting partitions"
|
ui_print "- Unmounting partitions"
|
||||||
umount /magisk
|
$BINDIR/magisk --umountimg /magisk $MAGISKLOOP
|
||||||
losetup -d $MAGISKLOOP 2>/dev/null
|
|
||||||
rmdir /magisk
|
rmdir /magisk
|
||||||
|
mv /sbin_tmp /sbin
|
||||||
umount -l /system
|
umount -l /system
|
||||||
|
umount -l /vendor 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ui_print "- Done"
|
ui_print "- Done"
|
||||||
|
@ -56,29 +56,6 @@ is_mounted() {
|
|||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
mount_image() {
|
|
||||||
if [ ! -d "$2" ]; then
|
|
||||||
mount -o rw,remount rootfs /
|
|
||||||
mkdir -p "$2" 2>/dev/null
|
|
||||||
$BOOTMODE && mount -o ro,remount rootfs /
|
|
||||||
[ ! -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
|
|
||||||
ui_print "- Mounting $1 to $2"
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
grep_prop() {
|
grep_prop() {
|
||||||
REGEX="s/^$1=//p"
|
REGEX="s/^$1=//p"
|
||||||
shift
|
shift
|
||||||
@ -114,6 +91,15 @@ remove_system_su() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recovery_actions() {
|
||||||
|
# TWRP bug fix
|
||||||
|
mount -o bind /dev/urandom /dev/random
|
||||||
|
# Clear out possible lib paths, let the binaries find them itself
|
||||||
|
export LD_LIBRARY_PATH=
|
||||||
|
# Temporarily block out all custom recovery binaries/libs
|
||||||
|
mv /sbin /sbin_tmp
|
||||||
|
}
|
||||||
|
|
||||||
abort() {
|
abort() {
|
||||||
ui_print "$1"
|
ui_print "$1"
|
||||||
mv /sbin_tmp /sbin 2>/dev/null
|
mv /sbin_tmp /sbin 2>/dev/null
|
||||||
|
Loading…
Reference in New Issue
Block a user