-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathframework-patcher-remote
executable file
·132 lines (111 loc) · 2.95 KB
/
framework-patcher-remote
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/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 $?
}
request_size_check() {
reqSizeM=`unzip -l "$1" 2>/dev/null | tail -n 1 | awk '{ print $1 }'`
reqSizeM=$((reqSizeM / 1048576 + 1))
}
image_size_check() {
e2fsck -yf $1
curBlocks=`e2fsck -n $1 2>/dev/null | grep $1 | cut -d, -f3 | cut -d\ -f2`;
curUsedM=`echo "$curBlocks" | cut -d/ -f1`
curSizeM=`echo "$curBlocks" | cut -d/ -f1`
curFreeM=$(((curSizeM - curUsedM) * 4 / 1024))
curUsedM=$((curUsedM * 4 / 1024 + 1))
curSizeM=$((curSizeM * 4 / 1024))
}
grow_magisk_img () {
request_size_check /tmp/services.jar
image_size_check ${MAGISK_IMG}
if [ "$reqSizeM" -gt "$curFreeM" ]; then
SIZE=$(((reqSizeM + curUsedM) / 32 * 32 + 64))
resize2fs ${MAGISK_IMG} ${SIZE}M
fi
}
shrink_magisk_img () {
image_size_check ${MAGISK_IMG}
NEWDATASIZE=$((curUsedM / 32 * 32 + 32))
if [ "$curSizeM" -gt "$NEWDATASIZE" ]; then
resize2fs $IMG ${NEWDATASIZE}M
fi
}
mount_image() {
if [ ! -d "$2" ]; then
mount -o rw,remount rootfs /
mkdir -p "$2" 2>/dev/null
$BOOTMODE && mount -o ro,remount rootfs /
[ ! -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
mount_image ${MAGISK_IMG} /magisk
}
umount_magisk () {
umount /magisk
losetup -d $(cat /tmp/loopdevice)
rm /tmp/loopdevice
}
if [[ -f /data/adb/magisk.img ]]; then
MAGISK_IMG=/data/adb/magisk.img
elif [[ -f /data/magisk.img ]]; then
MAGISK_IMG=/data/magisk.img
fi
if [[ -f ${MAGISK_IMG} ]]; then
grow_magisk_img
echo "magisk found: mount to /magisk"
mount_magisk
fi
if [[ -f /data/adb/.nanodroid-patcher ]]; then
echo " ++ /system/.nanodroid-patcher exists"
echo " ++ assuming ROM is already patched"
exit 0
fi
install_path=""
if [[ -d /magisk/NanoDroid ]]; then
echo "NanoDroid detected"
install_path="/magisk/NanoDroid/system"
mkdir -p "${install_path}"
elif [[ -d /magisk/NanoDroid_microG ]]; then
echo "NanoDroid microG detected"
install_path="/magisk/NanoDroid_microG/system"
mkdir -p "${install_path}"
else
echo "backing up services.jar to /sdcard/nanodroid_backups"
mkdir -p /sdcard/nanodroid_backups
cp /tmp/services.jar /sdcard/nanodroid_backups
echo "using ROM as destination"
install_path="/system"
echo /system/framework/services.jar >> \
/system/.nanodroid-list
fi
echo "install to \"${install_path}\""
cp /tmp/services.jar "${install_path}/framework" || exit 1
touch /data/adb/.nanodroid-patcher
if (is_mounted /magisk); then
echo "unmount /magisk"
umount_magisk
shrink_magisk_img
fi
echo "unmount /system"
umount /system