-
Notifications
You must be signed in to change notification settings - Fork 1
/
mount-magisk
executable file
·58 lines (51 loc) · 1.15 KB
/
mount-magisk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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