Various fixes

Fixes #13 and #17
This commit is contained in:
topjohnwu 2016-11-29 04:16:01 +08:00
parent 30c048723c
commit 670fe8590c
2 changed files with 44 additions and 36 deletions

View File

@ -19,6 +19,12 @@ INSTALLER=$TMPDIR/magisk
COREDIR=/magisk/.core
# Boot Image Variables
CHROMEDIR=$INSTALLER/chromeos
NEWBOOT=$TMPDIR/boottmp/new-boot.img
UNPACKDIR=$TMPDIR/boottmp/bootunpack
RAMDISK=$TMPDIR/boottmp/ramdisk
# Default permissions
umask 022
@ -86,7 +92,7 @@ find_boot_image() {
if [ -z "$BOOTIMAGE" ]; then
FSTAB="/etc/recovery.fstab"
[ ! -f "$FSTAB" ] && FSTAB="/etc/recovery.fstab.bak"
[ -f "$FSTAB" ] BOOTIMAGE=`grep -E '\b/boot\b' "$FSTAB" | grep -oE '/dev/[a-zA-Z0-9_./-]*'`
[ -f "$FSTAB" ] && BOOTIMAGE=`grep -E '\b/boot\b' "$FSTAB" | grep -oE '/dev/[a-zA-Z0-9_./-]*'`
fi
}
@ -112,7 +118,7 @@ mount_image() {
if (! is_mounted $2); then
LOOPDEVICE=/dev/block/loop$LOOP
if [ ! -f "$LOOPDEVICE" ]; then
mknod $LOOPDEVICE b 7 $LOOP
mknod $LOOPDEVICE b 7 $LOOP 2>/dev/null
fi
losetup $LOOPDEVICE $1
if [ "$?" -eq "0" ]; then
@ -148,7 +154,7 @@ unpack_boot() {
mkdir -p $UNPACKDIR
mkdir -p $RAMDISK
cd $UNPACKDIR
$BINDIR/bootimgtools --extract $1
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --extract $1
cd $RAMDISK
gunzip -c < $UNPACKDIR/ramdisk.gz | cpio -i
@ -158,11 +164,11 @@ repack_boot() {
cd $RAMDISK
find . | cpio -o -H newc 2>/dev/null | gzip -9 > $UNPACKDIR/ramdisk.gz
cd $UNPACKDIR
$BINDIR/bootimgtools --repack $ORIGBOOT
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --repack $ORIGBOOT
if [ -f chromeos ]; then
echo " " > config
echo " " > bootloader
$CHROMEDIR/futility vbutil_kernel --pack new-boot.img.signed --keyblock $CHROMEDIR/kernel.keyblock --signprivate $CHROMEDIR/kernel_data_key.vbprivk --version 1 --vmlinuz new-boot.img --config config --arch arm --bootloader bootloader --flags 0x1
LD_LIBRARY_PATH=$SYSTEMLIB $CHROMEDIR/futility vbutil_kernel --pack new-boot.img.signed --keyblock $CHROMEDIR/kernel.keyblock --signprivate $CHROMEDIR/kernel_data_key.vbprivk --version 1 --vmlinuz new-boot.img --config config --arch arm --bootloader bootloader --flags 0x1
rm -f new-boot.img
mv new-boot.img.signed new-boot.img
fi
@ -173,7 +179,7 @@ repack_boot() {
fi
fi
mv new-boot.img $NEWBOOT
$BINDIR/bootimgtools --hexpatch $NEWBOOT \
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --hexpatch $NEWBOOT \
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
}
@ -251,6 +257,9 @@ ui_print "- Device platform: $ARCH"
BINDIR=$INSTALLER/$ARCH
chmod -R 755 $CHROMEDIR/futility $BINDIR
SYSTEMLIB=/system/lib
($IS64BIT) && SYSTEMLIB=/system/lib64
find_boot_image
if [ -z "$BOOTIMAGE" ]; then
ui_print "! Unable to detect boot image"
@ -277,7 +286,6 @@ if (is_mounted /data); then
PATH=/data/busybox:$PATH
else
rm -rf /cache/data_bin 2>/dev/null
mkdir -p /cache/data_bin
cp -af $BINDIR /cache/data_bin
cp -af $INSTALLER/common/init.magisk.rc $INSTALLER/common/magic_mask.sh /cache/data_bin
fi
@ -322,11 +330,6 @@ ui_print "- Found Boot Image: $BOOTIMAGE"
rm -rf $TMPDIR/boottmp 2>/dev/null
mkdir -p $TMPDIR/boottmp
CHROMEDIR=$INSTALLER/chromeos
NEWBOOT=$TMPDIR/boottmp/new-boot.img
UNPACKDIR=$TMPDIR/boottmp/bootunpack
RAMDISK=$TMPDIR/boottmp/ramdisk
ORIGBOOT=$BOOTIMAGE
ui_print "- Unpacking boot image"
@ -407,7 +410,7 @@ if (! $SUPERSU); then
fi
# sepolicy patches
$BINDIR/sepolicy-inject --magisk -P sepolicy
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/sepolicy-inject --magisk -P sepolicy
# Add new items
mkdir -p magisk 2>/dev/null
@ -420,7 +423,7 @@ chmod 0750 init.magisk.rc sbin/magic_mask.sh
ui_print "- Repacking boot image"
repack_boot
BOOTSIZE=`blockdev --getsize64 $BOOTIMAGE`
BOOTSIZE=`blockdev --getsize64 $BOOTIMAGE 2>/dev/null`
NEWSIZE=`ls -l $NEWBOOT | awk '{print $5}'`
if [ "$NEWSIZE" -gt "$BOOTSIZE" ]; then
ui_print "! Boot partition space insufficient"

View File

@ -16,8 +16,9 @@ MOUNTINFO=$TMPDIR/mnt
# e.g. we rely on the option "-c" for cp (reserve contexts), and -exec for find
TOOLPATH=/data/busybox
BINPATH=/data/magisk
OLDPATH=$PATH
PATH=$TOOLPATH:$OLDPATH
export OLDPATH=$PATH
export PATH=$TOOLPATH:$OLDPATH
# Default permissions
umask 022
@ -44,7 +45,6 @@ unblock() {
}
run_scripts() {
PATH=$OLDPATH
BASE=$MOUNTPOINT
for MOD in $BASE/* ; do
if [ ! -f "$MOD/disable" ]; then
@ -56,7 +56,6 @@ run_scripts() {
fi
fi
done
PATH=$TOOLPATH:$OLDPATH
}
loopsetup() {
@ -124,20 +123,26 @@ travel() {
clone_dummy() {
for ITEM in "$1/"* ; do
if [ -d "$DUMMDIR$ITEM" ]; then
(clone_dummy "$ITEM")
elif [ ! -e "$DUMMDIR$ITEM" ]; then
if [ -d "$ITEM" ]; then
# Create dummy directory
mkdir -p "$DUMMDIR$ITEM"
elif [ -L "$ITEM" ]; then
# Symlinks are small, copy them
cp -afc "$ITEM" "$DUMMDIR$ITEM"
if [ ! -e "$DUMMDIR$ITEM" ]; then
if [ ! -d "$MOUNTINFO$ITEM" ]; then
if [ -d "$ITEM" ]; then
# Create dummy directory
mkdir -p "$DUMMDIR$ITEM"
elif [ -L "$ITEM" ]; then
# Symlinks are small, copy them
cp -afc "$ITEM" "$DUMMDIR$ITEM"
else
# Create dummy file
mktouch "$DUMMDIR$ITEM"
fi
chcon -f "u:object_r:system_file:s0" "$DUMMDIR$ITEM"
else
# Create dummy file
mktouch "$DUMMDIR$ITEM"
# Need to clone a skeleton
(clone_dummy "$ITEM")
fi
chcon -f "u:object_r:system_file:s0" "$DUMMDIR$ITEM"
elif [ -d "$DUMMDIR$ITEM" ]; then
# Need to clone a skeleton
(clone_dummy "$ITEM")
fi
done
}
@ -270,12 +275,6 @@ case $1 in
log_print "** Magisk post-fs-data mode running..."
# Live patch sepolicy
$BINPATH/sepolicy-inject --live -s su
# Multirom functions should go here, not available right now
MULTIROM=false
# Cache support
if [ -d "/cache/data_bin" ]; then
rm -rf $BINPATH $TOOLPATH
@ -294,6 +293,12 @@ case $1 in
find $TOOLPATH -exec chcon -h "u:object_r:system_file:s0" {} \;
chmod -R 755 $BINPATH $TOOLPATH
# Live patch sepolicy
$BINPATH/sepolicy-inject --live -s su
# Multirom functions should go here, not available right now
MULTIROM=false
# Image merging
chmod 644 $IMG /cache/magisk.img /data/magisk_merge.img 2>/dev/null
merge_image /cache/magisk.img