-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
customize.sh
444 lines (400 loc) · 10.9 KB
/
customize.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# space
ui_print " "
# var
UID=`id -u`
[ ! "$UID" ] && UID=0
ABILIST=`grep_get_prop ro.product.cpu.abilist`
if [ ! "$ABILIST" ]; then
ABILIST=`grep_get_prop ro.system.product.cpu.abilist`
fi
ABILIST32=`grep_get_prop ro.product.cpu.abilist32`
if [ ! "$ABILIST32" ]; then
ABILIST32=`grep_get_prop ro.system.product.cpu.abilist32`
fi
if [ ! "$ABILIST32" ]; then
[ -f /system/lib/libandroid.so ] && ABILIST32=true
fi
# log
if [ "$BOOTMODE" != true ]; then
FILE=/data/media/"$UID"/$MODID\_recovery.log
ui_print "- Log will be saved at $FILE"
exec 2>$FILE
ui_print " "
fi
# optionals
OPTIONALS=/data/media/"$UID"/optionals.prop
if [ ! -f $OPTIONALS ]; then
touch $OPTIONALS
fi
# debug
if [ "`grep_prop debug.log $OPTIONALS`" == 1 ]; then
ui_print "- The install log will contain detailed information"
set -x
ui_print " "
fi
# recovery
if [ "$BOOTMODE" != true ]; then
MODPATH_UPDATE=`echo $MODPATH | sed 's|modules/|modules_update/|g'`
rm -f $MODPATH/update
rm -rf $MODPATH_UPDATE
fi
# run
. $MODPATH/function.sh
# info
MODVER=`grep_prop version $MODPATH/module.prop`
MODVERCODE=`grep_prop versionCode $MODPATH/module.prop`
ui_print " ID=$MODID"
ui_print " Version=$MODVER"
ui_print " VersionCode=$MODVERCODE"
if [ "$KSU" == true ]; then
ui_print " KSUVersion=$KSU_VER"
ui_print " KSUVersionCode=$KSU_VER_CODE"
ui_print " KSUKernelVersionCode=$KSU_KERNEL_VER_CODE"
sed -i 's|#k||g' $MODPATH/post-fs-data.sh
else
ui_print " MagiskVersion=$MAGISK_VER"
ui_print " MagiskVersionCode=$MAGISK_VER_CODE"
fi
ui_print " "
# architecture
if [ "$ABILIST" ]; then
ui_print "- $ABILIST architecture"
ui_print " "
fi
NAME=arm64-v8a
NAME2=armeabi-v7a
if ! echo "$ABILIST" | grep -Eq "$NAME|$NAME2"; then
if [ "$BOOTMODE" == true ]; then
ui_print "! This ROM doesn't support $NAME"
ui_print " nor $NAME2 architecture"
else
ui_print "! This Recovery doesn't support $NAME"
ui_print " nor $NAME2 architecture"
ui_print " Try to install via Magisk app instead"
fi
abort
fi
if ! echo "$ABILIST" | grep -q $NAME; then
rm -rf `find $MODPATH -type d -name *64*`\
$MODPATH/system*/bin
if [ "$BOOTMODE" != true ]; then
ui_print "! This Recovery doesn't support $NAME architecture"
ui_print " Try to install via Magisk app instead"
ui_print " "
fi
fi
if ! echo "$ABILIST" | grep -q $NAME2; then
rm -rf $MODPATH/system*/lib\
$MODPATH/system*/vendor/lib
if [ "$BOOTMODE" != true ]; then
ui_print "! This Recovery doesn't support $NAME2 architecture"
ui_print " Try to install via Magisk app instead"
ui_print " "
fi
fi
# sdk
NUM=21
if [ "$API" -lt $NUM ]; then
ui_print "! Unsupported SDK $API."
ui_print " You have to upgrade your Android version"
ui_print " at least SDK $NUM to use this module."
abort
else
ui_print "- SDK $API"
ui_print " "
fi
# recovery
mount_partitions_in_recovery
# magisk
magisk_setup
# path
SYSTEM=`realpath $MIRROR/system`
VENDOR=`realpath $MIRROR/vendor`
PRODUCT=`realpath $MIRROR/product`
SYSTEM_EXT=`realpath $MIRROR/system_ext`
ODM=`realpath $MIRROR/odm`
MY_PRODUCT=`realpath $MIRROR/my_product`
# sepolicy
FILE=$MODPATH/sepolicy.rule
DES=$MODPATH/sepolicy.pfsd
if [ "`grep_prop sepolicy.sh $OPTIONALS`" == 1 ]\
&& [ -f $FILE ]; then
mv -f $FILE $DES
fi
# function
file_check_system() {
for FILE in $FILES; do
DESS="$SYSTEM$FILE $SYSTEM_EXT$FILE"
for DES in $DESS; do
if [ -f $DES ]; then
ui_print "- Detected"
ui_print "$DES"
rm -f $MODPATH/system*$FILE
ui_print " "
fi
done
done
}
file_check_vendor() {
for FILE in $FILES; do
DESS="$VENDOR$FILE $ODM$FILE"
for DES in $DESS; do
if [ -f $DES ]; then
ui_print "- Detected"
ui_print "$DES"
rm -f $MODPATH/system*/vendor$FILE
ui_print " "
fi
done
done
}
# check
FILES="/bin/shelld /bin/miuibooster"
file_check_system
if [ "$IS64BIT" == true ]; then
LISTS=`ls $MODPATH/system/lib64`
FILES=`for LIST in $LISTS; do echo /lib64/$LIST; done`
file_check_system
LISTS=`ls $MODPATH/system/vendor/lib64`
FILES=`for LIST in $LISTS; do echo /lib64/$LIST; done`
file_check_vendor
fi
if [ "$ABILIST32" ]; then
LISTS=`ls $MODPATH/system/lib`
FILES=`for LIST in $LISTS; do echo /lib/$LIST; done`
file_check_system
LISTS=`ls $MODPATH/system/vendor/lib`
FILES=`for LIST in $LISTS; do echo /lib/$LIST; done`
file_check_vendor
fi
# function
check_function() {
ui_print "- Checking"
ui_print "$NAME"
ui_print " function at"
ui_print "$FILE"
ui_print " Please wait..."
if ! grep -q $NAME $FILE; then
ui_print " Function not found"
SYSTEM_10=true
fi
ui_print " "
}
# check
SYSTEM_10=false
NAME=_ZN7android23sp_report_stack_pointerEv
if [ "$IS64BIT" == true ]; then
DES=$MODPATH/system/bin/shelld
if [ -f $DES ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libshellservice.so||g' -e 's|libshell_jni.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib64/$LIST; done`
check_function
fi
DES=$MODPATH/system/bin/miuibooster
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib64/$LIST; done`
check_function
fi
DES=$MODPATH/system/lib64/libexmedia.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libexmedia.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib64/$LIST; done`
check_function
fi
DES=$MODPATH/system/lib64/libmiuiblur.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libmiuiblur.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib64/$LIST; done`
check_function
fi
DES=$MODPATH/system/lib64/libshell.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libshell.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib64/$LIST; done`
check_function
fi
DES=$MODPATH/system/vendor/lib64/libcdsprpc.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libcdsprpc.so||g' -e 's|lib%s_skel.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib64/$LIST; done`
check_function
fi
fi
if [ "$ABILIST32" ]; then
DES=$MODPATH/system/lib/libexmedia.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libexmedia.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib/$LIST; done`
check_function
fi
DES=$MODPATH/system/lib/libmiuiblur.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libmiuiblur.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib/$LIST; done`
check_function
fi
DES=$MODPATH/system/lib/libshell.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libshell.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib/$LIST; done`
check_function
fi
DES=$MODPATH/system/vendor/lib/libcdsprpc.so
if [ -f $DES ] && [ $SYSTEM_10 != true ]; then
LISTS=`strings $DES | grep ^lib | grep .so\
| sed -e 's|libcdsprpc.so||g' -e 's|lib%s_skel.so||g'`
FILE=`for LIST in $LISTS; do echo $SYSTEM/lib/$LIST; done`
check_function
fi
fi
if [ $SYSTEM_10 == true ]; then
ui_print "- Using legacy libraries"
cp -rf $MODPATH/system_10/* $MODPATH/system
ui_print " "
fi
rm -rf $MODPATH/system_10
# extract
APP=miuisystem
ui_print "- Extracting..."
FILE=`find $MODPATH/system -type f -name $APP.apk`
DIR=$MODPATH/system/etc
DES=assets/*
unzip -d $TMPDIR -o $FILE $DES
cp -rf $TMPDIR/$DES $DIR
ui_print " "
# cleaning
ui_print "- Cleaning..."
PKGS=`cat $MODPATH/package.txt`
if [ "$BOOTMODE" == true ]; then
for PKG in $PKGS; do
FILE=`find /data/app -name *$PKG*`
if [ "$FILE" ]; then
RES=`pm uninstall $PKG 2>/dev/null`
fi
done
fi
rm -rf $MODPATH/unused
remove_sepolicy_rule
ui_print " "
# power save
FILE=$MODPATH/system/etc/sysconfig/*
if [ "`grep_prop power.save $OPTIONALS`" == 1 ]; then
ui_print "- $MODNAME will not be allowed in power save."
ui_print " It may save your battery but decreasing $MODNAME performance."
for PKG in $PKGS; do
sed -i "s|<allow-in-power-save package=\"$PKG\"/>||g" $FILE
sed -i "s|<allow-in-power-save package=\"$PKG\" />||g" $FILE
done
ui_print " "
fi
# function
conflict() {
for NAME in $NAMES; do
DIR=/data/adb/modules_update/$NAME
if [ -f $DIR/uninstall.sh ]; then
sh $DIR/uninstall.sh
fi
rm -rf $DIR
DIR=/data/adb/modules/$NAME
rm -f $DIR/update
touch $DIR/remove
FILE=/data/adb/modules/$NAME/uninstall.sh
if [ -f $FILE ]; then
sh $FILE
rm -f $FILE
fi
rm -rf /metadata/magisk/$NAME\
/mnt/vendor/persist/magisk/$NAME\
/persist/magisk/$NAME\
/data/unencrypted/magisk/$NAME\
/cache/magisk/$NAME\
/cust/magisk/$NAME
done
}
# conflict
NAMES=MIUICore
conflict
# function
permissive_2() {
sed -i 's|#2||g' $MODPATH/post-fs-data.sh
}
permissive() {
FILE=/sys/fs/selinux/enforce
SELINUX=`cat $FILE`
if [ "$SELINUX" == 1 ]; then
if ! setenforce 0; then
echo 0 > $FILE
fi
SELINUX=`cat $FILE`
if [ "$SELINUX" == 1 ]; then
ui_print " Your device can't be turned to Permissive state."
ui_print " Using Magisk Permissive mode instead."
permissive_2
else
if ! setenforce 1; then
echo 1 > $FILE
fi
sed -i 's|#1||g' $MODPATH/post-fs-data.sh
fi
else
sed -i 's|#1||g' $MODPATH/post-fs-data.sh
fi
}
# permissive
if [ "`grep_prop permissive.mode $OPTIONALS`" == 1 ]; then
ui_print "- Using device Permissive mode."
rm -f $MODPATH/sepolicy.rule
permissive
ui_print " "
elif [ "`grep_prop permissive.mode $OPTIONALS`" == 2 ]; then
ui_print "- Using Magisk Permissive mode."
rm -f $MODPATH/sepolicy.rule
permissive_2
ui_print " "
fi
# public
FILE=$MODPATH/post-fs-data.sh
if [ "`grep_prop miui.public $OPTIONALS`" != 0 ]; then
sed -i 's|#p||g' $FILE
else
ui_print "- Does not patch public.libraries.txt"
ui_print " You will not be able to normal install Miui apps"
ui_print " "
fi
# global
FILE=$MODPATH/service.sh
NAME=ro.product.mod_device
if [ "`grep_prop miui.global $OPTIONALS`" == 1 ]; then
ui_print "- Global mode"
sed -i "s|#resetprop -n $NAME|resetprop -n $NAME|g" $FILE
ui_print " "
fi
# code
FILE=$MODPATH/service.sh
NAME=ro.miui.ui.version.code
if [ "`grep_prop miui.code $OPTIONALS`" == 0 ]; then
ui_print "- Removing $NAME..."
sed -i "s|resetprop -n $NAME|#resetprop -n $NAME|g" $FILE
ui_print " "
fi
# media
if [ ! -d /product/media ] && [ -d /system/media ]; then
ui_print "- Using /system/media instead of /product/media"
mv -f $MODPATH/system/product/media $MODPATH/system
rm -rf $MODPATH/system/product
ui_print " "
elif [ ! -d /product/media ] && [ ! -d /system/media ]; then
ui_print "! /product/media & /system/media not found"
ui_print " "
fi
# unmount
unmount_mirror