forked from dsixda/Android-Kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_update_script
More file actions
executable file
·319 lines (242 loc) · 8.96 KB
/
fix_update_script
File metadata and controls
executable file
·319 lines (242 loc) · 8.96 KB
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
############################################################################
#
# Copyright (c) 2013 - dsixda ([email protected])
#
# Android Kitchen is 100% free. This script file is intended for personal
# and/or educational use only. It may not be duplicated for monetary
# benefit or any other purpose without the permission of the developer.
#
############################################################################
cd WORKING_*
if [ ! -d system ]
then
echo
echo "Error: No /system folder found!"
cd ..
exit 0
fi
if [ -e META-INF/com/google/android/update-script ]
then
#
# Check for symbolic links in /system/bin and add symlinks to update-script
#
# Don't go all the way into system/bin, because some of the binaries in
# there may collide with your operating system's file operation commands
# (e.g. ls, rm)!
cd system
echo
echo -n "Looking for symbolic links under /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 "None detected"
#
# 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 "Adding a default set of toolbox symlinks to 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 "Adding bugreport symlink ..."
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 "Adding dumpcrash symlink ..."
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
#
# Check if symlinks found in ROM
#
elif [ "$symlinks" != "" ]
then
echo -n "They will now be added to the update-script and removed from 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 "No symbolic links in ROM; they are found in 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/etc/bluez ]
then
perl -pi -e 's/set_perm_recursive 1002 1002 0755 0440 SYSTEM:etc\/bluez//g' META-INF/com/google/android/update-script
perl -pi -e 's/set_perm 0 0 0755 SYSTEM:etc\/bluez//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