mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-19 02:01:28 +00:00
Update emulator.sh to support all AVD images
This commit is contained in:
parent
cdb53ca049
commit
ee39616a8b
@ -7,15 +7,11 @@
|
|||||||
# Magisk Manager will be happy to run properly within the official
|
# Magisk Manager will be happy to run properly within the official
|
||||||
# emulator bundled with Android Studio (AVD).
|
# emulator bundled with Android Studio (AVD).
|
||||||
#
|
#
|
||||||
# ONLY use this script for developing Magisk Manager in the
|
# ONLY use this script for developing Magisk Manager or root apps
|
||||||
# emulator. The constructed Magisk environment is not a fully
|
# in the emulator. The constructed Magisk environment is not a
|
||||||
# functional one as if it is running on an actual device.
|
# fully functional one as if it is running on an actual device.
|
||||||
# The script only supports non system-as-root images, meaning
|
|
||||||
# AVD images that are newer than API 25 are NOT supported.
|
|
||||||
# This script is meant to be used for emulators running obscure
|
|
||||||
# Android versions; use an actual device for modern Androids.
|
|
||||||
#
|
#
|
||||||
# The script assumes you are using x86 emulator images.
|
# The script assumes you are using x86/x64 emulator images.
|
||||||
# Build binaries with `./build.py binary` before running this script.
|
# Build binaries with `./build.py binary` before running this script.
|
||||||
#
|
#
|
||||||
################################################################
|
################################################################
|
||||||
@ -25,10 +21,21 @@ abort() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mount_sbin() {
|
||||||
|
mount -t tmpfs -o 'mode=0755' tmpfs /sbin
|
||||||
|
$SELINUX && chcon u:object_r:rootfs:s0 /sbin
|
||||||
|
}
|
||||||
|
|
||||||
if [ ! -f /system/build.prop ]; then
|
if [ ! -f /system/build.prop ]; then
|
||||||
# Running on PC
|
# Running on PC
|
||||||
cd "`dirname "$0"`/.."
|
cd "`dirname "$0"`/.."
|
||||||
adb push native/out/x86/busybox native/out/x86/magisk scripts/emulator.sh /data/local/tmp
|
adb push native/out/x86/busybox scripts/emulator.sh /data/local/tmp
|
||||||
|
emu_arch=`adb shell uname -m`
|
||||||
|
if [ $emu_arch = "x86_64" ]; then
|
||||||
|
adb push native/out/x86/magiskinit64 /data/local/tmp/magiskinit
|
||||||
|
else
|
||||||
|
adb push native/out/x86/magiskinit /data/local/tmp
|
||||||
|
fi
|
||||||
adb root || abort 'adb root failed'
|
adb root || abort 'adb root failed'
|
||||||
adb shell sh /data/local/tmp/emulator.sh
|
adb shell sh /data/local/tmp/emulator.sh
|
||||||
exit 0
|
exit 0
|
||||||
@ -36,15 +43,14 @@ fi
|
|||||||
|
|
||||||
cd /data/local/tmp
|
cd /data/local/tmp
|
||||||
chmod 777 busybox
|
chmod 777 busybox
|
||||||
|
chmod 777 magiskinit
|
||||||
# Currently only support rootfs based emulators
|
|
||||||
./busybox mount | ./busybox grep -q rootfs || abort 'Only support non system-as-root emulators'
|
|
||||||
|
|
||||||
# Emulator's adb shell should have root
|
# Emulator's adb shell should have root
|
||||||
[ `./busybox id -u` -eq 0 ] || abort 'ADB shell should have root access'
|
[ `./busybox id -u` -eq 0 ] || abort 'ADB shell should have root access'
|
||||||
|
|
||||||
# Check whether already setup
|
# Check whether already setup
|
||||||
[ -f /sbin/magisk ] && abort "Magisk is already setup"
|
[ -f /sbin/magisk ] && abort "Magisk is already setup"
|
||||||
|
./busybox pgrep magiskd && abort "Magisk is already setup"
|
||||||
|
|
||||||
# First setup a good env to work with
|
# First setup a good env to work with
|
||||||
rm -rf bin
|
rm -rf bin
|
||||||
@ -53,27 +59,61 @@ rm -rf bin
|
|||||||
OLD_PATH="$PATH"
|
OLD_PATH="$PATH"
|
||||||
PATH="/data/local/tmp/bin:$PATH"
|
PATH="/data/local/tmp/bin:$PATH"
|
||||||
|
|
||||||
# Setup sbin mirror
|
# SELinux stuffs
|
||||||
mount -o rw,remount /
|
[ -e /sys/fs/selinux ] && SELINUX=true || SELINUX=false
|
||||||
rm -rf /root
|
if $SELINUX; then
|
||||||
mkdir /root
|
ln -sf ./magiskinit magiskpolicy
|
||||||
chmod 750 /root
|
./magiskpolicy --live --magisk 'allow magisk * * *'
|
||||||
ln /sbin/* /root
|
fi
|
||||||
mount -o ro,remount /
|
|
||||||
|
|
||||||
# Setup sbin overlay
|
# Setup sbin overlay
|
||||||
mount -t tmpfs tmpfs /sbin
|
if mount | grep -q rootfs; then
|
||||||
chmod 755 /sbin
|
mount -o rw,remount /
|
||||||
ln -s /root/* /sbin
|
rm -rf /root
|
||||||
cp ./magisk /sbin/magisk
|
mkdir /root
|
||||||
|
chmod 750 /root
|
||||||
|
ln /sbin/* /root
|
||||||
|
mount -o ro,remount /
|
||||||
|
mount_sbin
|
||||||
|
ln -s /root/* /sbin
|
||||||
|
else
|
||||||
|
mount_sbin
|
||||||
|
mkdir -p /sbin/.magisk/mirror/system_root
|
||||||
|
block=`mount | grep ' / ' | awk '{ print $1 }'`
|
||||||
|
[ $block = "/dev/root" ] && block=/dev/block/dm-0
|
||||||
|
mount -o ro $block /sbin/.magisk/mirror/system_root
|
||||||
|
for file in /sbin/.magisk/mirror/system_root/sbin/*; do
|
||||||
|
[ ! -e $file ] && break
|
||||||
|
if [ -L $file ]; then
|
||||||
|
cp -af $file /sbin
|
||||||
|
else
|
||||||
|
sfile=/sbin/`basename $file`
|
||||||
|
touch $sfile
|
||||||
|
mount -o bind $file $sfile
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Magisk stuffs
|
||||||
|
if [ -e /apex ]; then
|
||||||
|
./magiskinit -x magisk /sbin/magisk.bin
|
||||||
|
[ -e /system/lib64 ] && LIB=lib64 || LIB=lib
|
||||||
|
cat <<EOF > /sbin/magisk
|
||||||
|
#!/system/bin/sh
|
||||||
|
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:/apex/com.android.runtime/$LIB"
|
||||||
|
exec /sbin/magisk.bin "\$0" "\$@"
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
./magiskinit -x magisk /sbin/magisk
|
||||||
|
fi
|
||||||
chmod 755 /sbin/magisk
|
chmod 755 /sbin/magisk
|
||||||
ln -s ./magisk /sbin/su
|
ln -s ./magisk /sbin/su
|
||||||
|
ln -s ./magisk /sbin/resetprop
|
||||||
|
ln -s ./magisk /sbin/magiskhide
|
||||||
mkdir -p /sbin/.magisk/busybox
|
mkdir -p /sbin/.magisk/busybox
|
||||||
cp -af ./busybox /sbin/.magisk/busybox/busybox
|
cp -af ./busybox /sbin/.magisk/busybox/busybox
|
||||||
/sbin/.magisk/busybox/busybox --install -s /sbin/.magisk/busybox
|
/sbin/.magisk/busybox/busybox --install -s /sbin/.magisk/busybox
|
||||||
|
|
||||||
# Magisk stuffs
|
|
||||||
mkdir -p /data/adb/modules 2>/dev/null
|
mkdir -p /data/adb/modules 2>/dev/null
|
||||||
mkdir /data/adb/post-fs-data.d 2>/dev/null
|
mkdir /data/adb/post-fs-data.d 2>/dev/null
|
||||||
mkdir /data/adb/services.d 2>/dev/null
|
mkdir /data/adb/services.d 2>/dev/null
|
||||||
magisk --daemon
|
/sbin/magisk --daemon
|
||||||
|
Loading…
x
Reference in New Issue
Block a user