forked from DavidPisces/ReduceMIUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
264 lines (250 loc) · 8.94 KB
/
install.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
#!/bin/sh
# ReduceMIUI 精简计划 配置文件
# Made by @雄氏老方
# 跳过挂载
SKIPMOUNT=false
# 如果您需要加载system.prop,请将其设置为true
PROPFILE=true
# 如果您需要post-fs-data脚本(post-fs-data.sh),请将其设置为true
POSTFSDATA=false
# 如果您需要late_start服务脚本(service.sh),请将其设置为true
LATESTARTSERVICE=true
# SDK判断
sdk=$(grep_prop ro.build.version.sdk)
# 所要求最小版本
min_sdk=29
Enable_determination=false
# 禁用miui日志
is_clean_logs=true
# 使用hosts屏蔽小米某些ad域名
# 注意:使用该功能会导致主题商店在线加载图片出现问题
is_use_hosts=false
# 精简数量累计
num=0
# 可编辑文件 命名为*.prop是为了编辑/查看时一目了然
Compatible_with_older_versions="$(cat ${TMPDIR}/common/兼容精简.prop | grep -v '#')"
Package_Name_Reduction="$(cat ${TMPDIR}/common/包名精简.prop | grep -v '#')"
dex2oat_list="$(cat ${TMPDIR}/common/dex2oat.prop | grep -v '#')"
# 模块信息
pre_install() {
inspect_file
# 模块配置
module_id=Reducemiui
module_name="Reduce MIUI Project"
module_author="雄氏老方 & 阿巴酱"
module_minMagisk=19000
module_description="精简系统服务,关闭部分系统日志 更新日期:"
# 模块版本号
version="2.8"
# 模块精简列表更新日期
update_date="21.10.8"
ui_print "- 提取模块文件"
touch $TMPDIR/module.prop
unzip -o "$ZIPFILE" 'system/*' -d $MODPATH >&2
# 写入模块信息
echo -e "id=$module_id\nname=$module_name\nauthor=$module_author\nminMagisk=$module_minMagisk\n" >$TMPDIR/module.prop
# 保留dex2oat.prop配置文件
cp -r ${TMPDIR}/common/dex2oat.prop ${MODPATH}/
}
# 兼容精简
run_one() {
ui_print " "
ui_print "----------[ Run: 兼容精简 ]"
echo "- $(date '+%Y/%m/%d %T'): [兼容精简]" >>${MODPATH}/log.md
ui_print "- 如果这里空空如也"
ui_print "- 说明你不是远古版本的MIUI"
for i in ${Compatible_with_older_versions}; do
if [ -d "${i}" ]; then
apk_find="$(ls ${i})"
for j in ${apk_find}; do
case ${j} in
*.apk)
num="$((${num} + 1))"
set_mktouch_authority "${MODPATH}/${i}"
ui_print "- ${num}.REPLACE: ${i}/.replace"
echo "[${num}] REPLACE: ${i}/.replace" >>${MODPATH}/log.md
;;
esac
done
fi
done
echo "- [done]" >>${MODPATH}/log.md
ui_print "----------[ done ]"
ui_print " "
}
# 包名精简
run_two() {
ui_print " "
ui_print "----------[ Run: 包名精简 ]"
echo "- $(date '+%Y/%m/%d %T'): [包名精简]" >>${MODPATH}/log.md
appinfo -d " " -o ands,pn -pn ${Package_Name_Reduction} 2>/dev/null | while read line; do
app_1="$(echo ${line} | awk '{print $1}')"
app_2="$(echo ${line} | awk '{print $2}')"
app_path="$(pm path ${app_2} | grep -v '/data/app/' | sed 's/package://g')"
File_Dir="${MODPATH}${app_path%/*}"
[ -z "${app_path}" ] && echo "[!] >> ${app_1} << 为data应用: 或是经过应用商店更新"
if [ ! -d "$File_Dir" ]; then
num="$((${num} + 1))"
echo "- ${num}.REPLACE: ${app_1} (${app_2})"
set_mktouch_authority "${File_Dir}"
echo "名称:(${app_1})" >>${MODPATH}/log.md
echo "包名:(${app_2})" >>${MODPATH}/log.md
echo "原始路径: ${app_path}" >>${MODPATH}/log.md
echo "模块路径: $(echo ${File_Dir} | sed 's/modules_update/modules/g')" >>${MODPATH}/log.md
echo "" >>${MODPATH}/log.md
fi
done
echo "- [done]" >>${MODPATH}/log.md
ui_print "----------[ done ]"
ui_print " "
# 清理安装缓存
rm -rf ${bin_path}
}
retain_the_original_path() {
if [ "$(find /data/adb/modules*/Reducemiui -name '.replace')" != "" ]; then
ui_print " "
ui_print "----------[ Run: 原有路径保留 ]"
ui_print "- [&]: 已安装过模块 重新刷模块会保留原有精简路径"
Already_exists="$(find /data/adb/modules*/Reducemiui -name '.replace' | awk -F '/.replace' '{print $1}' | awk -F '/system/' '{print $2}')"
log_md="$(find /data/adb/modules*/Reducemiui -name 'log.md')"
cp -r ${log_md} ${MODPATH}
echo "- $(date '+%Y/%m/%d %T'): [原有路径保留]" >>${MODPATH}/log.md
for original_path in ${Already_exists}; do
num="$((${num} + 1))"
ui_print "- ${num}.REPLACE: /system/${original_path}"
echo "[${num}] update: /system/${original_path}/.replace" >>${MODPATH}/log.md
set_mktouch_authority "${MODPATH}/system/${original_path}"
done
echo "- [done]" >>${MODPATH}/log.md
ui_print "----------[ done ]"
ui_print " "
fi
}
inspect_file() {
tools_path="${TMPDIR}/common/tools"
[ ! -e "${tools_path}/appinfo" ] && abort "- 缺少必备文件: appinfo"
[ ! -e "${tools_path}/appinfo.dex" ] && abort "- 缺少必备文件: appinfo.dex"
}
change_env() {
bin_path="/data/adb/Reducemiui_bin"
[ ! -d "${bin_path}" ] && mkdir -p ${bin_path}
rm -rf ${bin_path}/* >/dev/null
cp -r ${tools_path}/appinfo* ${bin_path}
chmod 0777 ${bin_path}/*
export PATH="${bin_path}:${PATH}"
}
set_mktouch_authority() {
mkdir -p $1
touch $1/.replace
chown root:root $1/.replace
chmod 0644 $1/.replace
}
costom_setttings() {
# 版本判断启用配置
if [ "$Enable_determination" == "true" ]; then
if [ $sdk -ge $min_sdk ]; then
ui_print "- 当前SDK为:$sdk"
else
abort "- 当前SDK为:$sdk,不符合要求最低SDK:$min_sdk"
ui_print "- ! 安装终止"
fi
fi
inspect_file
change_env
# 写入更新日期
echo -n "description=$module_description$update_date" >>$TMPDIR/module.prop
# 写入版本号
echo -e "\nversion=$version" >>$TMPDIR/module.prop
}
clean_wifi_logs() {
if [ "$is_clean_logs" == "true" ]; then
ui_print "- 正在停止tcpdump"
stop tcpdump
ui_print "- 正在停止cnss_diag"
stop cnss_diag
ui_print "- 正在停止logd"
stop logd
ui_print "- 正在清除MIUI WiFi log"
rm -rf /data/vendor/wlan_logs/*
setprop sys.miui.ndcd off >/dev/null
touch /data/adb/modules_update/Reducemiui/system.prop
echo "sys.miui.ndcd=off" >/data/adb/modules_update/Reducemiui/system.prop
fi
}
uninstall_useless_app() {
ui_print "- 正在禁用智能服务"
pm disable com.miui.systemAdSolution >/dev/null && ui_print "- pm disable com.miui.systemAdSolution: Success" || ui_print "- 不存在应用: com.miui.systemAdSolution 或已被精简"
ui_print "- 正在移除Analytics"
if [ "$(pm list package | grep 'com.miui.analytics')" != "" ]; then
rm -rf /data/user/0/com.xiaomi.market/app_analytics/*
chown -R root:root /data/user/0/com.xiaomi.market/app_analytics/
chmod -R 000 /data/user/0/com.xiaomi.market/app_analytics/
pm uninstall --user 0 com.miui.analytics >/dev/null
if [ -d "/data/user/999/com.xiaomi.market/app_analytics/" ]; then
rm -rf /data/user/999/com.xiaomi.market/app_analytics/*
chown -R root:root /data/user/999/com.xiaomi.market/app_analytics/
chmod -R 000 /data/user/999/com.xiaomi.market/app_analytics/
pm uninstall --user 999 com.miui.analytics >/dev/null
fi
ui_print "- Analytics移除成功"
else
ui_print "- Analytics不存在"
fi
}
dex2oat_app() {
ui_print "- 为保障流畅,执行dex2oat(Everything)优化,需要一点时间..."
for app_list in ${dex2oat_list}; do
cmd package compile -m everything ${app_list} >/dev/null && ui_print "- ${app_list}: Success"
done
ui_print "- 优化完成"
}
hosts_file() {
find_hosts="$(find /data/adb/modules*/*/system/etc -name 'hosts')"
if [ "$(echo "$find_hosts" | grep -v "Reducemiui")" != "" ]; then
echo "$find_hosts" | grep "Reducemiui" | xargs rm -rf
find_hosts="$(find /data/adb/modules*/*/system/etc -name 'hosts')"
have_an_effect_hosts="$(echo $find_hosts | awk '{print $NF}')"
if [ "$(cat "${have_an_effect_hosts}" | grep '# Start Reducemiui hosts')" == "" ]; then
cat "${TMPDIR}/common/hosts.txt" >>${have_an_effect_hosts}
fi
else
mkdir -p ${MODPATH}/system/etc/
find_hosts="$(find /data/adb/modules*/Reducemiui/system/etc -name 'hosts')"
if [ ! -f "${find_hosts}" ]; then
cp -r /system/etc/hosts ${MODPATH}/system/etc/
cat ${TMPDIR}/common/hosts.txt >>${MODPATH}/system/etc/hosts
else
cp -r ${find_hosts} ${MODPATH}/system/etc/
fi
fi
}
# 最后步骤
dodone() {
# 防止侧漏精简无效
find ${MODPATH}/system_ext/ ${MODPATH}/product/ | grep ".replace" | awk -F "/Reducemiui" '{print $2}' | sed 's/\/.replace//g' | while read Lateral_leakage; do
mkdir -p ${MODPATH}/system${Lateral_leakage}
touch ${MODPATH}/system${Lateral_leakage}/.replace
done
[ -d "${MODPATH}/product" ] && rm -rf ${MODPATH}/product/
[ -d "${MODPATH}/system_ext" ] && rm -rf ${MODPATH}/system_ext/
# hosts文件判断
if [ $is_use_hosts == true ]; then
hosts_file
else
ui_print "- hosts文件未启用"
fi
}
pre_install
ui_print " "
ui_print " "
ui_print " Reduce MIUI Project"
ui_print " "
ui_print " "
costom_setttings
clean_wifi_logs
uninstall_useless_app
dex2oat_app
retain_the_original_path
run_one
run_two
dodone