-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcustomize.sh
288 lines (256 loc) · 6.17 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
# space
ui_print " "
# var
UID=`id -u`
[ ! "$UID" ] && UID=0
# 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 " "
# 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
# bit
if [ "$IS64BIT" == true ]; then
ui_print "- 64 bit"
else
ui_print "- 32 bit"
rm -rf `find $MODPATH -type d -name *64*`
fi
ui_print " "
# miuicore
if [ ! -d /data/adb/modules/MiuiCore ]; then
ui_print "! Miui Core Magisk Module is not installed."
ui_print " Please read github installation guide!"
abort
else
rm -f /data/adb/modules/MiuiCore/remove
rm -f /data/adb/modules/MiuiCore/disable
fi
# sepolicy
FILE=$MODPATH/sepolicy.rule
DES=$MODPATH/sepolicy.pfsd
if [ "`grep_prop sepolicy.sh $OPTIONALS`" == 1 ]\
&& [ -f $FILE ]; then
mv -f $FILE $DES
fi
# 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
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=MIUIGallery
conflict
# function
cleanup() {
if [ -f $DIR/uninstall.sh ]; then
sh $DIR/uninstall.sh
fi
DIR=/data/adb/modules_update/$MODID
if [ -f $DIR/uninstall.sh ]; then
sh $DIR/uninstall.sh
fi
}
# cleanup
DIR=/data/adb/modules/$MODID
FILE=$DIR/module.prop
PREVMODNAME=`grep_prop name $FILE`
if [ "`grep_prop data.cleanup $OPTIONALS`" == 1 ]; then
sed -i 's|^data.cleanup=1|data.cleanup=0|g' $OPTIONALS
ui_print "- Cleaning-up $MODID data..."
cleanup
ui_print " "
#elif [ -d $DIR ]\
#&& [ "$PREVMODNAME" != "$MODNAME" ]; then
# ui_print "- Different version detected"
# ui_print " Cleaning-up $MODID data..."
# cleanup
# ui_print " "
fi
# 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
# function
extract_lib() {
for APP in $APPS; do
FILE=`find $MODPATH/system -type f -name $APP.apk`
if [ -f `dirname $FILE`/extract ]; then
rm -f `dirname $FILE`/extract
ui_print "- Extracting..."
DIR=`dirname $FILE`/lib/"$ARCH"
mkdir -p $DIR
rm -rf $TMPDIR/*
DES=lib/"$ABI"/*
unzip -d $TMPDIR -o $FILE $DES
cp -f $TMPDIR/$DES $DIR
ui_print " "
fi
done
}
hide_oat() {
for APP in $APPS; do
REPLACE="$REPLACE
`find $MODPATH/system -type d -name $APP | sed "s|$MODPATH||g"`/oat"
done
}
# extract
APPS="`ls $MODPATH/system/priv-app` `ls $MODPATH/system/app`"
extract_lib
# hide
hide_oat
# features
PROP=`grep_prop miui.features $OPTIONALS`
FILE=$MODPATH/service.sh
if [ "$PROP" == 0 ]; then
ui_print "- Removing ro.gallery.device changes..."
sed -i 's|resetprop ro.gallery.device cepheus||g' $FILE
ui_print " "
elif [ "$PROP" ] && [ "$PROP" != 1 ]; then
ui_print "- ro.gallery.device will be changed to $PROP"
sed -i "s|cepheus|$PROP|g" $FILE
ui_print " "
fi
# function
patch_file() {
ui_print "- Patching"
ui_print "$FILE"
ui_print " changing $PROP"
ui_print " to $MODPROP"
ui_print " Please wait..."
sed -i "s|$PROP|$MODPROP|g" $FILE
ui_print " "
}
# patch
FILE=`find $MODPATH/system -type f -name libnexeditorsdk.so`
PROP=ro.product.device
MODPROP=ro.gallery.device
patch_file
FILE=`find $MODPATH -type f -name libnex*.so`
PROP=ro.product.manufacturer
MODPROP=ro.product.miui.gallery
patch_file