mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 16:07:39 +00:00
Update scripts to use BusyBox standalone mode
This commit is contained in:
parent
409cb06ea0
commit
db9a4b31f9
@ -56,10 +56,9 @@ initialize() {
|
|||||||
if $BOOTMODE; then
|
if $BOOTMODE; then
|
||||||
# Override ui_print when booted
|
# Override ui_print when booted
|
||||||
ui_print() { log -t Magisk -- "$1"; }
|
ui_print() { log -t Magisk -- "$1"; }
|
||||||
else
|
fi
|
||||||
OUTFD=
|
OUTFD=
|
||||||
setup_flashable
|
setup_flashable
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
@ -73,9 +72,9 @@ main() {
|
|||||||
|
|
||||||
$BOOTMODE || recovery_actions
|
$BOOTMODE || recovery_actions
|
||||||
|
|
||||||
ui_print "************************"
|
PRETTY_VER=$MAGISK_VER
|
||||||
ui_print "* Magisk v$MAGISK_VER addon.d"
|
echo $PRETTY_VER | grep -q '\.' && PRETTY_VER=v$PRETTY_VER
|
||||||
ui_print "************************"
|
print_title "Magisk $PRETTY_VER addon.d"
|
||||||
|
|
||||||
mount_partitions
|
mount_partitions
|
||||||
check_data
|
check_data
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
#MAGISK
|
#MAGISK
|
||||||
##########################################################################################
|
############################################
|
||||||
#
|
#
|
||||||
# Magisk Flash Script (updater-script)
|
# Magisk Flash Script (updater-script)
|
||||||
# by topjohnwu
|
# by topjohnwu
|
||||||
#
|
#
|
||||||
# This script will detect, construct the environment for Magisk
|
############################################
|
||||||
# It will then call boot_patch.sh to patch the boot image
|
|
||||||
#
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
##########################################################################################
|
############################################
|
||||||
# Preparation
|
# Preparation
|
||||||
##########################################################################################
|
############################################
|
||||||
|
|
||||||
COMMONDIR=$INSTALLER/common
|
COMMONDIR=$INSTALLER/common
|
||||||
APK=$COMMONDIR/magisk.apk
|
APK=$COMMONDIR/magisk.apk
|
||||||
@ -33,13 +30,13 @@ fi
|
|||||||
|
|
||||||
setup_flashable
|
setup_flashable
|
||||||
|
|
||||||
##########################################################################################
|
############################################
|
||||||
# Detection
|
# Detection
|
||||||
##########################################################################################
|
############################################
|
||||||
|
|
||||||
ui_print "************************"
|
PRETTY_VER=$MAGISK_VER
|
||||||
ui_print "* Magisk v$MAGISK_VER Installer"
|
echo $PRETTY_VER | grep -q '\.' && PRETTY_VER=v$PRETTY_VER
|
||||||
ui_print "************************"
|
print_title "Magisk $PRETTY_VER Installer"
|
||||||
|
|
||||||
is_mounted /data || mount /data || is_mounted /cache || mount /cache
|
is_mounted /data || mount /data || is_mounted /cache || mount /cache
|
||||||
mount_partitions
|
mount_partitions
|
||||||
@ -63,16 +60,16 @@ chmod -R 755 $CHROMEDIR $BINDIR
|
|||||||
# Check if system root is installed and remove
|
# Check if system root is installed and remove
|
||||||
remove_system_su
|
remove_system_su
|
||||||
|
|
||||||
##########################################################################################
|
############################################
|
||||||
# Environment
|
# Environment
|
||||||
##########################################################################################
|
############################################
|
||||||
|
|
||||||
ui_print "- Constructing environment"
|
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 $BBDIR/busybox $MAGISKBIN
|
cp -af $BINDIR/. $COMMONDIR/. $CHROMEDIR $BBBIN $MAGISKBIN
|
||||||
chmod -R 755 $MAGISKBIN
|
chmod -R 755 $MAGISKBIN
|
||||||
|
|
||||||
# addon.d
|
# addon.d
|
||||||
@ -86,9 +83,9 @@ fi
|
|||||||
|
|
||||||
$BOOTMODE || recovery_actions
|
$BOOTMODE || recovery_actions
|
||||||
|
|
||||||
##########################################################################################
|
############################################
|
||||||
# Boot/DTBO Patching
|
# Boot/DTBO Patching
|
||||||
##########################################################################################
|
############################################
|
||||||
|
|
||||||
install_magisk
|
install_magisk
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#MAGISK
|
#MAGISK
|
||||||
##########################################################################################
|
############################################
|
||||||
#
|
#
|
||||||
# Magisk Uninstaller
|
# Magisk Uninstaller
|
||||||
# by topjohnwu
|
# by topjohnwu
|
||||||
#
|
#
|
||||||
##########################################################################################
|
############################################
|
||||||
|
|
||||||
##########################################################################################
|
############################################
|
||||||
# Preparation
|
# Preparation
|
||||||
##########################################################################################
|
############################################
|
||||||
|
|
||||||
# This path should work in any cases
|
# This path should work in any cases
|
||||||
TMPDIR=/dev/tmp
|
TMPDIR=/dev/tmp
|
||||||
@ -33,9 +33,7 @@ fi
|
|||||||
|
|
||||||
setup_flashable
|
setup_flashable
|
||||||
|
|
||||||
ui_print "************************"
|
print_title "Magisk Uninstaller"
|
||||||
ui_print " Magisk Uninstaller "
|
|
||||||
ui_print "************************"
|
|
||||||
|
|
||||||
is_mounted /data || mount /data || abort "! Unable to mount partitions"
|
is_mounted /data || mount /data || abort "! Unable to mount partitions"
|
||||||
is_mounted /cache || mount /cache 2>/dev/null
|
is_mounted /cache || mount /cache 2>/dev/null
|
||||||
@ -53,9 +51,9 @@ $DATA_DE || abort "! Cannot access /data, please uninstall with Magisk Manager"
|
|||||||
$BOOTMODE || recovery_actions
|
$BOOTMODE || recovery_actions
|
||||||
run_migrations
|
run_migrations
|
||||||
|
|
||||||
##########################################################################################
|
############################################
|
||||||
# Uninstall
|
# Uninstall
|
||||||
##########################################################################################
|
############################################
|
||||||
|
|
||||||
get_flags
|
get_flags
|
||||||
find_boot_image
|
find_boot_image
|
||||||
|
@ -7,32 +7,30 @@ extract_bb() {
|
|||||||
"$BBBIN" >/dev/null 2>&1 || dd if="$0" of="$BBBIN" bs=1024 skip=$(($X86_CNT + 1))
|
"$BBBIN" >/dev/null 2>&1 || dd if="$0" of="$BBBIN" bs=1024 skip=$(($X86_CNT + 1))
|
||||||
}
|
}
|
||||||
setup_bb() {
|
setup_bb() {
|
||||||
export BBDIR=$TMPDIR/bin
|
mkdir -p $TMPDIR 2>/dev/null
|
||||||
BBBIN=$BBDIR/busybox
|
BBBIN=$TMPDIR/busybox
|
||||||
mkdir -p $BBDIR 2>/dev/null
|
|
||||||
extract_bb
|
extract_bb
|
||||||
$BBBIN --install -s $BBDIR
|
|
||||||
export PATH=$BBDIR:$PATH
|
|
||||||
}
|
}
|
||||||
|
export BBBIN
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"extract"|"-x")
|
"extract"|"-x")
|
||||||
[ -z "$2" ] && BBBIN=./busybox || BBBIN="$2"
|
[ -z "$2" ] && BBBIN=./busybox || BBBIN="$2"
|
||||||
extract_bb
|
extract_bb
|
||||||
;;
|
;;
|
||||||
"indep"|"sh")
|
"sh")
|
||||||
TMPDIR=.
|
TMPDIR=.
|
||||||
setup_bb
|
setup_bb
|
||||||
shift
|
shift
|
||||||
exec /system/bin/sh "$@"
|
exec ./busybox sh -o standalone "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
export TMPDIR=/dev/tmp
|
TMPDIR=/dev/tmp
|
||||||
rm -rf $TMPDIR 2>/dev/null
|
rm -rf $TMPDIR 2>/dev/null
|
||||||
setup_bb
|
setup_bb
|
||||||
export INSTALLER=$TMPDIR/install
|
export INSTALLER=$TMPDIR/install
|
||||||
mkdir -p $INSTALLER
|
$BBBIN mkdir -p $INSTALLER
|
||||||
unzip -o "$3" -d $INSTALLER >&2
|
$BBBIN unzip -o "$3" -d $INSTALLER >&2
|
||||||
exec sh $INSTALLER/META-INF/com/google/android/updater-script "$@"
|
exec $BBBIN sh -o standalone $INSTALLER/META-INF/com/google/android/updater-script "$@"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit
|
exit
|
||||||
|
@ -56,13 +56,20 @@ resolve_vars() {
|
|||||||
SERVICED=$NVBASE/service.d
|
SERVICED=$NVBASE/service.d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_title() {
|
||||||
|
local len=$(echo -n $1 | wc -c)
|
||||||
|
len=$((len + 2))
|
||||||
|
local pounds=$(printf "%${len}s" | tr ' ' '*')
|
||||||
|
ui_print "$pounds"
|
||||||
|
ui_print " $1 "
|
||||||
|
ui_print "$pounds"
|
||||||
|
}
|
||||||
|
|
||||||
######################
|
######################
|
||||||
# Environment Related
|
# Environment Related
|
||||||
######################
|
######################
|
||||||
|
|
||||||
setup_flashable() {
|
setup_flashable() {
|
||||||
# Preserve environment varibles
|
|
||||||
OLD_PATH=$PATH
|
|
||||||
ensure_bb
|
ensure_bb
|
||||||
$BOOTMODE && return
|
$BOOTMODE && return
|
||||||
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
|
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
|
||||||
@ -79,18 +86,23 @@ setup_flashable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure_bb() {
|
ensure_bb() {
|
||||||
if [ -x $MAGISKTMP/busybox/busybox ]; then
|
[ -o standalone ] && return
|
||||||
[ -z $BBDIR ] && BBDIR=$MAGISKTMP/busybox
|
set -o standalone 2>/dev/null && return
|
||||||
elif [ -x $TMPDIR/bin/busybox ]; then
|
|
||||||
[ -z $BBDIR ] && BBDIR=$TMPDIR/bin
|
# At this point, we are not running in BusyBox ash
|
||||||
|
# Find our busybox binary
|
||||||
|
local BUSYBOX
|
||||||
|
if [ -f $TMPDIR/busybox ]; then
|
||||||
|
BUSYBOX=$TMPDIR/busybox
|
||||||
|
elif [ -f $MAGISKBIN/busybox ]; then
|
||||||
|
BUSYBOX=$MAGISKBIN/busybox
|
||||||
else
|
else
|
||||||
# Construct the PATH
|
abort "! Cannot find BusyBox"
|
||||||
[ -z $BBDIR ] && BBDIR=$TMPDIR/bin
|
|
||||||
mkdir -p $BBDIR
|
|
||||||
ln -s $MAGISKBIN/busybox $BBDIR/busybox
|
|
||||||
$MAGISKBIN/busybox --install -s $BBDIR
|
|
||||||
fi
|
fi
|
||||||
echo $PATH | grep -q "^$BBDIR" || export PATH=$BBDIR:$PATH
|
|
||||||
|
# Re-exec our script
|
||||||
|
chmod 755 $BUSYBOX
|
||||||
|
exec $BUSYBOX sh -o standalone $0 "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
recovery_actions() {
|
recovery_actions() {
|
||||||
@ -103,9 +115,6 @@ recovery_actions() {
|
|||||||
unset LD_LIBRARY_PATH
|
unset LD_LIBRARY_PATH
|
||||||
unset LD_PRELOAD
|
unset LD_PRELOAD
|
||||||
unset LD_CONFIG_FILE
|
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() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user