mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-25 02:55:33 +00:00
Reorganize scripts
This commit is contained in:
parent
65ebb0d2f8
commit
ab47b717b1
@ -7,7 +7,3 @@ get_flags() {
|
|||||||
$SYSTEM_ROOT && KEEPVERITY=true || KEEPVERITY=false
|
$SYSTEM_ROOT && KEEPVERITY=true || KEEPVERITY=false
|
||||||
[ "`getprop ro.crypto.state`" = "encrypted" ] && KEEPFORCEENCRYPT=true || KEEPFORCEENCRYPT=false
|
[ "`getprop ro.crypto.state`" = "encrypted" ] && KEEPFORCEENCRYPT=true || KEEPFORCEENCRYPT=false
|
||||||
}
|
}
|
||||||
|
|
||||||
run_migrations() {
|
|
||||||
# NOP
|
|
||||||
}
|
|
||||||
|
@ -17,6 +17,19 @@ fix_env() {
|
|||||||
cd /
|
cd /
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_migrations() {
|
||||||
|
# Move the stock backups
|
||||||
|
if [ -f /data/magisk/stock_boot* ]; then
|
||||||
|
mv /data/magisk/stock_boot* /data 2>/dev/null
|
||||||
|
fi
|
||||||
|
if [ -f /data/adb/magisk/stock_boot* ]; then
|
||||||
|
mv /data/adb/magisk/stock_boot* /data 2>/dev/null
|
||||||
|
fi
|
||||||
|
# Remove old dbs
|
||||||
|
rm -f /data/user*/*/magisk.db
|
||||||
|
[ -L /data/magisk.img ] || mv /data/magisk.img /data/adb/magisk.img 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
direct_install() {
|
direct_install() {
|
||||||
rm -rf /data/adb/magisk/* 2>/dev/null
|
rm -rf /data/adb/magisk/* 2>/dev/null
|
||||||
mkdir -p /data/adb/magisk 2>/dev/null
|
mkdir -p /data/adb/magisk 2>/dev/null
|
||||||
|
@ -398,7 +398,7 @@ static bool magisk_env() {
|
|||||||
LOGI("* Initializing Magisk environment\n");
|
LOGI("* Initializing Magisk environment\n");
|
||||||
|
|
||||||
// Alternative binaries paths
|
// Alternative binaries paths
|
||||||
const char *alt_bin[] = { "/cache/data_bin", "/data/magisk",
|
const char *alt_bin[] = { "/cache/data_adb/magisk", "/data/magisk",
|
||||||
"/data/data/com.topjohnwu.magisk/install",
|
"/data/data/com.topjohnwu.magisk/install",
|
||||||
"/data/user_de/0/com.topjohnwu.magisk/install" };
|
"/data/user_de/0/com.topjohnwu.magisk/install" };
|
||||||
for (auto &alt : alt_bin) {
|
for (auto &alt : alt_bin) {
|
||||||
|
@ -73,14 +73,6 @@ remove_system_su
|
|||||||
|
|
||||||
ui_print "- Constructing environment"
|
ui_print "- Constructing environment"
|
||||||
|
|
||||||
if $DATA; then
|
|
||||||
MAGISKBIN=/data/magisk
|
|
||||||
$DATA_DE && MAGISKBIN=/data/adb/magisk
|
|
||||||
run_migrations
|
|
||||||
else
|
|
||||||
MAGISKBIN=/cache/data_bin
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Copy required files
|
# Copy required files
|
||||||
rm -rf $MAGISKBIN/* 2>/dev/null
|
rm -rf $MAGISKBIN/* 2>/dev/null
|
||||||
mkdir -p $MAGISKBIN 2>/dev/null
|
mkdir -p $MAGISKBIN 2>/dev/null
|
||||||
|
@ -7,23 +7,57 @@
|
|||||||
#
|
#
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
#MAGISK_VERSION_STUB
|
###################
|
||||||
|
# Helper Functions
|
||||||
|
###################
|
||||||
|
|
||||||
# Detect whether in boot mode
|
ui_print() {
|
||||||
[ -z $BOOTMODE ] && BOOTMODE=false
|
$BOOTMODE && echo "$1" || echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD
|
||||||
$BOOTMODE || ps | grep zygote | grep -qv grep && BOOTMODE=true
|
}
|
||||||
$BOOTMODE || ps -A | grep zygote | grep -qv grep && BOOTMODE=true
|
|
||||||
|
|
||||||
# Presets
|
toupper() {
|
||||||
MAGISKTMP=/sbin/.magisk
|
echo "$@" | tr '[:lower:]' '[:upper:]'
|
||||||
[ -z $NVBASE ] && NVBASE=/data/adb
|
}
|
||||||
[ -z $MAGISKBIN ] && MAGISKBIN=$NVBASE/magisk
|
|
||||||
[ -z $IMG ] && IMG=$NVBASE/magisk.img
|
|
||||||
|
|
||||||
# Bootsigner related stuff
|
grep_cmdline() {
|
||||||
BOOTSIGNERCLASS=a.a
|
local REGEX="s/^$1=//p"
|
||||||
BOOTSIGNER="/system/bin/dalvikvm -Xnodex2oat -Xnoimage-dex2oat -cp \$APK \$BOOTSIGNERCLASS"
|
cat /proc/cmdline | tr '[:space:]' '\n' | sed -n "$REGEX" 2>/dev/null
|
||||||
BOOTSIGNED=false
|
}
|
||||||
|
|
||||||
|
grep_prop() {
|
||||||
|
local REGEX="s/^$1=//p"
|
||||||
|
shift
|
||||||
|
local FILES=$@
|
||||||
|
[ -z "$FILES" ] && FILES='/system/build.prop'
|
||||||
|
sed -n "$REGEX" $FILES 2>/dev/null | head -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
getvar() {
|
||||||
|
local VARNAME=$1
|
||||||
|
local VALUE=
|
||||||
|
VALUE=`grep_prop $VARNAME /sbin/.magisk/config /data/.magisk /cache/.magisk`
|
||||||
|
[ ! -z $VALUE ] && eval $VARNAME=\$VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
is_mounted() {
|
||||||
|
grep -q " `readlink -f $1` " /proc/mounts 2>/dev/null
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
abort() {
|
||||||
|
ui_print "$1"
|
||||||
|
$BOOTMODE || recovery_cleanup
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve_vars() {
|
||||||
|
MAGISKBIN=$NVBASE/magisk
|
||||||
|
IMG=$NVBASE/magisk.img
|
||||||
|
}
|
||||||
|
|
||||||
|
######################
|
||||||
|
# Environment Related
|
||||||
|
######################
|
||||||
|
|
||||||
setup_flashable() {
|
setup_flashable() {
|
||||||
$BOOTMODE && return
|
$BOOTMODE && return
|
||||||
@ -43,19 +77,59 @@ setup_flashable() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Backward compatibility
|
setup_bb() {
|
||||||
get_outfd() {
|
if [ -x $MAGISKTMP/busybox/busybox ]; then
|
||||||
setup_flashable
|
# Make sure this path is in the front
|
||||||
|
echo $PATH | grep -q "^$MAGISKTMP/busybox" || export PATH=$MAGISKTMP/busybox:$PATH
|
||||||
|
elif [ -x $TMPDIR/bin/busybox ]; then
|
||||||
|
# Make sure this path is in the front
|
||||||
|
echo $PATH | grep -q "^$TMPDIR/bin" || export PATH=$TMPDIR/bin:$PATH
|
||||||
|
else
|
||||||
|
# Construct the PATH
|
||||||
|
mkdir -p $TMPDIR/bin
|
||||||
|
ln -s $MAGISKBIN/busybox $TMPDIR/bin/busybox
|
||||||
|
$MAGISKBIN/busybox --install -s $TMPDIR/bin
|
||||||
|
export PATH=$TMPDIR/bin:$PATH
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_print() {
|
boot_actions() {
|
||||||
$BOOTMODE && echo "$1" || echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD
|
if [ ! -d $MAGISKTMP/mirror/bin ]; then
|
||||||
|
mkdir -p $MAGISKTMP/mirror/bin
|
||||||
|
mount -o bind $MAGISKBIN $MAGISKTMP/mirror/bin
|
||||||
|
fi
|
||||||
|
MAGISKBIN=$MAGISKTMP/mirror/bin
|
||||||
|
setup_bb
|
||||||
}
|
}
|
||||||
|
|
||||||
toupper() {
|
recovery_actions() {
|
||||||
echo "$@" | tr '[:lower:]' '[:upper:]'
|
# TWRP bug fix
|
||||||
|
mount -o bind /dev/urandom /dev/random
|
||||||
|
# Temporarily block out all custom recovery binaries/libs
|
||||||
|
mv /sbin /sbin_tmp
|
||||||
|
# Unset library paths
|
||||||
|
OLD_LD_LIB=$LD_LIBRARY_PATH
|
||||||
|
OLD_LD_PRE=$LD_PRELOAD
|
||||||
|
unset LD_LIBRARY_PATH
|
||||||
|
unset LD_PRELOAD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recovery_cleanup() {
|
||||||
|
mv /sbin_tmp /sbin 2>/dev/null
|
||||||
|
[ -z $OLD_PATH ] || export PATH=$OLD_PATH
|
||||||
|
[ -z $OLD_LD_LIB ] || export LD_LIBRARY_PATH=$OLD_LD_LIB
|
||||||
|
[ -z $OLD_LD_PRE ] || export LD_PRELOAD=$OLD_LD_PRE
|
||||||
|
ui_print "- Unmounting partitions"
|
||||||
|
umount -l /system_root 2>/dev/null
|
||||||
|
umount -l /system 2>/dev/null
|
||||||
|
umount -l /vendor 2>/dev/null
|
||||||
|
umount -l /dev/random 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# Installation Related
|
||||||
|
#######################
|
||||||
|
|
||||||
find_block() {
|
find_block() {
|
||||||
for BLOCK in "$@"; do
|
for BLOCK in "$@"; do
|
||||||
DEVICE=`find /dev/block -type l -iname $BLOCK | head -n 1` 2>/dev/null
|
DEVICE=`find /dev/block -type l -iname $BLOCK | head -n 1` 2>/dev/null
|
||||||
@ -139,51 +213,6 @@ get_flags() {
|
|||||||
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
|
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
|
||||||
}
|
}
|
||||||
|
|
||||||
grep_cmdline() {
|
|
||||||
local REGEX="s/^$1=//p"
|
|
||||||
cat /proc/cmdline | tr '[:space:]' '\n' | sed -n "$REGEX" 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
grep_prop() {
|
|
||||||
local REGEX="s/^$1=//p"
|
|
||||||
shift
|
|
||||||
local FILES=$@
|
|
||||||
[ -z "$FILES" ] && FILES='/system/build.prop'
|
|
||||||
sed -n "$REGEX" $FILES 2>/dev/null | head -n 1
|
|
||||||
}
|
|
||||||
|
|
||||||
getvar() {
|
|
||||||
local VARNAME=$1
|
|
||||||
local VALUE=
|
|
||||||
VALUE=`grep_prop $VARNAME /sbin/.magisk/config /data/.magisk /cache/.magisk`
|
|
||||||
[ ! -z $VALUE ] && eval $VARNAME=\$VALUE
|
|
||||||
}
|
|
||||||
|
|
||||||
run_migrations() {
|
|
||||||
# Update the broken boot backup
|
|
||||||
if [ -f /data/stock_boot_.img.gz ]; then
|
|
||||||
$MAGISKBIN/magiskboot --decompress /data/stock_boot_.img.gz /data/stock_boot.img
|
|
||||||
fi
|
|
||||||
# Update our previous backup to new format if exists
|
|
||||||
if [ -f /data/stock_boot.img ]; then
|
|
||||||
ui_print "- Migrating boot image backup"
|
|
||||||
SHA1=`$MAGISKBIN/magiskboot --sha1 /data/stock_boot.img 2>/dev/null`
|
|
||||||
STOCKDUMP=/data/stock_boot_${SHA1}.img
|
|
||||||
mv /data/stock_boot.img $STOCKDUMP
|
|
||||||
$MAGISKBIN/magiskboot --compress $STOCKDUMP
|
|
||||||
fi
|
|
||||||
# Move the stock backups
|
|
||||||
if [ -f /data/magisk/stock_boot* ]; then
|
|
||||||
mv /data/magisk/stock_boot* /data 2>/dev/null
|
|
||||||
fi
|
|
||||||
if [ -f /data/adb/magisk/stock_boot* ]; then
|
|
||||||
mv /data/adb/magisk/stock_boot* /data 2>/dev/null
|
|
||||||
fi
|
|
||||||
# Remove old dbs
|
|
||||||
rm -f /data/user*/*/magisk.db
|
|
||||||
[ -L /data/magisk.img ] || mv /data/magisk.img /data/adb/magisk.img 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
find_boot_image() {
|
find_boot_image() {
|
||||||
BOOTIMAGE=
|
BOOTIMAGE=
|
||||||
if [ ! -z $SLOT ]; then
|
if [ ! -z $SLOT ]; then
|
||||||
@ -201,23 +230,23 @@ flash_image() {
|
|||||||
# Make sure all blocks are writable
|
# Make sure all blocks are writable
|
||||||
$MAGISKBIN/magisk --unlock-blocks 2>/dev/null
|
$MAGISKBIN/magisk --unlock-blocks 2>/dev/null
|
||||||
case "$1" in
|
case "$1" in
|
||||||
*.gz) COM1="$MAGISKBIN/magiskboot --decompress '$1' - 2>/dev/null";;
|
*.gz) CMD1="$MAGISKBIN/magiskboot --decompress '$1' - 2>/dev/null";;
|
||||||
*) COM1="cat '$1'";;
|
*) CMD1="cat '$1'";;
|
||||||
esac
|
esac
|
||||||
if $BOOTSIGNED; then
|
if $BOOTSIGNED; then
|
||||||
COM2="$BOOTSIGNER -sign"
|
CMD2="$BOOTSIGNER -sign"
|
||||||
ui_print "- Sign image with test keys"
|
ui_print "- Sign image with test keys"
|
||||||
else
|
else
|
||||||
COM2="cat -"
|
CMD2="cat -"
|
||||||
fi
|
fi
|
||||||
if [ -b "$2" ]; then
|
if [ -b "$2" ]; then
|
||||||
local s_size=`stat -c '%s' "$1"`
|
local s_size=`stat -c '%s' "$1"`
|
||||||
local t_size=`blockdev --getsize64 "$2"`
|
local t_size=`blockdev --getsize64 "$2"`
|
||||||
[ $s_size -gt $t_size ] && return 1
|
[ $s_size -gt $t_size ] && return 1
|
||||||
eval $COM1 | eval $COM2 | cat - /dev/zero > "$2" 2>/dev/null
|
eval $CMD1 | eval $CMD2 | cat - /dev/zero > "$2" 2>/dev/null
|
||||||
else
|
else
|
||||||
ui_print "- Not block device, storing image"
|
ui_print "- Not block device, storing image"
|
||||||
eval $COM1 | eval $COM2 > "$2" 2>/dev/null
|
eval $CMD1 | eval $CMD2 > "$2" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -251,11 +280,6 @@ sign_chromeos() {
|
|||||||
mv new-boot.img.signed new-boot.img
|
mv new-boot.img.signed new-boot.img
|
||||||
}
|
}
|
||||||
|
|
||||||
is_mounted() {
|
|
||||||
grep -q " `readlink -f $1` " /proc/mounts 2>/dev/null
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_system_su() {
|
remove_system_su() {
|
||||||
if [ -f /system/bin/su -o -f /system/xbin/su ] && [ ! -f /su/bin/su ]; then
|
if [ -f /system/bin/su -o -f /system/xbin/su ] && [ ! -f /su/bin/su ]; then
|
||||||
ui_print "- Removing system installed root"
|
ui_print "- Removing system installed root"
|
||||||
@ -305,62 +329,24 @@ check_data() {
|
|||||||
# Test if DE storage is writable
|
# Test if DE storage is writable
|
||||||
$DATA && [ -d /data/adb ] && touch /data/adb/.rw && rm /data/adb/.rw && DATA_DE=true
|
$DATA && [ -d /data/adb ] && touch /data/adb/.rw && rm /data/adb/.rw && DATA_DE=true
|
||||||
fi
|
fi
|
||||||
|
$DATA && NVBASE=/data || NVBASE=/cache/data_adb
|
||||||
|
$DATA_DE && NVBASE=/data/adb
|
||||||
|
resolve_vars
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_bb() {
|
find_manager_apk() {
|
||||||
if [ -x $MAGISKTMP/busybox/busybox ]; then
|
APK=/data/adb/magisk.apk
|
||||||
# Make sure this path is in the front
|
[ -f $APK ] || APK=/data/magisk/magisk.apk
|
||||||
echo $PATH | grep -q "^$MAGISKTMP/busybox" || export PATH=$MAGISKTMP/busybox:$PATH
|
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
|
||||||
elif [ -x $TMPDIR/bin/busybox ]; then
|
if [ ! -f $APK ]; then
|
||||||
# Make sure this path is in the front
|
DBAPK=`magisk --sqlite "SELECT value FROM strings WHERE key='requester'" | cut -d= -f2`
|
||||||
echo $PATH | grep -q "^$TMPDIR/bin" || export PATH=$TMPDIR/bin:$PATH
|
[ -z "$DBAPK" ] || APK=/data/app/$DBAPK*/*.apk
|
||||||
else
|
|
||||||
# Construct the PATH
|
|
||||||
mkdir -p $TMPDIR/bin
|
|
||||||
ln -s $MAGISKBIN/busybox $TMPDIR/bin/busybox
|
|
||||||
$MAGISKBIN/busybox --install -s $TMPDIR/bin
|
|
||||||
export PATH=$TMPDIR/bin:$PATH
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_actions() {
|
#################
|
||||||
if [ ! -d $MAGISKTMP/mirror/bin ]; then
|
# Module Related
|
||||||
mkdir -p $MAGISKTMP/mirror/bin
|
#################
|
||||||
mount -o bind $MAGISKBIN $MAGISKTMP/mirror/bin
|
|
||||||
fi
|
|
||||||
MAGISKBIN=$MAGISKTMP/mirror/bin
|
|
||||||
setup_bb
|
|
||||||
}
|
|
||||||
|
|
||||||
recovery_actions() {
|
|
||||||
# TWRP bug fix
|
|
||||||
mount -o bind /dev/urandom /dev/random
|
|
||||||
# Temporarily block out all custom recovery binaries/libs
|
|
||||||
mv /sbin /sbin_tmp
|
|
||||||
# Unset library paths
|
|
||||||
OLD_LD_LIB=$LD_LIBRARY_PATH
|
|
||||||
OLD_LD_PRE=$LD_PRELOAD
|
|
||||||
unset LD_LIBRARY_PATH
|
|
||||||
unset LD_PRELOAD
|
|
||||||
}
|
|
||||||
|
|
||||||
recovery_cleanup() {
|
|
||||||
mv /sbin_tmp /sbin 2>/dev/null
|
|
||||||
[ -z $OLD_PATH ] || export PATH=$OLD_PATH
|
|
||||||
[ -z $OLD_LD_LIB ] || export LD_LIBRARY_PATH=$OLD_LD_LIB
|
|
||||||
[ -z $OLD_LD_PRE ] || export LD_PRELOAD=$OLD_LD_PRE
|
|
||||||
ui_print "- Unmounting partitions"
|
|
||||||
umount -l /system_root 2>/dev/null
|
|
||||||
umount -l /system 2>/dev/null
|
|
||||||
umount -l /vendor 2>/dev/null
|
|
||||||
umount -l /dev/random 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
abort() {
|
|
||||||
ui_print "$1"
|
|
||||||
$BOOTMODE || recovery_cleanup
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
set_perm() {
|
set_perm() {
|
||||||
chown $2:$3 $1 || return 1
|
chown $2:$3 $1 || return 1
|
||||||
@ -437,12 +423,29 @@ unmount_magisk_img() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
find_manager_apk() {
|
##################################
|
||||||
APK=/data/adb/magisk.apk
|
# Backwards Compatibile Functions
|
||||||
[ -f $APK ] || APK=/data/magisk/magisk.apk
|
##################################
|
||||||
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
|
get_outfd() { setup_flashable; }
|
||||||
if [ ! -f $APK ]; then
|
|
||||||
DBAPK=`magisk --sqlite "SELECT value FROM strings WHERE key='requester'" | cut -d= -f2`
|
#######
|
||||||
[ -z "$DBAPK" ] || APK=/data/app/$DBAPK*/*.apk
|
# main
|
||||||
fi
|
#######
|
||||||
}
|
|
||||||
|
#MAGISK_VERSION_STUB
|
||||||
|
|
||||||
|
# Detect whether in boot mode
|
||||||
|
[ -z $BOOTMODE ] && BOOTMODE=false
|
||||||
|
$BOOTMODE || ps | grep zygote | grep -qv grep && BOOTMODE=true
|
||||||
|
$BOOTMODE || ps -A | grep zygote | grep -qv grep && BOOTMODE=true
|
||||||
|
|
||||||
|
# Presets
|
||||||
|
MAGISKTMP=/sbin/.magisk
|
||||||
|
NVBASE=/data/adb
|
||||||
|
|
||||||
|
# Bootsigner related stuff
|
||||||
|
BOOTSIGNERCLASS=a.a
|
||||||
|
BOOTSIGNER="/system/bin/dalvikvm -Xnodex2oat -Xnoimage-dex2oat -cp \$APK \$BOOTSIGNERCLASS"
|
||||||
|
BOOTSIGNED=false
|
||||||
|
|
||||||
|
resolve_vars
|
||||||
|
Loading…
Reference in New Issue
Block a user