-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathfunction.sh
258 lines (246 loc) · 6.33 KB
/
function.sh
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# function
remove_cache() {
FILES=`find $MODPATH -type f -name *.apk | sed 's|.apk||g'`
APPS=`for FILE in $FILES; do basename $FILE; done`
for APP in $APPS; do
rm -f `find /data/system/package_cache\
/data/dalvik-cache /data/resource-cache\
-type f -name *$APP*`
done
}
mount_partitions_in_recovery() {
if [ "$BOOTMODE" != true ]; then
BLOCK=/dev/block/bootdevice/by-name
BLOCK2=/dev/block/mapper
ui_print "- Recommended to mount all partitions first"
ui_print " before installing this module"
ui_print " "
DIR=/vendor
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK2$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK/cust $DIR\
|| mount -o rw -t auto $BLOCK2/cust $DIR
fi
DIR=/product
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK2$DIR$SLOT $DIR
fi
DIR=/system_ext
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK2$DIR$SLOT $DIR
fi
DIR=/odm
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK2$DIR$SLOT $DIR
fi
DIR=/my_product
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR $DIR\
|| mount -o rw -t auto $BLOCK2$DIR $DIR
fi
DIR=/data
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK/userdata $DIR\
|| mount -o rw -t auto $BLOCK2/userdata $DIR
fi
DIR=/cache
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR $DIR\
|| mount -o rw -t auto $BLOCK2$DIR $DIR
fi
DIR=/persist
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR $DIR\
|| mount -o rw -t auto $BLOCK2$DIR $DIR
fi
DIR=/metadata
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR $DIR\
|| mount -o rw -t auto $BLOCK2$DIR $DIR
fi
DIR=/cust
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR $DIR\
|| mount -o rw -t auto $BLOCK2$DIR $DIR
fi
fi
}
get_device() {
DEV="`cat /proc/self/mountinfo | awk '{ if ( $5 == "'$1'" ) print $3 }' | head -1 | sed 's/:/ /g'`"
}
mount_mirror() {
RAN="`head -c6 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9'`"
while [ -e /dev/$RAN ]; do
RAN="`head -c6 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9'`"
done
mknod /dev/$RAN b `get_device "$1"; echo $DEV`
if mount -t ext4 -o ro /dev/$RAN "$2"\
|| mount -t erofs -o ro /dev/$RAN "$2"\
|| mount -t f2fs -o ro /dev/$RAN "$2"\
|| mount -t auto -o ro /dev/$RAN "$2"; then
blockdev --setrw /dev/$RAN
rm -f /dev/$RAN
return 0
fi
rm -f /dev/$RAN
return 1
}
unmount_mirror() {
if [ "$BOOTMODE" == true ]\
&& [ "$HASMIRROR" == false ]; then
FOLDS="$MIRROR/* $MIRROR"
for FOLD in $FOLDS; do
umount $FOLD
done
rm -rf $MIRROR/*
fi
}
remount_partitions() {
PARS="/ /system /vendor /product /system_ext /odm /my_product"
for PAR in $PARS; do
mount -o ro,remount $PAR
done
}
mount_system_to_mirror() {
DIR=/system
if [ ! -d $MIRROR$DIR ]; then
HASMIRROR=false
remount_partitions
unmount_mirror
ui_print "- Mounting $MIRROR$DIR..."
if [ "$SYSTEM_ROOT" == true ]\
|| [ "$SYSTEM_AS_ROOT" == true ]; then
mkdir -p $MIRROR/system_root
if mount_mirror / $MIRROR/system_root; then
rm -rf $MIRROR$DIR
ln -sf $MIRROR/system_root$DIR $MIRROR
else
ui_print " ! Failed"
rm -rf $MIRROR/system_root
fi
else
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " ! Failed"
rm -rf $MIRROR$DIR
fi
fi
ui_print " "
else
HASMIRROR=true
fi
}
mount_vendor_to_mirror() {
DIR=/vendor
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system$DIR ]; then
ln -sf $MIRROR/system$DIR $MIRROR
fi
fi
ui_print " "
fi
}
mount_product_to_mirror() {
DIR=/product
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system$DIR ]; then
ln -sf $MIRROR/system$DIR $MIRROR
fi
fi
ui_print " "
fi
}
mount_system_ext_to_mirror() {
DIR=/system_ext
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system$DIR ]; then
ln -sf $MIRROR/system$DIR $MIRROR
fi
fi
ui_print " "
fi
}
mount_odm_to_mirror() {
DIR=/odm
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system_root$DIR ]; then
ln -sf $MIRROR/system_root$DIR $MIRROR
elif [ -d $MIRROR/vendor$DIR ]; then
ln -sf $MIRROR/vendor$DIR $MIRROR
elif [ -d $MIRROR/system/vendor$DIR ]; then
ln -sf $MIRROR/system/vendor$DIR $MIRROR
fi
fi
ui_print " "
fi
}
mount_my_product_to_mirror() {
DIR=/my_product
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system_root$DIR ]; then
ln -sf $MIRROR/system_root$DIR $MIRROR
fi
fi
ui_print " "
fi
}
mount_partitions_to_mirror() {
mount_system_to_mirror
mount_vendor_to_mirror
mount_product_to_mirror
mount_system_ext_to_mirror
mount_odm_to_mirror
mount_my_product_to_mirror
}
magisk_setup() {
MAGISKTMP=`magisk --path`
if [ "$BOOTMODE" == true ]; then
if [ "$MAGISKTMP" ]; then
mount -o rw,remount $MAGISKTMP
INTERNALDIR=$MAGISKTMP/.magisk
MIRROR=$INTERNALDIR/mirror
else
INTERNALDIR=/mnt
mount -o rw,remount $INTERNALDIR
MIRROR=$INTERNALDIR/mirror
fi
mount_partitions_to_mirror
fi
}
remove_sepolicy_rule() {
rm -rf /metadata/magisk/"$MODID"\
/mnt/vendor/persist/magisk/"$MODID"\
/persist/magisk/"$MODID"\
/data/unencrypted/magisk/"$MODID"\
/cache/magisk/"$MODID"\
/cust/magisk/"$MODID"
}