forked from FlymeOS/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeconfig
executable file
·426 lines (370 loc) · 10.7 KB
/
makeconfig
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/bin/bash
##########################################
#
# author: coron
# usage: used to generate Makefile for an coron project
# date: 2013/11/21
#
##########################################
TAG="makeconfig"
WORK_DIR=$PWD
NEW_MAKEFILE=$WORK_DIR/Makefile
MAKECONFIG_ROOT=$PORT_ROOT/tools/config
DENSITY_CFG=$MAKECONFIG_ROOT/density.cfg
TEMPLATE_MAKEFILE=$MAKECONFIG_ROOT/Makefile.template
VENDOR_MODIFY_JARS_SUGGEST="framework|services|telephony-common|wifi-service|android.policy"
VENDOR_SAVED_APPS_SUGGEST="MtkBt|FMTransmitter|FMRadio|Bluetooth|FmRadio|.*Stk.*|Nfc"
PULL_BOOT_RECOVERY=pull_boot_recovery
GIT_IGNORE_CONFIG=$MAKECONFIG_ROOT/gitignore.template
PRJ_GIT_IGNORE=$WORK_DIR/.gitignore
FROM_OTA=0
OTA_PACKAGE=$WORK_DIR/ota.zip
OUT=$WORK_DIR/out
OUT_OTA_DIR=$OUT/ota
OUT_SYSTEM=$OUT_OTA_DIR/system/
OUT_METAINF=$OUT_OTA_DIR/META-INF
DENSITY=""
RESOLUTION=""
vendor_modify_jars=""
vendor_saved_apps=""
######## Error Exit Num ##########
ERR_USB_NOT_CONNECTED=151
ERR_DEVICE_NOT_ROOTED=152
ERR_MAKEFILE_EXIST=201
ERR_OTA_INCOMPATIBLE=202
ERR_MISSION_FAILED=209
################## adb ######################
# check adb can find a device
function checkAdbConnect()
{
echo ">>> Check connecting state"
adb shell ls /system > /dev/null 2>&1
if [ $? != "0" ];then
echo ">>> Device is not found, Please connect device and pc with USB cable, and open Adb Debug in device."
exit $ERR_USB_NOT_CONNECTED
fi
}
# wait for the device to be online or timeout
function waitForDeviceOnline ()
{
echo ">>> Wait for the device to be online..."
local timeout=30
while [ $timeout -gt 0 ]
do
if adb shell ls /system > /dev/null 2>&1; then
echo ">>> device is online"
break
fi
echo ">>> Device is not online, wait .."
sleep 3
timeout=$[$timeout - 3]
done
if [ $timeout -eq 0 ];then
echo ">>> Device not found, Please ensure adb can find your device and then rerun this script."
exit $ERR_USB_NOT_CONNECTED
fi
}
function checkAdbRoot()
{
echo ">>> Check adb root state"
SECURE_PROP=$(adb shell getprop ro.secure)
DEBUG_PROP=$(adb shell getprop ro.debuggable)
if [ x"$SECURE_PROP" = x"0" -o x"$DEBUG_PROP" = x"1" ];then
echo ">>> Kernel root ready, run adb root"
adb root
waitForDeviceOnline
return 0
fi
return 1
}
function checkSuRoot()
{
echo "exit" > exit_command
waitForDeviceOnline
adb push exit_command /data/local/tmp/
rm -f exit_command
if echo "su < /data/local/tmp/exit_command; exit" | adb shell | grep "not found" > /dev/null 2>&1;then
return 1
fi
return 0
}
# check device connecting state and adb root state
function checkRootState()
{
checkAdbConnect
checkAdbRoot
if [ $? == "0" ];then
echo ">>> Root State: Kernal Root"
return 0
fi
checkSuRoot
if [ $? == "0" ];then
echo ">>> Root State: System Root"
return 0
fi
echo ">>> Device is not a root phone."
exit $ERR_DEVICE_NOT_ROOTED
}
############# set up makefile ################
function checkEnvironment()
{
if [ -f $NEW_MAKEFILE ];then
echo ">>> $NEW_MAKEFILE already exist!"
exit $ERR_MAKEFILE_EXIST
fi
if [ ! -f $TEMPLATE_MAKEFILE ];then
echo ">>> $TEMPLATE_MAKEFILE doesn't exist! "
echo ">>> Make sure you do source ./build/envsetup first!"
exit $ERR_MISSION_FAILED
fi
adb shell ls / > /dev/null 2>&1
if [ $? != 0 -a -f $OTA_PACKAGE ];then
echo ">>> Device is not online, but ota.zip is exist."
echo ">>> Config Makefile from $OTA_PACKAGE."
FROM_OTA=1
fi
}
function checkOTAPackage()
{
echo ">>> Unzip $OTA_PACKAGE ..."
mkdir -p $OUT
rm -rf $OUT_OTA_DIR
unzip -q $OTA_PACKAGE -d $OUT_OTA_DIR
if [ ! -e $OUT_SYSTEM -o ! -e $OUT_METAINF ];then
echo ">>> Can not find $OUT_SYSTEM or $OUT_METAINF."
echo ">>> Check whether $OTA_PACKAGE is a ota package."
exit $ERR_OTA_INCOMPATIBLE
fi
if [ -f $OUT_OTA_DIR/boot.img ];then
cp $OUT_OTA_DIR/boot.img $WORK_DIR/boot.img
fi
if [ -f $OUT_OTA_DIR/recovery.img ];then
cp $OUT_OTA_DIR/recovery.img $WORK_DIR/recovery.img
fi
}
function checkMtkPlatform()
{
if [ $FROM_OTA != 0 ];then
if [ `cat $OUT_SYSTEM/build.prop | grep "mediatek" | wc -l` -gt 0 ]; then
MTK_PLATFORM=true
else
MTK_PLATFORM=false
fi
else
if [ `adb shell cat /system/build.prop | grep "mediatek" | wc -l` -gt 0 ]; then
MTK_PLATFORM=true
else
MTK_PLATFORM=false
fi
fi
echo ">>> Check MTK Platform: $MTK_PLATFORM"
}
function getResolution()
{
if [ $FROM_OTA != 0 ];then
echo ">>> Set Resolution as default"
RESOLUTION="720x1280"
return 0
fi
RESOLUTION=$(adb shell wm size \
| awk 'BEGIN{FS=": "}{print $NF}' | head -1)
}
function getDensity()
{
if [ $FROM_OTA != 0 ];then
echo ">>> Set Density as default"
DENSITY="xhdpi"
return 0
fi
lcd_density=$(adb shell getprop \
| grep "ro.sf.lcd_density" \
| awk 'BEGIN{FS="["}{print $NF}' \
| awk 'BEGIN{FS="]"}{print $1}')
if [ $? == "0" ] && [ "x$lcd_density" != "x" ];then
density=$(grep "$lcd_density" $DENSITY_CFG | cut -d ':' -f2)
if [ $? == "0" ] && [ "x$density" != "x" ];then
DENSITY=$density
fi
fi
}
function getVendorModifyJars()
{
frameworkListFile=$(mktemp -t -u frameworkList.XXXX)
if [ $FROM_OTA == 0 ];then
adb shell "if [ -f /data/local/tmp/framework-list ]; then rm /data/local/tmp/framework-list; fi"
adb shell "ls /system/framework/ > /data/local/tmp/framework-list"
adb pull /data/local/tmp/framework-list $frameworkListFile > /dev/null 2>&1
else
ls $OUT_SYSTEM/framework > $frameworkListFile
fi
if [ -e $frameworkListFile ]; then
vendor_modify_jars=$(grep "\.jar" $frameworkListFile \
| sed "s/\.jar//g" \
| egrep $VENDOR_MODIFY_JARS_SUGGEST \
| sed ":a;N;s/\n/ /g;ba")
rm $frameworkListFile
else
return 1
fi
}
function getConfigValueFromMakefile()
{
local makefile=$1
local prop=$2
local result_line_count
local base
if [ ! -f $makefile ];then
echo ">>> $makefile doesn't exist!!";
return 1
fi
# get the base rom type of project
# if you doesn't config BOARD_BASE_DEVICE_PROP_NAME in project's makefile, just ignore this project
# if you config more than one BOARD_BASE_DEVICE_PROP_NAME in project's makefile, exit with error
result_line_count=`grep "^[ ]*$prop" $makefile -w | wc | awk '{print $1}'`
if [ $result_line_count = "0" ];then
echo ">>> $makefile's $prop does't config!!";
return 1
elif [ $result_line_count != "1" ];then
echo ">>> $makefile's $prop define is wrong!!";
exit $ERR_MISSION_FAILED;
else # $result_line_count == "1"
base=`grep "^[ ]*$prop" $makefile -w \
| awk -F= '{print $NF}' | sed 's/^ *//g;s/$ *//g'`
if [ $? != "0" ] || [ "x$base" = "x" ];then
echo ">>> Can't get base from $makefile"
echo ">>> Make sure \"$prop\" in $makefile is right"
return 1;
fi
echo "$base"
return 0
fi
}
function getvendorSavedApps()
{
appListFile=$(mktemp -t -u appList.XXXX)
if [ $FROM_OTA == 0 ];then
adb shell "if [ -f /data/local/tmp/app-list ]; then rm /data/local/tmp/app-list; fi"
adb shell "ls /system/app/ > /data/local/tmp/app-list"
adb shell "ls /system/priv-app/ >> /data/local/tmp/app-list"
adb pull /data/local/tmp/app-list $appListFile > /dev/null 2>&1
else
ls $OUT_SYSTEM/app/ > $appListFile
ls $OUT_SYSTEM/priv-app/ >> $appListFile
fi
vendor_saved_apps_configed=$(getConfigValueFromMakefile $NEW_MAKEFILE "vendor_saved_apps")
if [ $? == "0" ] && [ "x$vendor_saved_apps_configed" != "x" ];then
vendor_saved_apps_configed=$(echo $vendor_saved_apps_configed \
| sed 's/^[ \t]*//g' \
| sed 's/[ \t]*$//g' \
| sed 's/[ \t][ \t]*/ /g' \
| sed 's/ /\|/g')
vendor_saved_apps_suggest=$VENDOR_SAVED_APPS_SUGGEST
if [ "x$vendor_saved_apps_configed" != "x" ];then
vendor_saved_apps_suggest="$vendor_saved_apps_suggest|$vendor_saved_apps_configed"
fi;
if [ -e $appListFile ]; then
vendor_saved_apps=$(cat $appListFile \
| egrep $vendor_saved_apps_suggest \
| sed ":a;N;s/\n/ /g;ba")
rm $appListFile
else
return 1
fi
fi
}
function getSystemType()
{
if [ $FROM_OTA == 0 ];then
if [ x"$(adb shell getprop ro.build.ab_update)" = x"true" ]; then
echo ">>> Is A/B System Device"
is_ab_update="true"
fi
fi
}
function setupMakefile()
{
echo ">>> Setup the Makefile Begin!"
cp $TEMPLATE_MAKEFILE $NEW_MAKEFILE
getVendorModifyJars
if [ $? == "0" ] && [ "x$vendor_modify_jars" != "x" ]; then
echo ">>> Set vendor_modify_jars: $vendor_modify_jars"
sed -i "s/^[ \t]*vendor_modify_jars[ \t]*\:.*/vendor_modify_jars \:\= $vendor_modify_jars/g" $NEW_MAKEFILE
else
echo ">>> Get the files list in /system/framework failed! "
echo ">>> Please check the adb is ok! "
exit $ERR_MISSION_FAILED
fi
getDensity
if [ "x$DENSITY" != "x" ]; then
echo ">>> Set DENSITY: $DENSITY"
sed -i "s/^[ \t]*DENSITY[ \t]*\:.*/DENSITY \:\= $DENSITY/g" $NEW_MAKEFILE
fi
getResolution
if [ "x$RESOLUTION" != "x" ];then
echo ">>> Set RESOLUTION: $RESOLUTION"
sed -i "s/^[ \t]*RESOLUTION[ \t]*\:.*/RESOLUTION \:\= $RESOLUTION/g" $NEW_MAKEFILE
fi
getvendorSavedApps
if [ "x$vendor_saved_apps" != "x" ]; then
echo ">>> Set vendor_saved_apps: $vendor_saved_apps"
sed -i "s/^[ \t]*vendor_saved_apps[ \t]*\:.*/vendor_saved_apps \:\= $vendor_saved_apps/g" $NEW_MAKEFILE
fi
getSystemType
if [ "x$is_ab_update" != "x" ]; then
echo ">>> Set PRODUCE_IS_AB_UPDATE: $is_ab_update"
sed -i "s/^[ \t]*#PRODUCE_IS_AB_UPDATE[ \t]*\:.*/PRODUCE_IS_AB_UPDATE \:\= $is_ab_update/g" $NEW_MAKEFILE
fi
echo "===================================================="
echo "Makefile Configuration:"
echo " vendor_modify_jars := $vendor_modify_jars"
echo " vendor_saved_apps := $vendor_saved_apps"
echo " DENSITY := $DENSITY"
echo " RESOLUTION := $RESOLUTION"
echo " PRODUCE_IS_AB_UPDATE := $is_ab_update"
echo "===================================================="
echo ">>> Setup the Makefile Done!"
}
############ init gitignore ###########
function initGitIgnore()
{
if [ -f $GIT_IGNORE_CONFIG ] && [ ! -f $PRJ_GIT_IGNORE ]; then
cp $GIT_IGNORE_CONFIG $PRJ_GIT_IGNORE
fi
}
############ pull boot and recovery ###########
function prepare_boot_recovery()
{
if [ ! -f $WORK_DIR/recovery.img ] && [ ! -f $WORK_DIR/recovery.fstab ]; then
pullTmp=`mktemp -d`
echo "Pull boot and recovery, It may take a few minutes, please wait...."
$PULL_BOOT_RECOVERY $pullTmp > /dev/null 2>&1
if [ -f $pullTmp/recovery.img ]; then
mv $pullTmp/recovery.img $WORK_DIR/recovery.img
fi
if [ -f $pullTmp/boot.img ] && [ ! -f $WORK_DIR/boot.img ] ; then
mv $pullTmp/boot.img $WORK_DIR/boot.img
fi
rm -rf $pullTmp
fi
}
############ make new project ###############
# start a new project
function newMakefile()
{
checkRootState
setupMakefile
#prepare_boot_recovery
initGitIgnore
}
function newMakefileFromOTA()
{
checkOTAPackage
setupMakefile
initGitIgnore
}
checkEnvironment
if [ $FROM_OTA == 0 ];then
newMakefile
else
newMakefileFromOTA
fi