Magic Mount Total Re-factor Part 2
1. It seems that many part of the system is upset about symlinks, revert to bind mounts 2. New system and vendor mirror implementation found, no need to copy anything 3. Thanks to the new mirror implementation, adding new items to /system and /vendor is now possible 4. Re-written some coding style
This commit is contained in:
parent
c07e9ac29d
commit
1e3586621b
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,7 +11,7 @@ uninstaller/arm/*
|
|||||||
uninstaller/arm64/*
|
uninstaller/arm64/*
|
||||||
uninstaller/x86/*
|
uninstaller/x86/*
|
||||||
uninstaller/x64/*
|
uninstaller/x64/*
|
||||||
zipsigntools/zipadjust
|
ziptools/zipadjust
|
||||||
|
|
||||||
# Generated scripts
|
# Generated scripts
|
||||||
zip_static/common/magic_mask.sh
|
zip_static/common/magic_mask.sh
|
||||||
|
@ -47,8 +47,8 @@ unblock() {
|
|||||||
run_scripts() {
|
run_scripts() {
|
||||||
BASE=$MOUNTPOINT
|
BASE=$MOUNTPOINT
|
||||||
for MOD in $BASE/* ; do
|
for MOD in $BASE/* ; do
|
||||||
if [ ! -f "$MOD/disable" ]; then
|
if [ ! -f $MOD/disable ]; then
|
||||||
if [ -f "$MOD/$1.sh" ]; then
|
if [ -f $MOD/$1.sh ]; then
|
||||||
chmod 755 $MOD/$1.sh
|
chmod 755 $MOD/$1.sh
|
||||||
chcon "u:object_r:system_file:s0" "$MOD/$1.sh"
|
chcon "u:object_r:system_file:s0" "$MOD/$1.sh"
|
||||||
log_print "$1: $MOD/$1.sh"
|
log_print "$1: $MOD/$1.sh"
|
||||||
@ -60,8 +60,8 @@ run_scripts() {
|
|||||||
|
|
||||||
loopsetup() {
|
loopsetup() {
|
||||||
LOOPDEVICE=
|
LOOPDEVICE=
|
||||||
for DEV in $(ls /dev/block/loop*); do
|
for DEV in `ls /dev/block/loop*`; do
|
||||||
if [ `losetup $DEV $1 >/dev/null 2>&1; echo $?` -eq 0 ]; then
|
if losetup $DEV $1; then
|
||||||
LOOPDEVICE=$DEV
|
LOOPDEVICE=$DEV
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@ -77,44 +77,39 @@ target_size_check() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
travel() {
|
travel() {
|
||||||
cd "$TRAVEL_ROOT/$1"
|
cd $TRAVEL_ROOT/$1
|
||||||
if [ -f ".replace" ]; then
|
if [ -f .replace ]; then
|
||||||
rm -rf "$MOUNTINFO/$1"
|
rm -rf $MOUNTINFO/$1
|
||||||
mktouch "$MOUNTINFO/$1" "$TRAVEL_ROOT"
|
mktouch $MOUNTINFO/$1 $TRAVEL_ROOT
|
||||||
else
|
else
|
||||||
for ITEM in * ; do
|
for ITEM in * ; do
|
||||||
if [ ! -e "/$1/$ITEM" ]; then
|
if [ ! -e /$1/$ITEM ]; then
|
||||||
# New item found
|
# New item found
|
||||||
if [ "$1" = "system" ]; then
|
# If we are in a higher level, delete the lower levels
|
||||||
# We cannot add new items to /system root, delete it
|
rm -rf $MOUNTINFO/dummy/$1
|
||||||
rm -rf "$ITEM"
|
# Mount the dummy parent
|
||||||
else
|
mktouch $MOUNTINFO/dummy/$1
|
||||||
# If we are in a higher level, delete the lower levels
|
|
||||||
rm -rf "$MOUNTINFO/dummy/$1"
|
|
||||||
# Mount the dummy parent
|
|
||||||
mktouch "$MOUNTINFO/dummy/$1"
|
|
||||||
|
|
||||||
if [ -d "$ITEM" ]; then
|
if [ -d $ITEM ]; then
|
||||||
# Create new dummy directory and mount it
|
# Create new dummy directory and mount it
|
||||||
mkdir -p "$DUMMDIR/$1/$ITEM"
|
mkdir -p $DUMMDIR/$1/$ITEM
|
||||||
mktouch "$MOUNTINFO/$1/$ITEM" "$TRAVEL_ROOT"
|
mktouch $MOUNTINFO/$1/$ITEM $TRAVEL_ROOT
|
||||||
elif [ -L "$ITEM" ]; then
|
elif [ -L $ITEM ]; then
|
||||||
# Symlinks are small, copy them
|
# Symlinks are small, copy them
|
||||||
mkdir -p "$DUMMDIR/$1" 2>/dev/null
|
mkdir -p $DUMMDIR/$1 2>/dev/null
|
||||||
cp -afc "$ITEM" "$DUMMDIR/$1/$ITEM"
|
cp -afc $ITEM $DUMMDIR/$1/$ITEM
|
||||||
else
|
else
|
||||||
# Create new dummy file and mount it
|
# Create new dummy file and mount it
|
||||||
mktouch "$DUMMDIR/$1/$ITEM"
|
mktouch $DUMMDIR/$1/$ITEM
|
||||||
mktouch "$MOUNTINFO/$1/$ITEM" "$TRAVEL_ROOT"
|
mktouch $MOUNTINFO/$1/$ITEM $TRAVEL_ROOT
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -d "$ITEM" ]; then
|
if [ -d $ITEM ]; then
|
||||||
# It's an directory, travel deeper
|
# It's an directory, travel deeper
|
||||||
(travel "$1/$ITEM")
|
(travel $1/$ITEM)
|
||||||
elif [ ! -L "$ITEM" ]; then
|
elif [ ! -L $ITEM ]; then
|
||||||
# Mount this file
|
# Mount this file
|
||||||
mktouch "$MOUNTINFO/$1/$ITEM" "$TRAVEL_ROOT"
|
mktouch $MOUNTINFO/$1/$ITEM $TRAVEL_ROOT
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -122,55 +117,33 @@ travel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clone_dummy() {
|
clone_dummy() {
|
||||||
for ITEM in $1/* ; do
|
for ITEM in $MIRRDIR$1/* ; do
|
||||||
if [ ! -e "$TRAVEL_ROOT$ITEM" ]; then
|
REAL=${ITEM#$MIRRDIR}
|
||||||
if [ ! -d "$MOUNTINFO$ITEM" ]; then
|
if [ ! -e $MOUNTINFO$REAL ]; then
|
||||||
if [ -L "$ITEM" ]; then
|
if [ -L $ITEM ]; then
|
||||||
# Copy original symlink
|
# Copy original symlink
|
||||||
cp -afc "$ITEM" "$TRAVEL_ROOT$ITEM"
|
cp -afc $ITEM $DUMMDIR$REAL
|
||||||
else
|
|
||||||
# Link to mirror item
|
|
||||||
ln -s "$MIRRDIR$ITEM" "$TRAVEL_ROOT$ITEM"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# Need to clone a skeleton
|
if [ -d $ITEM ]; then
|
||||||
(clone_dummy "$ITEM")
|
mkdir -p $DUMMDIR$REAL
|
||||||
|
else
|
||||||
|
mktouch $DUMMDIR$REAL
|
||||||
|
fi
|
||||||
|
# Mount the mirror
|
||||||
|
mktouch $MOUNTINFO/mirror$REAL
|
||||||
fi
|
fi
|
||||||
elif [ -d "$TRAVEL_ROOT$ITEM" ]; then
|
elif [ -d $MOUNTINFO$REAL ]; then
|
||||||
# Need to clone a skeleton
|
# Need to clone deeper
|
||||||
(clone_dummy "$ITEM")
|
mkdir -p $DUMMDIR$REAL
|
||||||
|
(clone_dummy $REAL)
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
make_copy_image() {
|
|
||||||
TARGETSIZE=$2
|
|
||||||
if [ -z $TARGETSIZE ]; then
|
|
||||||
TARGETSIZE=`du -s $1 | awk '{print $1}'`
|
|
||||||
TARGETSIZE=$((($TARGETSIZE / 10240 + 2) * 10240))
|
|
||||||
fi
|
|
||||||
TARGETIMG=/data/magisk/${1//\//_}.img
|
|
||||||
make_ext4fs -l ${TARGETSIZE}K -a $1 $TARGETIMG
|
|
||||||
loopsetup $TARGETIMG
|
|
||||||
mkdir -p $MIRRDIR/copy$1
|
|
||||||
mount -t ext4 -o rw,noatime $LOOPDEVICE $MIRRDIR/copy$1
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_copy_image() {
|
|
||||||
TARGETIMG=/data/magisk/${1//\//_}.img
|
|
||||||
umount $MIRRDIR/copy$1
|
|
||||||
rm -rf $MIRRDIR/copy
|
|
||||||
losetup -d $LOOPDEVICE 2>/dev/null
|
|
||||||
loopsetup $TARGETIMG
|
|
||||||
mount -t ext4 -o rw,noatime $LOOPDEVICE $1
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
bind_mount() {
|
bind_mount() {
|
||||||
if [ -e "$1" -a -e "$2" ]; then
|
if [ -e $1 -a -e $2 ]; then
|
||||||
mount -o bind $1 $2
|
mount -o bind $1 $2
|
||||||
if [ "$?" -eq "0" ]; then
|
if [ $? -eq 0 ]; then
|
||||||
log_print "Mount: $1"
|
log_print "Mount: $1"
|
||||||
else
|
else
|
||||||
log_print "Mount Fail: $1"
|
log_print "Mount Fail: $1"
|
||||||
@ -179,9 +152,9 @@ bind_mount() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
merge_image() {
|
merge_image() {
|
||||||
if [ -f "$1" ]; then
|
if [ -f $1 ]; then
|
||||||
log_print "$1 found"
|
log_print "$1 found"
|
||||||
if [ -f "$IMG" ]; then
|
if [ -f $IMG ]; then
|
||||||
log_print "$IMG found, attempt to merge"
|
log_print "$IMG found, attempt to merge"
|
||||||
|
|
||||||
# Handle large images
|
# Handle large images
|
||||||
@ -207,36 +180,29 @@ merge_image() {
|
|||||||
LOOPMERGE=$LOOPDEVICE
|
LOOPMERGE=$LOOPDEVICE
|
||||||
log_print "$LOOPMERGE $1"
|
log_print "$LOOPMERGE $1"
|
||||||
|
|
||||||
if [ ! -z "$LOOPDATA" ]; then
|
if [ ! -z $LOOPDATA -a ! -z $LOOPMERGE ]; then
|
||||||
if [ ! -z "$LOOPMERGE" ]; then
|
# if loop devices have been setup, mount images
|
||||||
# if loop devices have been setup, mount images
|
OK=false
|
||||||
OK=true
|
mount -t ext4 -o rw,noatime $LOOPDATA /cache/data_img && \
|
||||||
|
mount -t ext4 -o rw,noatime $LOOPMERGE /cache/merge_img && \
|
||||||
|
OK=true
|
||||||
|
|
||||||
if [ `mount -t ext4 -o rw,noatime $LOOPDATA /cache/data_img >/dev/null 2>&1; echo $?` -ne 0 ]; then
|
if $OK; then
|
||||||
OK=false
|
# Merge (will reserve selinux contexts)
|
||||||
fi
|
cd /cache/merge_img
|
||||||
|
for MOD in *; do
|
||||||
if [ `mount -t ext4 -o rw,noatime $LOOPMERGE /cache/merge_img >/dev/null 2>&1; echo $?` -ne 0 ]; then
|
if [ "$MOD" != "lost+found" ]; then
|
||||||
OK=false
|
log_print "Merging: $MOD"
|
||||||
fi
|
rm -rf /cache/data_img/$MOD
|
||||||
|
fi
|
||||||
if $OK; then
|
done
|
||||||
# Merge (will reserve selinux contexts)
|
cp -afc . /cache/data_img
|
||||||
cd /cache/merge_img
|
log_print "Merge complete"
|
||||||
for MOD in *; do
|
cd /
|
||||||
if [ "$MOD" != "lost+found" ]; then
|
|
||||||
log_print "Merging: $MOD"
|
|
||||||
rm -rf /cache/data_img/$MOD
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
cp -afc . /cache/data_img
|
|
||||||
log_print "Merge complete"
|
|
||||||
cd /
|
|
||||||
fi
|
|
||||||
|
|
||||||
umount /cache/data_img
|
|
||||||
umount /cache/merge_img
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
umount /cache/data_img
|
||||||
|
umount /cache/merge_img
|
||||||
fi
|
fi
|
||||||
|
|
||||||
losetup -d $LOOPDATA
|
losetup -d $LOOPDATA
|
||||||
@ -263,16 +229,16 @@ case $1 in
|
|||||||
|
|
||||||
log_print "** Magisk post-fs mode running..."
|
log_print "** Magisk post-fs mode running..."
|
||||||
|
|
||||||
# Cleanup previous version stuffs...
|
# Cleanup legacy stuffs...
|
||||||
rm -rf /cache/magisk /cache/magisk_merge /cache/magiskhide.log
|
rm -rf /cache/magisk /cache/magisk_merge /cache/magiskhide.log
|
||||||
|
|
||||||
if [ -d "/cache/magisk_mount" ]; then
|
if [ -d /cache/magisk_mount ]; then
|
||||||
log_print "* Mounting cache files"
|
log_print "* Mounting cache files"
|
||||||
find /cache/magisk_mount -type f 2>/dev/null | while read ITEM ; do
|
find /cache/magisk_mount -type f 2>/dev/null | while read ITEM ; do
|
||||||
chmod 644 "$ITEM"
|
chmod 644 $ITEM
|
||||||
chcon "u:object_r:system_file:s0" "$ITEM"
|
chcon "u:object_r:system_file:s0" $ITEM
|
||||||
TARGET="${ITEM#/cache/magisk_mount}"
|
TARGET=${ITEM#/cache/magisk_mount}
|
||||||
bind_mount "$ITEM" "$TARGET"
|
bind_mount $ITEM $TARGET
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -280,15 +246,9 @@ case $1 in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
post-fs-data )
|
post-fs-data )
|
||||||
if [ `mount | grep " /data " >/dev/null 2>&1; echo $?` -ne 0 ]; then
|
# /data not mounted yet
|
||||||
# /data not mounted yet, we will be called again later
|
! mount | grep " /data " && unblock
|
||||||
unblock
|
mount | grep " /data " | grep "tmpfs" && unblock
|
||||||
fi
|
|
||||||
|
|
||||||
if [ `mount | grep " /data " | grep "tmpfs" >/dev/null 2>&1; echo $?` -eq 0 ]; then
|
|
||||||
# /data not mounted yet, we will be called again later
|
|
||||||
unblock
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Don't run twice
|
# Don't run twice
|
||||||
if [ "`getprop magisk.restart_pfsd`" != "1" ]; then
|
if [ "`getprop magisk.restart_pfsd`" != "1" ]; then
|
||||||
@ -326,32 +286,29 @@ case $1 in
|
|||||||
|
|
||||||
# Mount magisk.img
|
# Mount magisk.img
|
||||||
[ ! -d $MOUNTPOINT ] && mkdir -p $MOUNTPOINT
|
[ ! -d $MOUNTPOINT ] && mkdir -p $MOUNTPOINT
|
||||||
if [ `cat /proc/mounts | grep $MOUNTPOINT >/dev/null 2>&1; echo $?` -ne 0 ]; then
|
if ! mount | grep $MOUNTPOINT; then
|
||||||
loopsetup $IMG
|
loopsetup $IMG
|
||||||
if [ ! -z "$LOOPDEVICE" ]; then
|
[ ! -z $LOOPDEVICE ] && mount -t ext4 -o rw,noatime $LOOPDEVICE $MOUNTPOINT
|
||||||
mount -t ext4 -o rw,noatime $LOOPDEVICE $MOUNTPOINT
|
if [ $? -ne 0 ]; then
|
||||||
|
log_print "magisk.img mount failed, nothing to do :("
|
||||||
|
unblock
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ `cat /proc/mounts | grep $MOUNTPOINT >/dev/null 2>&1; echo $?` -ne 0 ]; then
|
|
||||||
log_print "magisk.img mount failed, nothing to do :("
|
|
||||||
unblock
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove empty directories, legacy paths, symlinks, old temporary images
|
# Remove empty directories, legacy paths, symlinks, old temporary images
|
||||||
find $MOUNTPOINT -type d -depth ! -path "*core*" -exec rmdir {} \; 2>/dev/null
|
find $MOUNTPOINT -type d -depth ! -path "*core*" -exec rmdir {} \; 2>/dev/null
|
||||||
rm -rf $COREDIR/bin $COREDIR/dummy $COREDIR/mirror /data/magisk/*.img
|
rm -rf $COREDIR/bin $COREDIR/dummy $COREDIR/mirror /data/magisk/*.img
|
||||||
|
|
||||||
# Remove modules that is labeled to be removed
|
# Remove modules that is labeled to be removed
|
||||||
for MOD in $MOUNTPOINT/* ; do
|
for MOD in $MOUNTPOINT/* ; do
|
||||||
if [ -f "$MOD/remove" ] || [ "$MOD" = "zzsupersu" ]; then
|
if [ -f $MOD/remove ] || [ $MOD = zzsupersu ]; then
|
||||||
log_print "Remove module: $MOD"
|
log_print "Remove module: $MOD"
|
||||||
rm -rf $MOD
|
rm -rf $MOD
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Unmount, shrink, remount
|
# Unmount, shrink, remount
|
||||||
if [ `umount $MOUNTPOINT >/dev/null 2>&1; echo $?` -eq 0 ]; then
|
if umount $MOUNTPOINT; then
|
||||||
losetup -d $LOOPDEVICE
|
losetup -d $LOOPDEVICE
|
||||||
target_size_check $IMG
|
target_size_check $IMG
|
||||||
NEWDATASIZE=$(((curUsedM / 32 + 2) * 32))
|
NEWDATASIZE=$(((curUsedM / 32 + 2) * 32))
|
||||||
@ -360,10 +317,8 @@ case $1 in
|
|||||||
resize2fs $IMG ${NEWDATASIZE}M
|
resize2fs $IMG ${NEWDATASIZE}M
|
||||||
fi
|
fi
|
||||||
loopsetup $IMG
|
loopsetup $IMG
|
||||||
if [ ! -z "$LOOPDEVICE" ]; then
|
[ ! -z $LOOPDEVICE ] && mount -t ext4 -o rw,noatime $LOOPDEVICE $MOUNTPOINT
|
||||||
mount -t ext4 -o rw,noatime $LOOPDEVICE $MOUNTPOINT
|
if [ $? -ne 0 ]; then
|
||||||
fi
|
|
||||||
if [ `cat /proc/mounts | grep $MOUNTPOINT >/dev/null 2>&1; echo $?` -ne 0 ]; then
|
|
||||||
log_print "magisk.img mount failed, nothing to do :("
|
log_print "magisk.img mount failed, nothing to do :("
|
||||||
unblock
|
unblock
|
||||||
fi
|
fi
|
||||||
@ -376,7 +331,7 @@ case $1 in
|
|||||||
|
|
||||||
# Travel through all mods
|
# Travel through all mods
|
||||||
for MOD in $MOUNTPOINT/* ; do
|
for MOD in $MOUNTPOINT/* ; do
|
||||||
if [ -f "$MOD/auto_mount" -a -d "$MOD/system" -a ! -f "$MOD/disable" ]; then
|
if [ -f $MOD/auto_mount -a -d $MOD/system -a ! -f $MOD/disable ]; then
|
||||||
TRAVEL_ROOT=$MOD
|
TRAVEL_ROOT=$MOD
|
||||||
(travel system)
|
(travel system)
|
||||||
fi
|
fi
|
||||||
@ -386,94 +341,18 @@ case $1 in
|
|||||||
find $TMPDIR -exec chcon -h "u:object_r:system_file:s0" {} \;
|
find $TMPDIR -exec chcon -h "u:object_r:system_file:s0" {} \;
|
||||||
|
|
||||||
# linker(64), t*box required for bin
|
# linker(64), t*box required for bin
|
||||||
if [ -f "$MOUNTINFO/dummy/system/bin" ]; then
|
if [ -f $MOUNTINFO/dummy/system/bin ]; then
|
||||||
cp -afc /system/bin/linker* /system/bin/t*box $DUMMDIR/system/bin/
|
cp -afc /system/bin/linker* /system/bin/t*box $DUMMDIR/system/bin/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BACKUPLIBS=false
|
DISABLEHIDE=false
|
||||||
|
|
||||||
# Libraries are full of issues, copy a full clone to data
|
for i in /system /system/lib /system/lib64 /system/vendor /system/vendor/lib /system/vendor/lib64; do
|
||||||
|
[ -f $MOUNTINFO/dummy$1 ] && DISABLEHIDE=true && break
|
||||||
# lib
|
done
|
||||||
if [ -f "$MOUNTINFO/dummy/system/lib" ]; then
|
|
||||||
BACKUPLIBS=true
|
|
||||||
make_copy_image /system/lib
|
|
||||||
cp -afc /system/lib/. $MIRRDIR/copy/system/lib
|
|
||||||
cp -afc $DUMMDIR/system/lib/. $MIRRDIR/copy/system/lib
|
|
||||||
mount_copy_image /system/lib
|
|
||||||
rm -f $MOUNTINFO/dummy/system/lib
|
|
||||||
fi
|
|
||||||
|
|
||||||
# lib64
|
|
||||||
if [ -f "$MOUNTINFO/dummy/system/lib64" ]; then
|
|
||||||
BACKUPLIBS=true
|
|
||||||
make_copy_image /system/lib64
|
|
||||||
cp -afc /system/lib64/. $MIRRDIR/copy/system/lib64
|
|
||||||
cp -afc $DUMMDIR/system/lib64/. $MIRRDIR/copy/system/lib64
|
|
||||||
mount_copy_image /system/lib64
|
|
||||||
rm -f $MOUNTINFO/dummy/system/lib64
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Whole vendor
|
|
||||||
if [ -f "$MOUNTINFO/dummy/system/vendor" ]; then
|
|
||||||
BACKUPLIBS=true
|
|
||||||
LIBSIZE=`du -s /vendor/lib | awk '{print $1}'`
|
|
||||||
if [ -d /vendor/lib64 ]; then
|
|
||||||
LIB64SIZE=`du -s /vendor/lib64 | awk '{print $1}'`
|
|
||||||
VENDORLIBSIZE=$(((($LIBSIZE + $LIB64SIZE) / 10240 + 2) * 10240))
|
|
||||||
else
|
|
||||||
VENDORLIBSIZE=$((($LIBSIZE / 10240 + 2) * 10240))
|
|
||||||
fi
|
|
||||||
make_copy_image /vendor $VENDORLIBSIZE
|
|
||||||
|
|
||||||
# Copy lib/lib64
|
|
||||||
mkdir -p $MIRRDIR/copy/vendor/lib
|
|
||||||
cp -afc /vendor/lib/. $MIRRDIR/copy/vendor/lib
|
|
||||||
cp -afc $DUMMDIR/system/vendor/lib/. $MIRRDIR/copy/vendor/lib 2>/dev/null
|
|
||||||
if [ -d /vendor/lib64 ]; then
|
|
||||||
mkdir -p $MIRRDIR/copy/vendor/lib64
|
|
||||||
cp -afc /vendor/lib64/. $MIRRDIR/copy/vendor/lib64
|
|
||||||
cp -afc $DUMMDIR/system/vendor/lib64/. $MIRRDIR/copy/vendor/lib64 2>/dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp -afc $DUMMDIR/system/vendor/. $MIRRDIR/copy/vendor
|
|
||||||
|
|
||||||
TRAVEL_ROOT=$MIRRDIR/copy
|
|
||||||
(clone_dummy /vendor)
|
|
||||||
# Create vendor mirror
|
|
||||||
if [ `mount | grep -c "on /vendor type"` -ne 0 ]; then
|
|
||||||
VENDORBLOCK=`mount | grep "on /vendor type" | awk '{print $1}'`
|
|
||||||
mkdir -p $MIRRDIR/vendor
|
|
||||||
mount -o ro $VENDORBLOCK $MIRRDIR/vendor
|
|
||||||
else
|
|
||||||
ln -s $MIRRDIR/system/vendor $MIRRDIR/vendor
|
|
||||||
fi
|
|
||||||
mount_copy_image /vendor
|
|
||||||
rm -f $MOUNTINFO/dummy/system/vendor
|
|
||||||
fi
|
|
||||||
|
|
||||||
# vendor lib
|
|
||||||
if [ -f "$MOUNTINFO/dummy/system/vendor/lib" ]; then
|
|
||||||
BACKUPLIBS=true
|
|
||||||
make_copy_image /system/vendor/lib
|
|
||||||
cp -afc /system/vendor/lib/. $MIRRDIR/copy/system/vendor/lib
|
|
||||||
cp -afc $DUMMDIR/system/vendor/lib/. $MIRRDIR/copy/system/vendor/lib
|
|
||||||
mount_copy_image /system/vendor/lib
|
|
||||||
rm -f $MOUNTINFO/dummy/system/vendor/lib
|
|
||||||
fi
|
|
||||||
|
|
||||||
# vendor lib64
|
|
||||||
if [ -f "$MOUNTINFO/dummy/system/vendor/lib64" ]; then
|
|
||||||
BACKUPLIBS=true
|
|
||||||
make_copy_image /system/vendor/lib64
|
|
||||||
cp -afc /system/vendor/lib64/. $MIRRDIR/copy/system/vendor/lib64
|
|
||||||
cp -afc $DUMMDIR/system/vendor/lib64/. $MIRRDIR/copy/system/vendor/lib64
|
|
||||||
mount_copy_image /system/vendor/lib64
|
|
||||||
rm -f $MOUNTINFO/dummy/system/vendor/lib64
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Crash prevention!!
|
# Crash prevention!!
|
||||||
$BACKUPLIBS && rm -f $COREDIR/magiskhide/enable 2>/dev/null
|
$DISABLEHIDE && rm -f $COREDIR/magiskhide/enable 2>/dev/null
|
||||||
|
|
||||||
# Remove crap folder
|
# Remove crap folder
|
||||||
rm -rf $MOUNTPOINT/lost+found
|
rm -rf $MOUNTPOINT/lost+found
|
||||||
@ -481,35 +360,61 @@ case $1 in
|
|||||||
# Start doing tasks
|
# Start doing tasks
|
||||||
|
|
||||||
# Stage 1
|
# Stage 1
|
||||||
TRAVEL_ROOT=$DUMMDIR
|
log_print "* Stage 1: Mount system and vendor mirrors"
|
||||||
log_print "* Bind mount dummy system"
|
SYSTEMBLOCK=`mount | grep " /system " | awk '{print $1}'`
|
||||||
find $MOUNTINFO/dummy -type f 2>/dev/null | while read ITEM ; do
|
mkdir -p $MIRRDIR/system
|
||||||
TARGET=${ITEM#$MOUNTINFO/dummy}
|
mount -o ro $SYSTEMBLOCK $MIRRDIR/system
|
||||||
ORIG="$DUMMDIR$TARGET"
|
if [ `mount | grep -c " /vendor "` -ne 0 ]; then
|
||||||
(clone_dummy "$TARGET")
|
VENDORBLOCK=`mount | grep " /vendor " | awk '{print $1}'`
|
||||||
bind_mount "$ORIG" "$TARGET"
|
mkdir -p $MIRRDIR/vendor
|
||||||
done
|
mount -o ro $VENDORBLOCK $MIRRDIR/vendor
|
||||||
|
else
|
||||||
|
ln -s $MIRRDIR/system/vendor $MIRRDIR/vendor
|
||||||
|
fi
|
||||||
|
# Since mirrors always exist, we load libraries from mirrors
|
||||||
|
LD_LIBRARY_PATH=$MIRRDIR/system/lib:$MIRRDIR/vendor/lib
|
||||||
|
[ -d /system/lib64 ] LD_LIBRARY_PATH=$MIRRDIR/system/lib64:$MIRRDIR/vendor/lib64
|
||||||
|
|
||||||
# Stage 2
|
# Stage 2
|
||||||
log_print "* Bind mount module items"
|
log_print "* Stage 2: Mount dummy skeletons"
|
||||||
|
# Move dummy /system/vendor to /vendor for consistency
|
||||||
|
mv -f $MOUNTINFO/dummy/system/vendor $MOUNTINFO/dummy/vendor 2>/dev/null
|
||||||
|
mv -f $DUMMDIR/system/vendor $DUMMDIR/vendor 2>/dev/null
|
||||||
|
find $MOUNTINFO/dummy -type f 2>/dev/null | while read ITEM ; do
|
||||||
|
TARGET=${ITEM#$MOUNTINFO/dummy}
|
||||||
|
ORIG=$DUMMDIR$TARGET
|
||||||
|
(clone_dummy $TARGET)
|
||||||
|
bind_mount $ORIG $TARGET
|
||||||
|
done
|
||||||
|
|
||||||
|
# Stage 3
|
||||||
|
log_print "* Stage 3: Mount module items"
|
||||||
find $MOUNTINFO/system -type f 2>/dev/null | while read ITEM ; do
|
find $MOUNTINFO/system -type f 2>/dev/null | while read ITEM ; do
|
||||||
TARGET=${ITEM#$MOUNTINFO}
|
TARGET=${ITEM#$MOUNTINFO}
|
||||||
ORIG=`cat $ITEM`$TARGET
|
ORIG=`cat $ITEM`$TARGET
|
||||||
bind_mount $ORIG $TARGET
|
bind_mount $ORIG $TARGET
|
||||||
rm -f $DUMMDIR${TARGET%/*}/.dummy 2>/dev/null
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Run scripts
|
# Stage 4
|
||||||
|
log_print "* Stage 4: Execute module scripts"
|
||||||
run_scripts post-fs-data
|
run_scripts post-fs-data
|
||||||
|
|
||||||
|
# Stage 5
|
||||||
|
log_print "* Stage 5: Mount mirrored items back to dummy"
|
||||||
|
find $MOUNTINFO/mirror -type f 2>/dev/null | while read ITEM ; do
|
||||||
|
TARGET=${ITEM#$MOUNTINFO/mirror}
|
||||||
|
ORIG=$MIRRDIR$TARGET
|
||||||
|
bind_mount $ORIG $TARGET
|
||||||
|
done
|
||||||
|
|
||||||
# Bind hosts for Adblock apps
|
# Bind hosts for Adblock apps
|
||||||
if [ -f "$COREDIR/hosts" ]; then
|
if [ -f $COREDIR/hosts ]; then
|
||||||
log_print "* Enabling systemless hosts file support"
|
log_print "* Enabling systemless hosts file support"
|
||||||
bind_mount $COREDIR/hosts /system/etc/hosts
|
bind_mount $COREDIR/hosts /system/etc/hosts
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Expose busybox
|
# Expose busybox
|
||||||
if [ -f "$COREDIR/busybox/enable" ]; then
|
if [ -f $COREDIR/busybox/enable ]; then
|
||||||
log_print "* Enabling BusyBox"
|
log_print "* Enabling BusyBox"
|
||||||
cp -afc /data/busybox/. $COREDIR/busybox
|
cp -afc /data/busybox/. $COREDIR/busybox
|
||||||
cp -afc /system/xbin/. $COREDIR/busybox
|
cp -afc /system/xbin/. $COREDIR/busybox
|
||||||
@ -518,10 +423,6 @@ case $1 in
|
|||||||
bind_mount $COREDIR/busybox /system/xbin
|
bind_mount $COREDIR/busybox /system/xbin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Stage 3
|
|
||||||
log_print "* Bind mount system mirror"
|
|
||||||
bind_mount /system $MIRRDIR/system
|
|
||||||
|
|
||||||
# Restart post-fs-data if necessary (multirom)
|
# Restart post-fs-data if necessary (multirom)
|
||||||
$MULTIROM && setprop magisk.restart_pfsd 1
|
$MULTIROM && setprop magisk.restart_pfsd 1
|
||||||
|
|
||||||
@ -536,7 +437,7 @@ case $1 in
|
|||||||
run_scripts service
|
run_scripts service
|
||||||
|
|
||||||
# Magisk Hide
|
# Magisk Hide
|
||||||
if [ -f "$COREDIR/magiskhide/enable" ]; then
|
if [ -f $COREDIR/magiskhide/enable ]; then
|
||||||
log_print "* Removing tampered read-only system props"
|
log_print "* Removing tampered read-only system props"
|
||||||
|
|
||||||
VERIFYBOOT=`getprop ro.boot.verifiedbootstate`
|
VERIFYBOOT=`getprop ro.boot.verifiedbootstate`
|
||||||
|
Loading…
Reference in New Issue
Block a user