2022-01-19 05:12:11 -08:00
|
|
|
#####################################################################
|
|
|
|
# AVD MagiskInit Setup
|
|
|
|
#####################################################################
|
|
|
|
#
|
2023-03-17 20:08:31 +08:00
|
|
|
# Support API level: 23 - 33
|
2022-01-19 05:12:11 -08:00
|
|
|
#
|
|
|
|
# With an emulator booted and accessible via ADB, usage:
|
|
|
|
# ./build.py avd_patch path/to/booted/avd-image/ramdisk.img
|
|
|
|
#
|
|
|
|
# The purpose of this script is to patch AVD ramdisk.img and do a
|
|
|
|
# full integration test of magiskinit under several circumstances.
|
|
|
|
# After patching ramdisk.img, close the emulator, then select
|
|
|
|
# "Cold Boot Now" in AVD Manager to force a full reboot.
|
|
|
|
#
|
|
|
|
#####################################################################
|
|
|
|
# AVD Init Configurations:
|
|
|
|
#
|
|
|
|
# rootfs w/o early mount: API 23 - 25
|
|
|
|
# rootfs with early mount: API 26 - 27
|
|
|
|
# Legacy system-as-root: API 28
|
2022-08-02 03:37:04 -07:00
|
|
|
# 2 stage init: API 29 - 33
|
2022-01-19 05:12:11 -08:00
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
if [ ! -f /system/build.prop ]; then
|
|
|
|
# Running on PC
|
|
|
|
echo 'Please run `./build.py avd_patch` instead of directly executing the script!'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd /data/local/tmp
|
|
|
|
chmod 755 busybox
|
|
|
|
|
|
|
|
if [ -z "$FIRST_STAGE" ]; then
|
|
|
|
export FIRST_STAGE=1
|
|
|
|
export ASH_STANDALONE=1
|
|
|
|
# Re-exec script with busybox
|
|
|
|
exec ./busybox sh $0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract files from APK
|
2022-10-31 22:31:15 +08:00
|
|
|
unzip -oj magisk.apk 'assets/util_functions.sh' 'assets/stub.apk'
|
2022-01-19 05:12:11 -08:00
|
|
|
. ./util_functions.sh
|
|
|
|
|
|
|
|
api_level_arch_detect
|
|
|
|
|
2022-08-02 03:37:04 -07:00
|
|
|
unzip -oj magisk.apk "lib/$ABI/*" "lib/$ABI32/libmagisk32.so" -x "lib/$ABI/libbusybox.so"
|
2022-01-19 05:12:11 -08:00
|
|
|
for file in lib*.so; do
|
|
|
|
chmod 755 $file
|
|
|
|
mv "$file" "${file:3:${#file}-6}"
|
|
|
|
done
|
|
|
|
|
2022-02-11 04:34:26 +08:00
|
|
|
./magiskboot decompress ramdisk.cpio.tmp ramdisk.cpio
|
2022-01-19 05:12:11 -08:00
|
|
|
cp ramdisk.cpio ramdisk.cpio.orig
|
|
|
|
|
2023-04-25 04:54:46 +08:00
|
|
|
export KEEPVERITY=true
|
2023-03-08 14:42:54 +08:00
|
|
|
export KEEPFORCEENCRYPT=true
|
2023-02-12 16:36:38 +08:00
|
|
|
|
2023-03-08 14:42:54 +08:00
|
|
|
echo "KEEPVERITY=$KEEPVERITY" > config
|
|
|
|
echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
|
|
|
|
if [ -e "/system/bin/linker64" ]; then
|
2023-03-16 04:07:00 -07:00
|
|
|
echo "PREINITDEVICE=$(./magisk64 --preinit-device)" >> config
|
2023-03-08 14:42:54 +08:00
|
|
|
else
|
2023-03-16 04:07:00 -07:00
|
|
|
echo "PREINITDEVICE=$(./magisk32 --preinit-device)" >> config
|
2023-03-08 14:42:54 +08:00
|
|
|
fi
|
2022-01-19 05:12:11 -08:00
|
|
|
# For API 28, we also patch advancedFeatures.ini to disable SAR
|
|
|
|
# Manually override skip_initramfs by setting RECOVERYMODE=true
|
|
|
|
[ $API = "28" ] && echo 'RECOVERYMODE=true' >> config
|
2023-03-08 06:52:09 +08:00
|
|
|
RANDOMSEED=$(tr -dc 'a-f0-9' < /dev/urandom | head -c 16)
|
|
|
|
echo "RANDOMSEED=0x$RANDOMSEED" >> config
|
2023-04-25 04:54:46 +08:00
|
|
|
cat config
|
2022-01-19 05:12:11 -08:00
|
|
|
|
2023-05-23 18:12:06 -07:00
|
|
|
SKIP32="#"
|
|
|
|
SKIP64="#"
|
|
|
|
if [ -f magisk64 ]; then
|
|
|
|
./magiskboot compress=xz magisk64 magisk64.xz
|
|
|
|
unset SKIP64
|
|
|
|
fi
|
|
|
|
if [ -f magisk32 ]; then
|
|
|
|
./magiskboot compress=xz magisk32 magisk32.xz
|
|
|
|
unset SKIP32
|
|
|
|
fi
|
2022-10-31 22:31:15 +08:00
|
|
|
./magiskboot compress=xz stub.apk stub.xz
|
2022-01-19 05:12:11 -08:00
|
|
|
|
|
|
|
./magiskboot cpio ramdisk.cpio \
|
|
|
|
"add 0750 init magiskinit" \
|
|
|
|
"mkdir 0750 overlay.d" \
|
|
|
|
"mkdir 0750 overlay.d/sbin" \
|
2023-05-23 18:12:06 -07:00
|
|
|
"$SKIP32 add 0644 overlay.d/sbin/magisk32.xz magisk32.xz" \
|
|
|
|
"$SKIP64 add 0644 overlay.d/sbin/magisk64.xz magisk64.xz" \
|
2022-10-31 22:31:15 +08:00
|
|
|
"add 0644 overlay.d/sbin/stub.xz stub.xz" \
|
2022-01-19 05:12:11 -08:00
|
|
|
"patch" \
|
|
|
|
"backup ramdisk.cpio.orig" \
|
|
|
|
"mkdir 000 .backup" \
|
|
|
|
"add 000 .backup/.magisk config"
|
|
|
|
|
2022-10-31 22:31:15 +08:00
|
|
|
rm -f ramdisk.cpio.orig config magisk*.xz stub.xz
|
2022-02-11 04:34:26 +08:00
|
|
|
./magiskboot compress=gzip ramdisk.cpio ramdisk.cpio.gz
|