-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfix_update_script
executable file
·314 lines (237 loc) · 8.65 KB
/
fix_update_script
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
############################################################################
#
# Copyright (c) 2013 - dsixda (dislam@rocketmail.com)
# Copyright (c) 2014 - 越狱 (http://weibo.com/206021119)
#
# Android 厨房是100%免费。此脚本文件仅供个人或学习使用
# by hwh132 越狱 汉化
#
############################################################################
cd WORKING_*
if [ ! -d system ]
then
echo
echo "错误: 未发现 /system 文件夹!"
cd ..
exit 0
fi
if [ -e META-INF/com/google/android/update-script ]
then
#
# 检查 /system/bin 中的符号链接和添加符号链接到 update-script 脚本
#
# 不要进入 system/bin 的所有方式, 因为一些二进制文件
# 有可能发生冲突与你的系统文件操作命令
# (例如: ls, rm)!
cd system
echo
echo -n "正在查找 /system/bin 下的符号链接 ..."
symlinks=`find bin -type l -exec ls -l {} \; | sed 's/.* bin\/\([^ ]*\).*/\1/g'`
source_files=`find bin -type l -exec ls -l {} \; | sed 's/.*-> //g'`
#
# Fix for newer RFS-based ROMs (e.g. on Samsung Infuse 4G)
# The symlink files contain a hex-encoded reference to 'toolbox'
#
if [ "$symlinks" == "" ]
then
if [ -e bin/cat ]
then
toolbox_hex="0074006f006f006c0062006f0078"
test_toolbox=`od -A n -h -j 8 -N 13 bin/cat | sed 's/ //g'`
if [ "$test_toolbox" == "$toolbox_hex" ]
then
file_list=`ls bin`
for curr_file in $file_list
do
check_toolbox=`od -A n -h -j 8 -N 13 bin/$curr_file | sed 's/ //g'`
if [ "$check_toolbox" == "$toolbox_hex" ]
then
echo -n "."
symlinks="$symlinks $curr_file"
fi
done
fi
fi
fi
echo
symlinks=( $symlinks )
source_files=( $source_files )
#
# Check if no symlinks found in ROM and update-script has no symlink entries
#
if [ "$symlinks" == "" ] && [ "`grep "symlink toolbox" ../META-INF/com/google/android/update-script`" == "" ]
then
echo "什么也没检测到"
#
# Build a set of default symlinks in update-script if none found in /system/bin
#
if [ "`grep "symlink toolbox" ../META-INF/com/google/android/update-script`" == "" ] && [ -e bin/toolbox ]
then
echo -n "正在添加默认 toolbox 符号链接到 update-script 脚本"
cp ../../tools/update_files/default_symlinks .
sed -i -e '/copy_dir PACKAGE:system SYSTEM:/r default_symlinks' ../META-INF/com/google/android/update-script
rm default_symlinks
file_list=`ls bin`
#
# If binary already exists, then remove symlink in update-script
#
for curr_file in $file_list
do
echo -n "."
check_line="symlink toolbox SYSTEM:bin\\/$curr_file"
if [ `grep -c "$check_line" ../META-INF/com/google/android/update-script` != 0 ]
then
sed -i -e '/'"$check_line"'[ ]*$/d' ../META-INF/com/google/android/update-script
fi
done
echo
fi
if [ "`grep "symlink dumpstate" ../META-INF/com/google/android/update-script`" == "" ] && [ -e bin/dumpstate ]
then
if [ ! -e bin/bugreport ]
then
echo "正在添加 bugreport 符号链接 ..."
sed -i -e 's/copy_dir PACKAGE:system SYSTEM:/copy_dir PACKAGE:system SYSTEM:\nsymlink dumpstate SYSTEM:bin\/bugreport\n/' ../META-INF/com/google/android/update-script
fi
if [ ! -e bin/dumpcrash ]
then
echo "正在添加 dumpcrash 符号链接 ..."
sed -i -e 's/copy_dir PACKAGE:system SYSTEM:/copy_dir PACKAGE:system SYSTEM:\nsymlink dumpstate SYSTEM:bin\/dumpcrash\n/' ../META-INF/com/google/android/update-script
fi
fi
#
# 检查 ROM 中找到的符号链接
#
elif [ "$symlinks" != "" ]
then
echo -n "它们将会添加到 update-script 刷机脚本并从 system/bin 删除"
for (( i=0 ; i < ${#symlinks[@]} ; i++ ))
do
echo -n "."
link=${symlinks[$i]}
src=${source_files[$i]}
if [ "$src" == "" ]
then
src=toolbox
else
#
# Remove full paths for some binaries
#
if [ `echo $src | grep -c /busybox$` == 1 ]
then
src=busybox
elif [ `echo $src | grep -c /toolbox$` == 1 ]
then
src=toolbox
elif [ `echo $src | grep -c /dumpstate$` == 1 ]
then
src=dumpstate
elif [ `echo $src | grep -c /iwmulticall$` == 1 ]
then
src=iwmulticall
fi
fi
# Deleting the symbolic link
rm -f bin/$link
export LINK=$link
export SRC=$src
perl -pi -e 's/set_perm_recursive 0 0 0755 0644 SYSTEM:[ ]*$/symlink $ENV{"SRC"} SYSTEM:bin\/$ENV{"LINK"}\nset_perm_recursive 0 0 0755 0644 SYSTEM:/' ../META-INF/com/google/android/update-script
done
echo
else
echo "在 ROM 中未发现符号链接;在 update-script 脚本中发现"
fi
cd ..
#
# Modify the update-script if certain files are missing under /system
#
if [ ! -e system/bin/debuggerd ]
then
sed -i -e '/symlink debuggerd /d' META-INF/com/google/android/update-script
fi
if [ ! -e system/bin/mksh ]
then
sed -i -e '/symlink mksh /d' META-INF/com/google/android/update-script
fi
if [ ! -e system/bin/wiperiface_v02 ]
then
sed -i -e '/symlink wiperiface_v02 /d' META-INF/com/google/android/update-script
fi
if [ ! -e system/bin/ip ]
then
perl -pi -e 's/set_perm 0 3003 06755 SYSTEM:bin\/ip\n//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/etc/ppp ]
then
perl -pi -e 's/set_perm_recursive 0 0 0755 0555 SYSTEM:etc\/ppp[ ]*\n//g' META-INF/com/google/android/update-script
fi
if [ -d system/etc/bluetooth ]
then
perl -pi -e 's/set_perm_recursive 1002 1002 0755 0440 SYSTEM:etc\/bluez\n//g' META-INF/com/google/android/update-script
perl -pi -e 's/set_perm 0 0 0755 SYSTEM:etc\/bluez\n//g' META-INF/com/google/android/update-script
else
perl -pi -e 's/set_perm_recursive 1002 1002 0755 0440 SYSTEM:etc\/bluetooth\n//g' META-INF/com/google/android/update-script
perl -pi -e 's/set_perm 0 0 0755 SYSTEM:etc\/bluetooth\n//g' META-INF/com/google/android/update-script
fi
if [ ! -e system/etc/bluetooth/auto_pairing.conf ]
then
perl -pi -e 's/set_perm 1000 1000 0640 SYSTEM:etc\/bluetooth\/auto_pairing.conf\n//g' META-INF/com/google/android/update-script
fi
if [ ! -e system/etc/bluetooth/blacklist.conf ]
then
perl -pi -e 's/set_perm 3002 3002 0444 SYSTEM:etc\/bluetooth\/blacklist.conf\n//g' META-INF/com/google/android/update-script
fi
if [ ! -e system/etc/bluetooth/auto_pair_devlist.conf ]
then
perl -pi -e 's/set_perm 1000 1000 0640 SYSTEM:etc\/bluetooth\/auto_pair_devlist.conf\n//g' META-INF/com/google/android/update-script
fi
if [ ! -e system/bin/run-as ]
then
perl -pi -e 's/set_perm 0 2000 06750 SYSTEM:bin\/run-as\n//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/vendor ]
then
perl -pi -e 's/set_perm_recursive 0 2000 0755 0644 SYSTEM:vendor[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/vendor/firmware ]
then
perl -pi -e 's/set_perm_recursive 0 0 0755 0644 SYSTEM:vendor\/firmware[ ]*$//g' META-INF/com/google/android/update-script
perl -pi -e 's/set_perm 0 2000 0755 SYSTEM:vendor\/firmware[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/vendor/bin ]
then
perl -pi -e 's/set_perm_recursive 0 2000 0755 0755 SYSTEM:vendor\/bin[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/vendor/etc ]
then
perl -pi -e 's/set_perm_recursive 0 2000 0755 0644 SYSTEM:vendor\/etc[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/vendor/lib ]
then
perl -pi -e 's/set_perm 0 2000 0755 SYSTEM:vendor\/lib[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/vendor/lib/egl ]
then
perl -pi -e 's/set_perm 0 2000 0755 SYSTEM:vendor\/lib\/egl[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/vendor/lib/hw ]
then
perl -pi -e 's/set_perm 0 2000 0755 SYSTEM:vendor\/lib\/hw[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -e system/vendor/etc/gps.xml ]
then
perl -pi -e 's/set_perm 0 0 0644 SYSTEM:vendor\/etc\/gps.xml//g' META-INF/com/google/android/update-script
fi
if [ ! -d system/xbin ]
then
perl -pi -e 's/set_perm_recursive 0 2000 0755 0755 SYSTEM:xbin[ ]*$//g' META-INF/com/google/android/update-script
fi
if [ ! -e system/etc/install-recovery.sh ]
then
perl -pi -e 's/set_perm 0 0 0544 SYSTEM:etc\/install-recovery.sh\n//g' META-INF/com/google/android/update-script
fi
cd ..
scripts/fix_update_script_blanks
else
cd ..
fi