2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-11-07 15:20:36 +00:00
NanoDroid/mount-magisk
Christopher Roy Bratusek ec30353eac Initial commit
2018-01-23 21:11:52 +01:00

59 lines
1.2 KiB
Bash
Executable File

#!/sbin/sh
is_mounted() {
if [ ! -z "$2" ]; then
cat /proc/mounts | grep $1 | grep $2, >/dev/null
else
cat /proc/mounts | grep $1 >/dev/null
fi
return $?
}
mount_image() {
if [ ! -d "$2" ]; then
mount -o rw,remount rootfs /
mkdir -p "$2" 2>/dev/null
[ ! -d "$2" ] && return 1
fi
if ! is_mounted "$2"; then
LOOPDEVICE=
for LOOP in 0 1 2 3 4 5 6 7; do
if ! is_mounted "$2"; then
LOOPDEVICE=/dev/block/loop$LOOP
[ -e $LOOPDEVICE ] || mknod $LOOPDEVICE b 7 $LOOP 2>/dev/null
losetup $LOOPDEVICE "$1" && mount -t ext4 -o loop $LOOPDEVICE "$2"
if is_mounted "$2"; then
echo "$LOOPDEVICE" > /tmp/loopdevice
break;
fi
fi
done
fi
}
mount_magisk () {
mount /data &>/dev/null
if [ -f /data/adb/magisk.img ]; then
mount_image /data/adb/magisk.img /magisk
elif [ -f /data/magisk.img ]; then
mount_image /data/magisk.img /magisk
fi
}
umount_magisk () {
umount /magisk
losetup -d $(cat /tmp/loopdevice)
rm /tmp/loopdevice
}
if (is_mounted /magisk); then
if [ -f /tmp/loopdevice ]; then
umount_magisk
else echo "Magisk is mounted, but not using mount-magisk"
echo "not unmounting Magisk"
fi
else mount_magisk
fi