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
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))
.to(console, logs).exec().isSuccess())
return false;
@ -245,7 +245,7 @@ public abstract class MagiskInstaller {
.to(console, logs).exec().isSuccess())
return false;
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;
}

View File

@ -16,7 +16,7 @@ import androidx.annotation.NonNull;
public class RootUtils extends Shell.Initializer {
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

View File

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

View File

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

View File

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

View File

@ -45,14 +45,12 @@ is_mounted /data || mount /data || is_mounted /cache || mount /cache || abort "!
mount_partitions
find_boot_image
find_dtbo_image
check_data
get_flags
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
ui_print "- Target image: $BOOTIMAGE"
[ -z $DTBOIMAGE ] || ui_print "- DTBO image: $DTBOIMAGE"
# Detect version and architecture
api_level_arch_detect
@ -76,7 +74,7 @@ ui_print "- Constructing environment"
# Copy required files
rm -rf $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
# addon.d

View File

@ -59,7 +59,7 @@ find_boot_image
find_dtbo_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"
cd $MAGISKBIN
@ -125,18 +125,14 @@ esac
ui_print "- Removing Magisk files"
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
mount -o rw,remount /system
rm -f /system/addon.d/99-magisk.sh
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 /
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
}
setup_bb() {
BBDIR=$TMPDIR/bin
export BBDIR=$TMPDIR/bin
BBBIN=$BBDIR/busybox
mkdir -p $BBDIR 2>/dev/null
extract_bb
@ -20,7 +20,9 @@ case "$1" in
extract_bb
;;
"indep"|"sh")
TMPDIR=.;setup_bb;shift
TMPDIR=.
setup_bb
shift
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
###################
@ -61,10 +82,10 @@ resolve_vars() {
######################
setup_flashable() {
$BOOTMODE && return
# Preserve environment varibles
OLD_PATH=$PATH
setup_bb
ensure_bb
$BOOTMODE && return
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
# We will have to manually find out OUTFD
for FD in `ls /proc/$$/fd`; do
@ -78,48 +99,41 @@ setup_flashable() {
fi
}
setup_bb() {
ensure_bb() {
if [ -x $MAGISKTMP/busybox/busybox ]; then
# Make sure this path is in the front
echo $PATH | grep -q "^$MAGISKTMP/busybox" || export PATH=$MAGISKTMP/busybox:$PATH
[ -z $BBDIR ] && BBDIR=$MAGISKTMP/busybox
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
[ -z $BBDIR ] && BBDIR=$TMPDIR/bin
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
[ -z $BBDIR ] && BBDIR=$TMPDIR/bin
mkdir -p $BBDIR
ln -s $MAGISKBIN/busybox $BBDIR/busybox
$MAGISKBIN/busybox --install -s $BBDIR
fi
}
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
echo $PATH | grep -q "^$BBDIR" || export PATH=$BBDIR:$PATH
}
recovery_actions() {
# TWRP bug fix
# Make sure random don't get blocked
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
OLD_LD_CFG=$LD_CONFIG_FILE
unset LD_LIBRARY_PATH
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() {
mv /sbin_tmp /sbin 2>/dev/null
[ -z $OLD_PATH ] || export PATH=$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
[ -z $OLD_LD_CFG ] || export LD_CONFIG_FILE=$OLD_LD_CFG
ui_print "- Unmounting partitions"
umount -l /system_root 2>/dev/null
umount -l /system 2>/dev/null
@ -257,7 +271,9 @@ find_dtbo_image() {
}
patch_dtbo_image() {
find_dtbo_image
if [ ! -z $DTBOIMAGE ]; then
ui_print "- DTBO image: $DTBOIMAGE"
if $MAGISKBIN/magiskboot --dtb-test $DTBOIMAGE; then
ui_print "- Backing up stock DTBO image"
$MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz
@ -397,24 +413,10 @@ unmount_magisk_img() {
rm -f $MODULEPATH 2>/dev/null
}
#######
# main
#######
boot_actions() { return; }
#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
########
# Setup
########
resolve_vars