mirror of
https://github.com/topjohnwu/Magisk
synced 2024-11-13 20:54:12 +01:00
Fix SuperSU installation
This commit is contained in:
parent
0a0eb3f710
commit
d274e45587
@ -102,7 +102,7 @@ EXIT /B %ERRORLEVEL%
|
||||
ECHO ************************
|
||||
ECHO * Copying Files
|
||||
ECHO ************************
|
||||
COPY /Y scripts\ramdisk_patch.sh zip_static\common\ramdisk_patch.sh
|
||||
COPY /Y scripts\custom_ramdisk_patch.sh zip_static\common\custom_ramdisk_patch.sh
|
||||
COPY /Y scripts\init.magisk.rc zip_static\common\init.magisk.rc
|
||||
COPY /Y binaries\busybox-arm zip_static\arm\busybox
|
||||
COPY /Y binaries\busybox-arm64 zip_static\arm64\busybox
|
||||
|
2
build.sh
2
build.sh
@ -75,7 +75,7 @@ zip_package() {
|
||||
echo "************************"
|
||||
echo "* Copying files"
|
||||
echo "************************"
|
||||
cp -afv scripts/ramdisk_patch.sh zip_static/common/ramdisk_patch.sh
|
||||
cp -afv scripts/custom_ramdisk_patch.sh zip_static/common/custom_ramdisk_patch.sh
|
||||
cp -afv scripts/init.magisk.rc zip_static/common/init.magisk.rc
|
||||
cp -afv binaries/busybox-arm zip_static/arm/busybox
|
||||
cp -afv binaries/busybox-arm64 zip_static/arm64/busybox
|
||||
|
@ -195,18 +195,19 @@ static void cpio_add(mode_t mode, const char *entry, const char *filename, vecto
|
||||
}
|
||||
|
||||
static void cpio_test(vector *v) {
|
||||
#define MAGISK_PATCH 0x1
|
||||
#define SUPERSU_PATCH 0x2
|
||||
int ret = 0;
|
||||
cpio_file *f;
|
||||
vec_for_each(v, f) {
|
||||
if (strcmp(f->filename, "sbin/launch_daemonsu.sh") == 0) {
|
||||
if (!ret) ret = 2;
|
||||
ret |= SUPERSU_PATCH;
|
||||
} else if (strcmp(f->filename, "init.magisk.rc") == 0) {
|
||||
ret = 1;
|
||||
break;
|
||||
ret |= MAGISK_PATCH;
|
||||
}
|
||||
}
|
||||
cpio_vec_destroy(v);
|
||||
exit(ret);
|
||||
exit((ret & SUPERSU_PATCH) ? SUPERSU_PATCH : (ret & MAGISK_PATCH));
|
||||
}
|
||||
|
||||
static int check_verity_pattern(const char *s) {
|
||||
|
57
scripts/custom_ramdisk_patch.sh
Normal file
57
scripts/custom_ramdisk_patch.sh
Normal file
@ -0,0 +1,57 @@
|
||||
#!/system/bin/sh
|
||||
|
||||
RAMDISK=$1
|
||||
|
||||
TMPDIR=/dev/tmp
|
||||
MAGISKBIN=/data/magisk
|
||||
[ ! -e $MAGISKBIN ] && MAGISKBIN=/cache/data_bin
|
||||
[ ! -e $MAGISKBIN ] && exit 1
|
||||
SYSTEMLIB=/system/lib
|
||||
[ -d /system/lib64 ] && SYSTEMLIB=/system/lib64
|
||||
|
||||
mkdir -p $TMPDIR 2>/dev/null
|
||||
cd $TMPDIR
|
||||
|
||||
cpio_add() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-add $RAMDISK $RAMDISK $1 $2 $3
|
||||
}
|
||||
|
||||
cpio_extract() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-extract $RAMDISK $1 $2
|
||||
}
|
||||
|
||||
cpio_mkdir() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-mkdir $RAMDISK $RAMDISK $1 $2
|
||||
}
|
||||
|
||||
# Recursive
|
||||
cpio_rm() {
|
||||
if [ "$1" = "-r" ]; then
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-ls $RAMDISK | grep "^$2/" | while read i ; do
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-rm $RAMDISK $RAMDISK $i
|
||||
done
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-rmdir $RAMDISK $RAMDISK $2
|
||||
else
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-rm $RAMDISK $RAMDISK $1
|
||||
fi
|
||||
}
|
||||
|
||||
# Cleanup SuperSU backups
|
||||
cpio_rm -r .subackup
|
||||
|
||||
# Add magisk entrypoint
|
||||
cpio_extract init.rc init.rc
|
||||
grep "import /init.magisk.rc" init.rc >/dev/null || sed -i '1,/.*import.*/s/.*import.*/import \/init.magisk.rc\n&/' init.rc
|
||||
sed -i "/selinux.reload_policy/d" init.rc
|
||||
cpio_add 750 init.rc init.rc
|
||||
|
||||
# sepolicy patches
|
||||
cpio_extract sepolicy sepolicy
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskpolicy --load sepolicy --save sepolicy --minimal
|
||||
cpio_add 644 sepolicy sepolicy
|
||||
|
||||
# Add new items
|
||||
cpio_mkdir 755 magisk
|
||||
cpio_add 750 init.magisk.rc $MAGISKBIN/init.magisk.rc
|
||||
cpio_add 750 sbin/magic_mask.sh $MAGISKBIN/magic_mask.sh
|
||||
|
@ -171,6 +171,21 @@ remove_system_su() {
|
||||
fi
|
||||
}
|
||||
|
||||
# --cpio-add <incpio> <mode> <entry> <infile>
|
||||
cpio_add() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-add ramdisk.cpio $1 $2 $3
|
||||
}
|
||||
|
||||
# --cpio-extract <incpio> <entry> <outfile>
|
||||
cpio_extract() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-extract ramdisk.cpio $1 $2
|
||||
}
|
||||
|
||||
# --cpio-mkdir <incpio> <mode> <entry>
|
||||
cpio_mkdir() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-mkdir ramdisk.cpio $1 $2
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# Detection
|
||||
##########################################################################################
|
||||
@ -249,7 +264,7 @@ is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
|
||||
rm -rf $MAGISKBIN 2>/dev/null
|
||||
mkdir -p $MAGISKBIN
|
||||
cp -af $BINDIR/busybox $BINDIR/magiskboot $BINDIR/magiskpolicy $COMMONDIR/magisk.apk \
|
||||
$COMMONDIR/init.magisk.rc $COMMONDIR/ramdisk_patch.sh $COMMONDIR/magic_mask.sh $MAGISKBIN
|
||||
$COMMONDIR/init.magisk.rc $COMMONDIR/custom_ramdisk_patch.sh $COMMONDIR/magic_mask.sh $MAGISKBIN
|
||||
# Legacy support
|
||||
ln -sf /data/magisk/magiskpolicy $MAGISKBIN/sepolicy-inject
|
||||
|
||||
@ -372,8 +387,9 @@ case $? in
|
||||
2 ) # SuperSU patched
|
||||
SUPERSU=true
|
||||
ui_print "- SuperSU patched boot detected!"
|
||||
ui_print "- Adding auto patch script for SuperSU"
|
||||
cp -af $COMMONDIR/ramdisk_patch.sh /data/custom_ramdisk_patch.sh
|
||||
ui_print "- Adding ramdisk patch script for SuperSU"
|
||||
cp -af $COMMONDIR/custom_ramdisk_patch.sh /data/custom_ramdisk_patch.sh
|
||||
ui_print "- We are using SuperSU's own tools, mounting su.img"
|
||||
is_mounted /data && SUIMG=/data/su.img || SUIMG=/cache/su.img
|
||||
mount_image $SUIMG /su
|
||||
SUPERSULOOP=$LOOPDEVICE
|
||||
@ -390,21 +406,15 @@ case $? in
|
||||
rm stock_boot.img
|
||||
else
|
||||
ui_print "! Cannot find stock boot image backup"
|
||||
ui_print "! Will still try to complete installation"
|
||||
# Since no backup at all, let's try our best...
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-restore ramdisk.cpio
|
||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
ui_print "! SuperSU image mount failed..."
|
||||
ui_print "! Will still try to complete installation"
|
||||
# Since we cannot rely on sukernel, do it outselves...
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-restore ramdisk.cpio
|
||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||
ui_print "! Magisk scripts are placed correctly"
|
||||
ui_print "! Flash SuperSU immediately to finish installation"
|
||||
exit 1
|
||||
fi
|
||||
# Remove SuperSU backups, since we are recreating it
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-rm ramdisk.cpio -r .subackup
|
||||
;;
|
||||
esac
|
||||
|
||||
@ -414,13 +424,39 @@ esac
|
||||
|
||||
# All ramdisk patch commands are stored in a separate script
|
||||
ui_print "- Patching ramdisk"
|
||||
source $COMMONDIR/ramdisk_patch.sh $BOOTTMP/ramdisk.cpio
|
||||
|
||||
cd $BOOTTMP
|
||||
# Create ramdisk backups
|
||||
if $SUPERSU; then
|
||||
[ -f /su/bin/sukernel ] && LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-backup ramdisk.cpio.orig ramdisk.cpio ramdisk.cpio
|
||||
# Use sukernel to patch ramdisk, so we can use its own tools to backup
|
||||
sh $COMMONDIR/custom_ramdisk_patch.sh $BOOTTMP/ramdisk.cpio
|
||||
|
||||
# Create ramdisk backups
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB /su/bin/sukernel --cpio-backup ramdisk.cpio.orig ramdisk.cpio ramdisk.cpio
|
||||
|
||||
else
|
||||
# The common patches
|
||||
$KEEPVERITY || LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-patch-dmverity ramdisk.cpio
|
||||
$KEEPFORCEENCRYPT || LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-patch-forceencrypt ramdisk.cpio
|
||||
|
||||
# Add magisk entrypoint
|
||||
cpio_extract init.rc init.rc
|
||||
grep "import /init.magisk.rc" init.rc >/dev/null || sed -i '1,/.*import.*/s/.*import.*/import \/init.magisk.rc\n&/' init.rc
|
||||
sed -i "/selinux.reload_policy/d" init.rc
|
||||
cpio_add 750 init.rc init.rc
|
||||
|
||||
# sepolicy patches
|
||||
cpio_extract sepolicy sepolicy
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskpolicy --load sepolicy --save sepolicy --minimal
|
||||
cpio_add 644 sepolicy sepolicy
|
||||
|
||||
# Add new items
|
||||
cpio_mkdir 755 magisk
|
||||
|
||||
[ ! -z $SHA1 ] && echo "# STOCKSHA1=$SHA1" >> $COMMONDIR/init.magisk.rc
|
||||
cpio_add 750 init.magisk.rc $COMMONDIR/init.magisk.rc
|
||||
|
||||
cpio_add 750 sbin/magic_mask.sh $COMMONDIR/magic_mask.sh
|
||||
|
||||
# Create ramdisk backups
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --cpio-backup ramdisk.cpio ramdisk.cpio.orig
|
||||
fi
|
||||
|
||||
|
@ -1,57 +0,0 @@
|
||||
# This file will be sourced by Magisk patch zip, so all variables in the main script should be present
|
||||
# However, this file may also be called by SuperSU, so we still have to find our own variables in this case
|
||||
|
||||
RAMDISK=$1
|
||||
|
||||
if [ -z $MAGISK ]; then
|
||||
TMPDIR=/dev/tmp
|
||||
MAGISKBIN=/data/magisk
|
||||
[ ! -e $MAGISKBIN ] && MAGISKBIN=/cache/data_bin
|
||||
[ ! -e $MAGISKBIN ] && exit 1
|
||||
SYSTEMLIB=/system/lib
|
||||
[ -d /system/lib64 ] && SYSTEMLIB=/system/lib64
|
||||
KEEPVERITY=true
|
||||
KEEPFORCEENCRYPT=true
|
||||
fi
|
||||
|
||||
cd $TMPDIR
|
||||
|
||||
# --cpio-add <incpio> <mode> <entry> <infile>
|
||||
cpio_add() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-add $RAMDISK $1 $2 $3
|
||||
}
|
||||
|
||||
# --cpio-extract <incpio> <entry> <outfile>
|
||||
cpio_extract() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-extract $RAMDISK $1 $2
|
||||
}
|
||||
|
||||
# --cpio-mkdir <incpio> <mode> <entry>
|
||||
cpio_mkdir() {
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-mkdir $RAMDISK $1 $2
|
||||
}
|
||||
|
||||
# The common patches
|
||||
$KEEPVERITY || LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-patch-dmverity $RAMDISK
|
||||
$KEEPFORCEENCRYPT || LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskboot --cpio-patch-forceencrypt $RAMDISK
|
||||
|
||||
# Add magisk entrypoint
|
||||
cpio_extract init.rc init.rc
|
||||
grep "import /init.magisk.rc" init.rc >/dev/null || sed -i '1,/.*import.*/s/.*import.*/import \/init.magisk.rc\n&/' init.rc
|
||||
sed -i "/selinux.reload_policy/d" init.rc
|
||||
cpio_add 750 init.rc init.rc
|
||||
|
||||
# sepolicy patches
|
||||
cpio_extract sepolicy sepolicy
|
||||
LD_LIBRARY_PATH=$SYSTEMLIB $MAGISKBIN/magiskpolicy --load sepolicy --save sepolicy --minimal
|
||||
cpio_add 644 sepolicy sepolicy
|
||||
|
||||
# Add new items
|
||||
|
||||
cpio_mkdir 755 magisk
|
||||
|
||||
cp -af $MAGISKBIN/init.magisk.rc init.magisk.rc
|
||||
[ ! -z $SHA1 ] && echo "# STOCKSHA1=$SHA1" >> init.magisk.rc
|
||||
cpio_add 750 init.magisk.rc init.magisk.rc
|
||||
|
||||
cpio_add 750 sbin/magic_mask.sh $MAGISKBIN/magic_mask.sh
|
Loading…
Reference in New Issue
Block a user