-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_cm
executable file
·470 lines (442 loc) · 11 KB
/
build_cm
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#!/bin/bash
# Menu to maintain and build CM.
# Written by tristan202. Feel free to use, modify and distribute the script.
# Just remember to give proper credit
#
# tristan202 [ad] gmail.com
me=`basename $0`
# Colorize and add text parameters
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldgrn=${txtbld}$(tput setaf 2) # green
bldblu=${txtbld}$(tput setaf 4) # blue
txtrst=$(tput sgr0) # Reset
line='----------------------------------------'
# Make sure to add a model name
if [ "$#" == "0" ]; then
echo ""
echo "Usage: $me {Model name, i.e. yuga|maguro}"
exit 1
fi
# A few variables
CM=$HOME/android/cm11
DEVICE=$1
OUT=$CM/out/target/product/$DEVICE
TRISTAN202=$HOME/android/tristan202
# Current time
NOWFULL=$(date +%b-%d-%Y-%H.%M)
NOWDATE=$(date +%b-%d-%Y)
# Rename the Guake tab, end enable numlock
guake -r CM-11
if [ -x /usr/bin/numlockx ]; then
/usr/bin/numlockx on
fi
Output() {
echo "${bldgrn}$(date -d "1970-01-01 UTC $2 seconds") - $1 $OPERATION""ing $3${txtrst}"
}
Duration() {
local S=$(echo $FINISH_TIME $BEGIN_TIME | awk '{print$1-$2}')
((h=S/3600))
((m=S%3600/60))
((s=S%60))
printf "$OPERATION""ing took: %dh:%dm:%ds\n" $h $m $s
}
Begin() {
BEGIN_TIME=$(date +%s)
Output Begin $BEGIN_TIME "$1"
}
Finish() {
FINISH_TIME=$(date +%s)
Output Finished $FINISH_TIME "$1"
Duration
}
Init_Repo ()
{
clear
if [ ! -d $CM ]; then
echo ""
echo "${bldblu}Setting up CM repo...${txtrst}"
mkdir $CM
fi
if [ ! -d ~/bin ]; then
mkdir ~/bin
PATH=~/bin:$PATH
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
fi
if [ ! -f ~/bin/repo ]; then
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
fi
cd $CM && repo init -u git://github.com/CyanogenMod/android.git -b cm-11.0
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
Main
}
Start_Sync ()
{
clear
if [ -d $CM ]; then
echo ""
OPERATION="Sync"
Begin
echo ""
echo "${bldblu}Syncing repo...${txtrst}"
cd $CM && repo sync
echo ""
Finish
else
echo ""
echo "${bldred}Directory does not exist. Check your 'CM' variable in line 5.${txtrst}"
echo ""
exit 0
fi
Sync_End
}
Sync_End ()
{
echo ""
echo "${bldblu}Got any cherries to pick?${txtrst}"
echo -n "Press [${bldgrn}Y${txtrst}] if you do, or [${bldred}N${txtrst}] to return to main menu."
echo ""
read -n1 char
case "$char" in
[Nn]) Main ;;
[Yy]) Pick_Cherries ;;
*) clear && echo "" && Sync_End ;;
esac
}
Start_Build ()
{
clear
OPERATION="Build"
files=$(ls $OUT/*.zip* 2> /dev/null | wc -l)
if [ "$files" != "0" ]; then
echo "${bldblu}Previous builds detected in 'out' folder. Delete them now?${txtrst}"
echo -n "Press [${bldgrn}Y${txtrst}] to delete them, or [${bldred}N${txtrst}] to start build without deleting them."
echo ""
read -n1 char
case "$char" in
[Nn]) Build ;;
[Yy]) rm $OUT/*.zip* ;;
*) Start_Build ;;
esac
fi
Build
}
Build ()
{
clear
echo ""
echo "${bldblu}Good, starting build...${txtrst}"
Begin
if [ ! -f $CM/vendor/cm/proprietary/lib/armeabi/libjackpal-androidterm4.so ] && [ ! -f $CM/vendor/cm/proprietary/lib/mips/libjackpal-androidterm4.so ] && [ ! -f $CM/vendor/cm/proprietary/lib/x86/libjackpal-androidterm4.so ]; then
$CM/vendor/cm/get-prebuilts
fi
cd $CM
rm -rf out/target/product/$DEVICE/system/build.prop
wait
echo ""
echo "${bldblu}Setting up environment${txtrst}"
echo ""
. build/envsetup.sh
wait
echo ""
echo "${bldblu}Brunching device${txtrst}"
echo ""
brunch $DEVICE -j2
Finish
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
Main
}
Reboot_Bootloader ()
{
clear
echo ""
echo "${bldblu}Rebooting to bootloader. Happy flashing.${txtrst}"
if pidof -x adb > /dev/null
then
echo "ADB server already running, proceeding."
sleep 2
else
adb start-server
fi
adb reboot bootloader
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
adb kill-server
Main
}
Start_Clobber ()
{
clear
echo ""
echo "${bldblu}Cleaning build directory...${txtrst}"
OPERATION="Clean"
Begin
cd $CM
make clobber
Finish
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
Main
}
Pick_Cherries ()
{
clear
echo ""
echo "${bldblu}Picking cherries...${txtrst}"
OPERATION="Cherrypick"
tput cnorm
echo ""
echo "${bldblu}Copy/paste the project folder, i.e. 'frameworks/base'${txtrst}"
echo -n ">" && read folder
echo ""
echo "${bldblu}Now paste the cherry-pick git link, i.e. 'git fetch <someproject> refs/changes/... && git cherry-pick FETCH_HEAD'${txtrst}"
echo -n ">" && read cherry
clear
echo ""
Begin
cd $CM/$folder
CHERRY=${cherry%%??????????????????????????????}
$CHERRY && git cherry-pick FETCH_HEAD
Finish
echo ""
echo "${bldblu}Got any more cherries to pick?${txtrst}"
echo -n "Press [${bldgrn}Y${txtrst}] if you do, or [${bldred}N${txtrst}] to return to main menu."
echo ""
read -n1 char
case "$char" in
[Nn]) Main ;;
[Yy]) Pick_Cherries ;;
*) Pick_Cherries ;;
esac
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
Main
}
Start_Push ()
{
clear
echo "If you haven't done so already, connect your phone to usb now."
read -p "${bldblu}Press [Enter] to continue...${txtrst}"
echo ""
if pidof -x adb > /dev/null
then
echo "ADB server already running, proceeding."
sleep 2
else
adb start-server
fi
DEVICES=$(adb get-state)
if [ $DEVICES == "device" ]; then
FILE=$(find $OUT -type f -name "cm-11*.zip" -printf %f)
for zip in $FILE
do
echo "${bldblu}$line${txtrst}"
echo ""
echo "Push to internal or external?"
echo ""
echo " ${bldblu}1${txtrst} Internal (/sdcard)"
echo " ${bldblu}2${txtrst} External (/ext_card)"
echo ""
echo "${bldblu}$line${txtrst}"
echo -n "${bldblu} "
read -n1 answer
echo "${txtrst}"
case "$answer" in
[1]) Push_Int ;;
[2]) Push_Ext ;;
*) Start_Push ;;
esac
done
else
echo ""
echo "${bldred}Are you completely sure you remembered to plug in both ends of the cable?${txtrst}"
read -p "${bldblu}Press [Enter] to try again...${txtrst}"
Start_Push
fi
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
Main
}
Push_Int ()
{
FILE=$(find $OUT -type f -name "cm-11*.zip" -printf %f)
for zip in $FILE
do
clear
OPERATION="Push"
Begin
echo ""
echo "Pushing '$zip' to /sdcard/cm-unofficial-$NOWDATE-tristan202.zip"
adb push $OUT/$zip /sdcard/cm-unofficial-$NOWDATE-tristan202.zip
Finish
done
}
Push_Ext ()
{
FILE=$(find $OUT -type f -name "cm-11*.zip" -printf %f)
for zip in $FILE
do
clear
OPERATION="Push"
Begin
echo ""
echo "Pushing '$zip' to /ext_card/cm-unofficial-$NOWDATE-tristan202.zip"
adb push $OUT/$zip /ext_card/cm-unofficial-$NOWDATE-tristan202.zip
Finish
done
}
Reboot_Recovery ()
{
clear
echo ""
echo "${bldblu}Rebooting to recovery. Happy flashing.${txtrst}"
if pidof -x adb > /dev/null
then
echo "ADB server already running, proceeding."
sleep 2
else
adb start-server
fi
adb reboot recovery
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
adb kill-server
Main
}
Ask_Clobber ()
{
while true
do
clear
echo ""
echo "${bldblu}Are you sure you want to do this? It is rarely needed...${txtrst}"
echo ""
echo -n "Press [${bldred}Y${txtrst}] to continue, or [${bldgrn}N${txtrst}] to return to main menu."
read -n1 char
case "$char" in
[Nn]) Main ;;
[Yy]) Start_Clobber ;;
*) Ask_Clobber ;;
esac
done
}
Get_Prebuilts ()
{
clear
echo ""
echo "${bldblu}Getting prebuilts. This only needs to be done once...${txtrst}"
echo ""
OPERATION="Gett"
Begin
$CM/vendor/cm/get-prebuilts
Finish
read -p "${bldblu}Press [Enter] to return to menu...${txtrst}"
Main
}
Logcat_Menu ()
{
clear
while true
do
clear
echo "${bldblu}$line${txtrst}"
echo "Logcat menu"
echo ""
echo "To stop the logcat, press ctrl+z"
echo "The name of the logfile will be"
echo "~/logcat-<time-date>.log"
echo ""
echo "Select from the following functions"
echo ""
echo " ${bldblu}1${txtrst} Logcat to file"
echo " ${bldblu}2${txtrst} Live logcat"
echo "${bldblu}$line${txtrst}"
echo -n " "
read -n1 answer
case "$answer" in
[1]) clear && adb logcat >> ~/logcat-$NOWFULL.log;;
[2]) clear && adb logcat -C;;
esac
done
exit 0
}
Reboot_Menu ()
{
clear
while true
do
clear
echo "${bldblu}$line${txtrst}"
echo "Reboot menu"
echo ""
echo "Select from the following functions"
echo ""
echo " ${bldblu}1${txtrst} Reboot"
echo " ${bldblu}2${txtrst} Reboot to recovery"
echo " ${bldblu}3${txtrst} Reboot to bootloader"
echo " ${bldblu}4${txtrst} Return to main menu"
echo "${bldblu}$line${txtrst}"
echo -n " "
read -n1 answer
case "$answer" in
[1]) adb reboot && Main;;
[2]) Reboot_Recovery;;
[3]) Reboot_Bootloader;;
[4]) Main;;
esac
done
exit 0
}
Main ()
{
clear
while true
do
clear
echo "${bldblu}$line${txtrst}"
echo "CM maintenance and build script"
echo ""
echo "Building ${bldblu}CM-11${txtrst} for ${bldblu}$DEVICE${txtrst}"
echo ""
echo "Select from the following functions"
echo ""
if [ ! -f $CM/.repo/manifest.xml ]; then
echo " ${bldgrn}S${txtrst} Set up CM 11 repo"
fi
echo " ${bldblu}1${txtrst} Sync CM 11 repo"
if [ ! -f $CM/vendor/cm/proprietary/lib/armeabi/libjackpal-androidterm4.so ] && [ ! -f $CM/vendor/cm/proprietary/lib/mips/libjackpal-androidterm4.so ] && [ ! -f $CM/vendor/cm/proprietary/lib/x86/libjackpal-androidterm4.so ]; then
echo " ${bldblu}P${txtrst} Get CM prebuilts"
fi
echo " ${bldblu}2${txtrst} Build CM 11"
echo " ${bldblu}3${txtrst} Push finished build to device"
echo " ${bldblu}4${txtrst} Reboot menu"
echo " ${bldblu}5${txtrst} Pick cherries"
echo " ${bldblu}6${txtrst} View the CM Gerrit"
echo " ${bldblu}L${txtrst} Logcat"
echo " ${bldred}C${txtrst} Clean build directory"
echo " ${bldblu}X${txtrst} Exit"
echo "${bldblu}$line${txtrst}"
tput civis
echo -n " "
read -n1 answer
case "$answer" in
[Ss]) Init_Repo;;
[1]) Start_Sync;;
[2]) Start_Build;;
[3]) Start_Push;;
[4]) Reboot_Menu;;
[5]) Pick_Cherries;;
[6]) xdg-open http://review.cyanogenmod.org/#/q/status:merged+branch:cm-11,n,z ;;
[Cc]) Ask_Clobber;;
[Pp]) Get_Prebuilts;;
[Ll]) Logcat_Menu;;
[Xx]) clear
adb kill-server
echo "${bldblu}Live long and prosper... tristan202${txtrst}"
echo ""
tput cnorm
if [ -x /usr/bin/numlockx ]; then
/usr/bin/numlockx off
fi
break ;;
esac
done
exit 0
}
Main