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
+2 -6
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
;;
+1 -3
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
+3 -7
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
+4 -2
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 "$@"
;;
*)
+45 -43
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