Update scripts

This commit is contained in:
topjohnwu 2019-02-24 02:11:11 -05:00
parent 0f46493477
commit defbbdfe21
9 changed files with 74 additions and 87 deletions

View File

@ -215,7 +215,7 @@ public abstract class MagiskInstaller {
// Patch boot image // Patch boot image
if (!Shell.sh(Utils.fmt("cd %s; KEEPFORCEENCRYPT=%b KEEPVERITY=%b " + if (!Shell.sh(Utils.fmt("cd %s; KEEPFORCEENCRYPT=%b KEEPVERITY=%b " +
"sh update-binary indep boot_patch.sh %s", "sh update-binary sh boot_patch.sh %s",
installDir, Config.keepEnc, Config.keepVerity, srcBoot)) installDir, Config.keepEnc, Config.keepVerity, srcBoot))
.to(console, logs).exec().isSuccess()) .to(console, logs).exec().isSuccess())
return false; return false;
@ -245,7 +245,7 @@ public abstract class MagiskInstaller {
.to(console, logs).exec().isSuccess()) .to(console, logs).exec().isSuccess())
return false; return false;
if (!Config.keepVerity) if (!Config.keepVerity)
Shell.su("find_dtbo_image", "patch_dtbo_image").to(console, logs).exec(); Shell.su("patch_dtbo_image").to(console, logs).exec();
return true; return true;
} }

View File

@ -16,7 +16,7 @@ import androidx.annotation.NonNull;
public class RootUtils extends Shell.Initializer { public class RootUtils extends Shell.Initializer {
public static void rmAndLaunch(String rm, String launch) { public static void rmAndLaunch(String rm, String launch) {
Shell.su(Utils.fmt("(rm_launch %d %s %s)&", Const.USER_ID, rm, launch)).exec(); Shell.su(Utils.fmt("(rm_launch %s %s)&", rm, launch)).exec();
} }
@Override @Override

View File

@ -1,18 +1,18 @@
env_check() { env_check() {
for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do
[ -f /data/adb/magisk/$file ] || return 1 [ -f $MAGISKBIN/$file ] || return 1
done done
return 0 return 0
} }
fix_env() { fix_env() {
cd /data/adb/magisk cd $MAGISKBIN
local OLDPATH="$PATH" local OLDPATH="$PATH"
PATH=/sbin:/system/bin:/vendor/bin PATH=/sbin:/system/bin:/vendor/bin
sh update-binary extract sh update-binary -x
PATH="$OLDPATH" PATH="$OLDPATH"
./busybox rm -f /sbin/.magisk/busybox/* ./busybox rm -f $MAGISKTMP/busybox/*
/sbin/.magisk/mirror/bin/busybox --install -s /sbin/.magisk/busybox $MAGISKTMP/mirror/bin/busybox --install -s $MAGISKTMP/busybox
rm -f update-binary magisk.apk rm -f update-binary magisk.apk
cd / cd /
} }
@ -31,11 +31,11 @@ run_migrations() {
} }
direct_install() { direct_install() {
rm -rf /data/adb/magisk/* 2>/dev/null rm -rf $MAGISKBIN/* 2>/dev/null
mkdir -p /data/adb/magisk 2>/dev/null mkdir -p $MAGISKBIN 2>/dev/null
chmod 700 /data/adb chmod 700 $NVBASE
cp -rf $1/* /data/adb/magisk cp -af $1/. $MAGISKBIN
rm -rf /data/adb/magisk/new-boot.img rm -f $MAGISKBIN/new-boot.img
echo "- Flashing new boot image" echo "- Flashing new boot image"
flash_image $1/new-boot.img $2 flash_image $1/new-boot.img $2
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -47,12 +47,7 @@ direct_install() {
} }
mm_patch_dtbo() { mm_patch_dtbo() {
if $KEEPVERITY; then $KEEPVERITY && return 1 || patch_dtbo_image
return 1
else
find_dtbo_image
patch_dtbo_image
fi
} }
restore_imgs() { restore_imgs() {
@ -114,8 +109,7 @@ EOF
} }
rm_launch() { rm_launch() {
db_clean $1 pm uninstall $1
pm uninstall $2 am start -n ${2}/a.c
am start -n ${3}/a.c
exit exit
} }

View File

@ -374,10 +374,9 @@ def zip_uninstaller(args):
# Binaries # Binaries
for lib_dir, zip_dir in [('armeabi-v7a', 'arm'), ('x86', 'x86')]: for lib_dir, zip_dir in [('armeabi-v7a', 'arm'), ('x86', 'x86')]:
for bin in ['magisk', 'magiskboot']: source = os.path.join('native', 'out', lib_dir, 'magiskboot')
source = os.path.join('native', 'out', lib_dir, bin) target = os.path.join(zip_dir, 'magiskboot')
target = os.path.join(zip_dir, bin) zip_with_msg(zipf, source, target)
zip_with_msg(zipf, source, target)
# Scripts # Scripts
# util_functions.sh # util_functions.sh

View File

@ -33,8 +33,6 @@ initialize() {
# Load utility functions # Load utility functions
. $MAGISKBIN/util_functions.sh . $MAGISKBIN/util_functions.sh
find_manager_apk
} }
show_logo() { show_logo() {
@ -44,6 +42,7 @@ show_logo() {
} }
installation() { installation() {
find_manager_apk
find_boot_image find_boot_image
find_dtbo_image find_dtbo_image
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image" [ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
@ -98,7 +97,6 @@ main_v1() {
} }
main_v2() { main_v2() {
boot_actions
show_logo show_logo
mount_partitions mount_partitions
# Swap the slot # Swap the slot
@ -137,9 +135,7 @@ case "$1" in
addond-v2) addond-v2)
initialize initialize
# Override ui_print # Override ui_print
ui_print() { ui_print() { log -t Magisk -- "$1"; }
log -t Magisk -- "$1"
}
# addon.d-v2 # addon.d-v2
main_v2 main_v2
;; ;;

View File

@ -45,14 +45,12 @@ is_mounted /data || mount /data || is_mounted /cache || mount /cache || abort "!
mount_partitions mount_partitions
find_boot_image find_boot_image
find_dtbo_image
check_data check_data
get_flags get_flags
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image" [ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
ui_print "- Target image: $BOOTIMAGE" ui_print "- Target image: $BOOTIMAGE"
[ -z $DTBOIMAGE ] || ui_print "- DTBO image: $DTBOIMAGE"
# Detect version and architecture # Detect version and architecture
api_level_arch_detect api_level_arch_detect
@ -76,7 +74,7 @@ ui_print "- Constructing environment"
# 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
cp -af $BINDIR/. $COMMONDIR/. $CHROMEDIR $TMPDIR/bin/busybox $MAGISKBIN cp -af $BINDIR/. $COMMONDIR/. $CHROMEDIR $BBDIR/busybox $MAGISKBIN
chmod -R 755 $MAGISKBIN chmod -R 755 $MAGISKBIN
# addon.d # addon.d

View File

@ -59,7 +59,7 @@ find_boot_image
find_dtbo_image find_dtbo_image
[ -e $BOOTIMAGE ] || abort "! Unable to detect boot image" [ -e $BOOTIMAGE ] || abort "! Unable to detect boot image"
ui_print "- Found boot/ramdisk image: $BOOTIMAGE" ui_print "- Found target image: $BOOTIMAGE"
[ -z $DTBOIMAGE ] || ui_print "- Found dtbo image: $DTBOIMAGE" [ -z $DTBOIMAGE ] || ui_print "- Found dtbo image: $DTBOIMAGE"
cd $MAGISKBIN cd $MAGISKBIN
@ -125,18 +125,14 @@ esac
ui_print "- Removing Magisk files" ui_print "- Removing Magisk files"
rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data/property/*magisk* \ rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data/property/*magisk* \
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/adb/*magisk* 2>/dev/null /data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/adb/*magisk* \
/data/adb/post-fs-data.d /data/adb/service.d /data/adb/modules* 2>/dev/null
if [ -f /system/addon.d/99-magisk.sh ]; then if [ -f /system/addon.d/99-magisk.sh ]; then
mount -o rw,remount /system mount -o rw,remount /system
rm -f /system/addon.d/99-magisk.sh rm -f /system/addon.d/99-magisk.sh
fi fi
# Remove persist props (for Android P+ using protobuf)
for prop in `./magisk resetprop -p | grep -E 'persist.*magisk' | grep -oE '^\[[a-zA-Z0-9.@:_-]+\]' | tr -d '[]'`; do
./magisk resetprop -p --delete $prop
done
cd / cd /
if $BOOTMODE; then if $BOOTMODE; then

View File

@ -7,7 +7,7 @@ extract_bb() {
"$BBBIN" >/dev/null || dd if="$0" of="$BBBIN" bs=1024 skip=1 count=$X86_CNT "$BBBIN" >/dev/null || dd if="$0" of="$BBBIN" bs=1024 skip=1 count=$X86_CNT
} }
setup_bb() { setup_bb() {
BBDIR=$TMPDIR/bin export BBDIR=$TMPDIR/bin
BBBIN=$BBDIR/busybox BBBIN=$BBDIR/busybox
mkdir -p $BBDIR 2>/dev/null mkdir -p $BBDIR 2>/dev/null
extract_bb extract_bb
@ -20,7 +20,9 @@ case "$1" in
extract_bb extract_bb
;; ;;
"indep"|"sh") "indep"|"sh")
TMPDIR=.;setup_bb;shift TMPDIR=.
setup_bb
shift
exec /system/bin/sh "$@" exec /system/bin/sh "$@"
;; ;;
*) *)

View File

@ -7,6 +7,27 @@
# #
########################################################################################## ##########################################################################################
##########
# Presets
##########
#MAGISK_VERSION_STUB
# Detect whether in boot mode
[ -z $BOOTMODE ] && BOOTMODE=false
$BOOTMODE || ps | grep zygote | grep -qv grep && BOOTMODE=true
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -qv grep && BOOTMODE=true
# Presets
MAGISKTMP=/sbin/.magisk
NVBASE=/data/adb
[ -z $TMPDIR ] && TMPDIR=/dev/tmp
# Bootsigner related stuff
BOOTSIGNERCLASS=a.a
BOOTSIGNER="/system/bin/dalvikvm -Xnodex2oat -Xnoimage-dex2oat -cp \$APK \$BOOTSIGNERCLASS"
BOOTSIGNED=false
################### ###################
# Helper Functions # Helper Functions
################### ###################
@ -61,10 +82,10 @@ resolve_vars() {
###################### ######################
setup_flashable() { setup_flashable() {
$BOOTMODE && return
# Preserve environment varibles # Preserve environment varibles
OLD_PATH=$PATH OLD_PATH=$PATH
setup_bb ensure_bb
$BOOTMODE && return
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
# We will have to manually find out OUTFD # We will have to manually find out OUTFD
for FD in `ls /proc/$$/fd`; do for FD in `ls /proc/$$/fd`; do
@ -78,48 +99,41 @@ setup_flashable() {
fi fi
} }
setup_bb() { ensure_bb() {
if [ -x $MAGISKTMP/busybox/busybox ]; then if [ -x $MAGISKTMP/busybox/busybox ]; then
# Make sure this path is in the front [ -z $BBDIR ] && BBDIR=$MAGISKTMP/busybox
echo $PATH | grep -q "^$MAGISKTMP/busybox" || export PATH=$MAGISKTMP/busybox:$PATH
elif [ -x $TMPDIR/bin/busybox ]; then elif [ -x $TMPDIR/bin/busybox ]; then
# Make sure this path is in the front [ -z $BBDIR ] && BBDIR=$TMPDIR/bin
echo $PATH | grep -q "^$TMPDIR/bin" || export PATH=$TMPDIR/bin:$PATH
else else
# Construct the PATH # Construct the PATH
mkdir -p $TMPDIR/bin [ -z $BBDIR ] && BBDIR=$TMPDIR/bin
ln -s $MAGISKBIN/busybox $TMPDIR/bin/busybox mkdir -p $BBDIR
$MAGISKBIN/busybox --install -s $TMPDIR/bin ln -s $MAGISKBIN/busybox $BBDIR/busybox
export PATH=$TMPDIR/bin:$PATH $MAGISKBIN/busybox --install -s $BBDIR
fi fi
} echo $PATH | grep -q "^$BBDIR" || export PATH=$BBDIR:$PATH
boot_actions() {
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
} }
recovery_actions() { recovery_actions() {
# TWRP bug fix # Make sure random don't get blocked
mount -o bind /dev/urandom /dev/random mount -o bind /dev/urandom /dev/random
# Temporarily block out all custom recovery binaries/libs
mv /sbin /sbin_tmp
# Unset library paths # Unset library paths
OLD_LD_LIB=$LD_LIBRARY_PATH OLD_LD_LIB=$LD_LIBRARY_PATH
OLD_LD_PRE=$LD_PRELOAD OLD_LD_PRE=$LD_PRELOAD
OLD_LD_CFG=$LD_CONFIG_FILE
unset LD_LIBRARY_PATH unset LD_LIBRARY_PATH
unset LD_PRELOAD unset LD_PRELOAD
unset LD_CONFIG_FILE
# Force our own busybox path to be in the front
# and do not use anything in recovery's sbin
export PATH=$BBDIR:/system/bin:/vendor/bin
} }
recovery_cleanup() { recovery_cleanup() {
mv /sbin_tmp /sbin 2>/dev/null export PATH=$OLD_PATH
[ -z $OLD_PATH ] || export PATH=$OLD_PATH
[ -z $OLD_LD_LIB ] || export LD_LIBRARY_PATH=$OLD_LD_LIB [ -z $OLD_LD_LIB ] || export LD_LIBRARY_PATH=$OLD_LD_LIB
[ -z $OLD_LD_PRE ] || export LD_PRELOAD=$OLD_LD_PRE [ -z $OLD_LD_PRE ] || export LD_PRELOAD=$OLD_LD_PRE
[ -z $OLD_LD_CFG ] || export LD_CONFIG_FILE=$OLD_LD_CFG
ui_print "- Unmounting partitions" ui_print "- Unmounting partitions"
umount -l /system_root 2>/dev/null umount -l /system_root 2>/dev/null
umount -l /system 2>/dev/null umount -l /system 2>/dev/null
@ -257,7 +271,9 @@ find_dtbo_image() {
} }
patch_dtbo_image() { patch_dtbo_image() {
find_dtbo_image
if [ ! -z $DTBOIMAGE ]; then if [ ! -z $DTBOIMAGE ]; then
ui_print "- DTBO image: $DTBOIMAGE"
if $MAGISKBIN/magiskboot --dtb-test $DTBOIMAGE; then if $MAGISKBIN/magiskboot --dtb-test $DTBOIMAGE; then
ui_print "- Backing up stock DTBO image" ui_print "- Backing up stock DTBO image"
$MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz $MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz
@ -397,24 +413,10 @@ unmount_magisk_img() {
rm -f $MODULEPATH 2>/dev/null rm -f $MODULEPATH 2>/dev/null
} }
####### boot_actions() { return; }
# main
#######
#MAGISK_VERSION_STUB ########
# Setup
# 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 resolve_vars