forked from dsixda/Android-Kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_busybox_to_update_script
More file actions
executable file
·189 lines (148 loc) · 7.01 KB
/
add_busybox_to_update_script
File metadata and controls
executable file
·189 lines (148 loc) · 7.01 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
############################################################################
#
# 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.
#
############################################################################
#
# This script has one optional parameter:
#
# $1 = 'override' - add the busybox info to the update-script no matter what
# = 'amend' - use the installbusybox file, which is supported by update-script
# - use this only when ROM is being built with update-script
#
#
# Don't add 'installbusybox' script if going to convert to updater-script when
# buiding ROM; it's too much clutter -- use the installation command directly.
#
# The installation command uses 'run_program' and a set of arguments, which
# would only work with an updater-script. On the other hand, the update-
# script uses the 'installbusybox' script, which is executed by run_program
# but requires no arguments.
#
if [ "$1" == "amend" ]
then
convert_to_edify=0
else
convert_to_edify=1
fi
cd WORKING_*
cd META-INF/com/google/android
echo
if [ -e update-script ]
then
if [ "$convert_to_edify" == "0" ]
then
# Exit if all busybox symlinks already exist in update-script, or a
# busybox installer script exists in base dir of working folder
if [ "`grep -c \"symlink busybox\" update-script`" != "0" ] || \
[ "`grep -m 1 \"busybox ln\" ../../../../*`" != "" ] || \
[ "`grep -m 1 \"busybox --install\" ../../../../*`" != "" ]
then
cd ../../../../..
exit 0
fi
#
# Remove existing busybox references in update-script
#
search_run=`grep -c "run_program.*xbin/busybox --install" update-script`
search_perm=`grep -c "set_perm.*xbin/busybox" update-script`
search_symlinks=`grep -c "symlink.*xbin/busybox " update-script`
if [ $search_run -gt 0 ] || [ $search_perm -gt 0 ] || [ $search_symlinks -gt 0 ]
then
echo "Removing existing references to /system/xbin/busybox in update-script"
sed -i \
-e '/set_perm.*xbin\/busybox/d' \
-e '/symlink.*xbin\/busybox/d' \
-e '/run_program.*xbin\/busybox --install/d' \
update-script
fi
echo "Adding installbusybox to working folder"
cp ../../../../../tools/busybox_files/installbusybox ../../../../
echo "Adding installbusybox to update-script"
if [ `grep -c "set_perm_recursive.*SYSTEM:xbin[ ]*$" update-script` != 0 ]
then
sed -i -e 's/set_perm_recursive\(.*\)SYSTEM:xbin[ ]*$/set_perm_recursive\1SYSTEM:xbin\nset_perm 0 1000 0755 SYSTEM:xbin\/busybox\nrun_program PACKAGE:installbusybox\n/' update-script
elif [ `grep -c "init.goldfish.sh" update-script` != 0 ]
then
sed -i -e 's/set_perm 0 2000 0550 SYSTEM:etc\/init.goldfish.sh/set_perm 0 2000 0550 SYSTEM:etc\/init.goldfish.sh\nset_perm 0 1000 0755 SYSTEM:xbin\/busybox\nrun_program PACKAGE:installbusybox/g' update-script
elif [ `grep -c "write_raw_image .*:boot.img BOOT:" update-script` != 0 ]
then
sed -i -e 's/write_raw_image \(.*:boot.img\) BOOT:/set_perm 0 1000 0755 SYSTEM:xbin\/busybox\nrun_program PACKAGE:installbusybox\nwrite_raw_image \1 BOOT:/' update-script
else
echo "set_perm 0 1000 0755 SYSTEM:xbin/busybox" >> update-script
echo "run_program PACKAGE:installbusybox" >> update-script
fi
if [ `grep -c installbusybox update-script` == 0 ]
then
echo "Error: installbusybox not added to update-script!"
else
if [ ! -e ../../../../system/bin/busybox ]
then
echo "Adding symlink to /system/bin/busybox"
sed -i -e 's/set_perm 0 1000 0755 SYSTEM:xbin\/busybox/set_perm 0 1000 0755 SYSTEM:xbin\/busybox\nsymlink \/system\/xbin\/busybox SYSTEM:bin\/busybox/g' update-script
fi
fi
######################################################################
# The update-script will be converted to updater-script when built
######################################################################
elif [ "$convert_to_edify" == "1" ]
then
# Remove the installbusybox script with just a single call in the updater-script (which
# is not compatible with update-scripts)
if [ -e ../../../../installbusybox ]
then
echo "Removing existing references to BusyBox and installbusybox in update-script"
sed -i \
-e '/set_perm.*bin\/busybox/d' \
-e '/symlink.*bin\/busybox/d' \
-e '/run_program.*installbusybox/d' \
update-script
if [ -e ../../../../installbusybox ]
then
echo "Removing installbusybox"
rm -f ../../../../installbusybox
fi
echo
elif [[ "$1" != "override" ]] && [[ `grep -c "symlink busybox" update-script` != 0 || `grep -c "symlink /system/xbin/busybox " update-script` != 0 ]]
then
echo "update-script already has BusyBox content"
elif [[ "$1" != "override" ]] && [[ "`grep -m 1 \"busybox ln\" ../../../../* 2>/dev/null`" != "" || "`grep -m 1 \"busybox --install\" ../../../../* 2>/dev/null`" != "" ]]
then
echo "A script containing BusyBox symlinks was detected"
echo "No changes to update-script required"
else
echo "Adding BusyBox install command to update-script"
if [ `grep -c "set_perm_recursive.*SYSTEM:xbin[ ]*$" update-script` != 0 ]
then
sed -i -e 's/set_perm_recursive\(.*\)SYSTEM:xbin[ ]*$/set_perm_recursive\1SYSTEM:xbin\nset_perm 0 1000 0755 SYSTEM:xbin\/busybox\nrun_program PACKAGE:system\/xbin\/busybox --install -s SYSTEM:xbin\n/' update-script
elif [ `grep -c "init.goldfish.sh" update-script` != 0 ]
then
sed -i -e 's/set_perm 0 2000 0550 SYSTEM:etc\/init.goldfish.sh/set_perm 0 2000 0550 SYSTEM:etc\/init.goldfish.sh\nset_perm 0 1000 0755 SYSTEM:xbin\/busybox\nrun_program PACKAGE:system\/xbin\/busybox --install -s SYSTEM:xbin\n/g' update-script
elif [ `grep -c "write_raw_image .*:boot.img BOOT:" update-script` != 0 ]
then
sed -i -e 's/write_raw_image \(.*:boot.img\) BOOT:/set_perm 0 1000 0755 SYSTEM:xbin\/busybox\nrun_program PACKAGE:system\/xbin\/busybox --install -s SYSTEM:xbin\nwrite_raw_image \1 BOOT:/' update-script
else
echo "set_perm 0 1000 0755 SYSTEM:xbin/busybox" >> update-script
echo "run_program PACKAGE:system\/xbin\/busybox --install -s SYSTEM:xbin" >> update-script
fi
if [ `grep -c "busybox --install -s" update-script` == 0 ]
then
echo "Error: BusyBox not added to update-script!"
else
if [ ! -e ../../../../system/bin/busybox ]
then
echo "Adding symlink to /system/bin/busybox"
sed -i -e 's/set_perm 0 1000 0755 SYSTEM:xbin\/busybox/set_perm 0 1000 0755 SYSTEM:xbin\/busybox\nsymlink \/system\/xbin\/busybox SYSTEM:bin\/busybox/g' update-script
fi
fi
fi
fi
else
echo "Error: No update-script found!"
fi
cd ../../../../..
scripts/fix_update_script_blanks