forked from ScriBt/ScriBt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROM.sh
executable file
·2475 lines (2344 loc) · 97.2 KB
/
ROM.sh
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#========================< Projekt ScriBt >============================#
#=========< Copyright 2016-2017, Arvindraj Thangaraj - "a7r3" >========#
#======================================================================#
# #
# This software is licensed under the terms of the GNU General Public #
# License version 3, as published by the Free Software Foundation, and #
# may be copied, distributed, and modified under those terms. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License [LICENSE file in this repository] for #
# more details. #
# #
#======================================================================#
# #
# https://github.com/a7r3/ScriBt - I live here #
# #
# Feel free to enter your modifications and submit it to me with #
# a Pull Request, Contributions are WELCOME #
# #
# Contributors: #
# Arvindraj Thangaraj (a7r3/Arvind7352) #
# Adrian DC (AdrianDC) #
# Akhil Narang (akhilnarang) #
# Caio Oliveira (Caio99BR) #
# Łukasz "JustArchi" Domeradzki #
# Nathan Chancellor (nathanchance/The Flash) #
# Tim Schumacher (TimSchumi) #
# Tom Radtke "CubeDev" #
# nosedive #
#======================================================================#
# Default Maximum Width to be occupied by the Interface #
export NOCHARS_DEF="54"; #
#======================================================================#
function cmdprex() # D ALL
{
# shellcheck disable=SC2001
local ARGS=( $(echo "${@// /#}" | sed -e 's/--out=.*txt//') );
# Argument (Parameter) Array
local ARG=( ${ARGS[*]/*<->/NULL} );
# Argument Description Array
local ARGD=( ${ARGS[*]/<->*/} );
# Splash some colors!
center_it "${CL_YEL}[!]${NONE} Command Execution ${CL_YEL}[!]${NONE}" "1eq1";
for (( CT=0; CT<${#ARG[*]}; CT++ )); do
if [[ $(eval "echo \${ARG[${CT}]}") != "NULL" ]]; then
echo -en "\033[1;3${CT}m$(eval "echo \${ARG[${CT}]}") " | sed -e 's/NULL//g' -e 's/execroot/sudo/g' -e 's/#/ /g';
fi
done
echo -e "\n";
for (( CT=0; CT<${#ARGD[*]}; CT++ )); do
if [[ $(eval "echo \${ARG[${CT}]}") != "NULL" ]]; then
echo -en "\033[1;3${CT}m$(eval "echo \${ARGD[${CT}]}")\033[0m\n" | sed 's/#/ /g';
fi
done
# Give some time for the user to read it
pause "4";
echo;
[[ "$1" =~ --out=* ]] && local TEE="2>&1 | tee -a ${1/*=/}";
local CMD=$(echo "${ARG[*]} ${TEE}" | sed -e 's/NULL//g' -e 's/#/ /g');
# Execute the command
if eval "${CMD}"; then
echo -e "\n${SCS} Command Execution Successful";
unset STS;
else
echo -e "\n${FLD} Command Execution Failed";
STS="1";
fi
unset -v CT i;
dash_it;
} # cmdprex
function cherrypick() # Automated Use only
{
echo -ne '\033]0;ScriBt : Picking Cherries\007';
center_it "${CL_LRD}Pick those Cherries${NONE}" "1eq";
echo -e "\n${ATBT} Attempting to Cherry-Pick Provided Commits\n";
cd "${CALL_ME_ROOT}$1" || exitScriBt 1;
git fetch ${2/\/tree\// };
git cherry-pick "$3";
cd "${CALL_ME_ROOT}";
echo -e "\n${INF} It's possible that the pick may have conflicts. Solve those and then continue.";
dash_it;
} # cherrypick
function interrupt() # ID
{
cd "${CALL_ME_ROOT}";
echo -e "\n\n*** Ouch! Plz don't kill me! ***";
exitScriBt 0;
} # interrupt
function exitScriBt() # ID
{
function prefGen()
{
echo -e "\n${EXE} Saving Current Configuration";
echo -e "\n${QN} Name of the Config\n${INF} Default : ${ROMNIS:-scribt}_${SBDEV:-config}\n";
prompt NOC --no-repeat;
[[ -z "$NOC" ]] && NOC="${ROMNIS:-scribt}_${SBDEV:-config}";
if [[ -f "${NOC}.rc" ]]; then
echo -e "\n${FLD} Configuration ${NOC} exists";
echo -e "\n${QN} Overwrite it ${YES_NO}";
prompt OVRT;
case "$OVRT" in
[Yy]) echo -e "\n${EXE} Deleting ${NOC}"; rm -rf "${NOC}.rc" ;;
[Nn]) prefGen ;;
esac
unset OVRT;
fi
{
echo -e "# ScriBt Automation Config File";
echo -e "# ${ROM_FN} for ${SBDEV:-"Some Device"}\nAUTOMATE=\"true_dat\"\n";
echo -e "#################\n# Information #\n#################\n\n";
cat varlist;
echo -e "\n\n#################\n# Sequencing #\n##################\n";
echo -e "# Your Code goes here\n\ninit;\nsync;\npre_build;\nbuild;\n\n# Some moar code eg. Uploading the ROM";
} >> "${NOC}.rc";
echo -e "\n${SCS} Configuration file ${NOC} created successfully";
echo -e "\n${INF} You may modify the config, and automate ScriBt next time";
unset NOC;
} # prefGen
if type patcher &>/dev/null; then # Assume the patchmgr was used if this function is loaded
if show_patches | grep -q '[Y]'; then # Some patches are still applied
echo -e "\n${SCS} Applied Patches detected";
echo -e "\n${QN} Do you want to reverse them ${YES_NO}\n";
prompt ANSWER;
[[ "$ANSWER" == [Yy] ]] && patcher;
unset ANSWER;
fi
fi
# Fetching ScriBt variables
set -o posix;
set > "${TV2}";
diff "${TV1}" "${TV2}" | grep SB | sed -e 's/[<>] //g' > varlist;
while read -r line; do
VARS="${VARS}${line//=*/} ";
done <<< "$(cat varlist)";
if [[ "${REQ_CONFIG_GEN}" == [Yy] ]]; then
prefGen;
fi
rm -f varlist;
echo -e "\n${EXE} Unsetting all variables";
unset ${VARS:-SB2} VARS REQ_CONFIG_GEN;
if [[ ! -z "${ACTIVE_VENV}" ]]; then
stop_venv;
fi
echo -e "\n${SCS:-[:)]} Thanks for using ScriBt.\n";
if [[ "$1" == "0" ]]; then
if ! sign_exists "\u2764"; then SIGN="<3"; fi;
echo -e "${CL_LGN}[${NONE}${CL_LRD}${SIGN}${NONE}${CL_LGN}]${NONE} Peace! :)\n";
else
echo -e "${CL_LRD}[${NONE}${CL_RED}<${NONE}${CL_LGR}/${NONE}${CL_RED}3${NONE}${CL_LRD}]${NONE} Failed somewhere :(\n";
fi
rm -f "${TV1}" "${TV2}" "${TMP}";
[[ -f "${PATHDIR}update_message.txt" ]] && rm "${PATHDIR}update_message.txt";
[[ -s "${STMP}" ]] || rm "${STMP}"; # If temp_sync.txt is empty, delete it
[[ -s "${RMTMP}" ]] || rm "${RMTMP}"; # If temp_compile.txt is empty, delete it
exit "$1";
} # exitScriBt
function get_rom_info()
{
# Get ROM's info, if user directly starts sync
cd "${CALL_ME_ROOT}.repo/manifests";
local RNM=$(git config --get remote.origin.url | awk -F "/" '{print $4}');
cd ${CALL_ME_ROOT};
for FILE in ${CAFR[*]} ${AOSPR[*]}; do
if grep -q "${RNM}" "${FILE}"; then
source "${FILE}";
ROM_FN="$(echo ${FILE//.rc/} | awk -F "/" '{print $NF}' | sed -e 's/_/ /g')";
break;
fi
done
unset FILE;
} # get_rom_info
function main_menu()
{
unset ACTION;
echo -ne '\033]0;ScriBt : Main Menu\007';
center_it "${SCS} ${CL_LBL}Main Menu${NONE} ${SCS}" "eq1";
echo -e "1$(center_it "Choose ROM & Init" "sp" "$(( NOCHARS_DEF - 2 ))")1";
echo -e "2$(center_it "Sync" "sp" "$(( NOCHARS_DEF - 2 ))")2";
echo -e "3$(center_it "Pre-Build" "sp" "$(( NOCHARS_DEF - 2 ))")3";
echo -e "4$(center_it "Build" "sp" "$(( NOCHARS_DEF - 2 ))")4";
echo -e "5$(center_it "Various Tools" "sp" "$(( NOCHARS_DEF - 2 ))")5\n";
echo -e "6$(center_it "About ScriBt" "sp" "$(( NOCHARS_DEF - 2 ))")6";
echo -e "7$(center_it "EXIT" "sp" "$(( NOCHARS_DEF - 2 ))")7";
dash_it;
echo -e "\n${QN} Select the Option you want to start with\n";
prompt ACTION;
} # main_menu
function manifest_gen() # D 1,5
{
function add_repo()
{
local lineStart="<project" lineEnd="/>";
local repo_name repo_path repo_revision repo_remote;
echo -e "\n${INF} Please enter the following one by one\n";
echo -e "${INF} Hit Enter if no answer is to be provided (repository name & path CANNOT be blank).";
echo -en "\n${QN} Repository Name : "; prompt repo_name;
echo -en "\n${QN} Repository Path : "; prompt repo_path;
echo -en "\n${QN} Branch : "; prompt repo_revision --no-repeat;
listremotes;
echo -e "\n${QN} Enter the desired remote ${CL_WYT}name${NONE}\n";
prompt repo_remote --no-repeat;
line=( "name=\"${repo_name}\"" "path=\"${repo_path}\"" );
[[ ! -z "${repo_revision}" ]] && line=( "${line[*]}" "revision=\"${repo_revision}\"" );
[[ ! -z "${repo_remote}" ]] && line=( "${line[*]}" "remote=\"${repo_remote}\"" );
if grep -q "${repo_path}" "${MANIFEST}"; then
echo -e "\n${FLD} Another repo has the same checkout path ${CL_WYT}${repo_path}${NONE}";
echo -e "\n${INF} Please try again";
else
line=( "${lineStart}" "${line[*]}" "${lineEnd}" );
echo -e "${line[*]}" >> "${FILE}";
echo -e "\n${SCS} Repository added";
fi
} # add_repo
function remove_repo()
{
local lineStart="<remove-project" lineEnd="/>";
local repo_name;
echo -e "\n${QN} Please enter the Repository Name\n";
prompt repo_name;
if grep -q "${repo_name}" "${MANIFEST}"; then
line=( "${lineStart}" "name=\"${repo_name}\"" "${lineEnd}" );
echo -e "${line[*]}" >> "${FILE}";
echo -e "\n${SCS} Project ${repo_name} removed from manifest";
else
echo -e "\n${FLD} Project ${repo_name} not found. Bailing out.\n";
fi
} # remove_repo
function add_remote()
{
local lineStart="<remote"; local lineEnd="/>";
local remote_name remote_url remote_revision;
echo -e "\n${INF} Please enter the following one by one\n";
echo -e "${INF} If some of them are not needed, hit ENTER key [remote name and remote URL CANNOT be blank]";
echo -en "\n${QN} Remote Name : "; prompt remote_name;
echo -en "\n${QN} Remote Fetch URL : "; prompt remote_url;
echo -en "\n${QN} Revision : "; prompt remote_revision;
for CT in ${REMN[*]}; do
if [[ "${CT}" == "${remote_name}" ]]; then
echo -e "${FLD} Remote ${remote_name} already exists\n";
echo -e "${INF} Try again\n";
break && manifest_gen_menu;
fi
done
line=( "name=\"${remote_name}\"" "fetch=\"${remote_url}\"" );
[[ ! -z "${remote_revision}" ]] && line=( "${line[*]}" "revision=\"${remote_revision}\"" );
line=( "${lineStart}" "${line[*]}" "${lineEnd}" );
echo -e "${line[*]}" >> "${FILE}";
echo -e "\n${SCS} Remote ${remote_name} added";
unset CT;
} # add_remote
function listremotes()
{
echo -en "\n${INF} Following are the list of Remotes\n";
echo -en "\n${INF} ${CL_WYT}Name${NONE}\t${CL_DGR}(Fetch URL)${NONE}\n\n";
for (( CT=0; CT<"${#REMN[*]}"; CT++ )); do
eval "echo -e \${CL_WYT}\${REMN[$CT]} \${CL_DGR}\(\${REMF[$CT]}\)";
echo -e "${NONE}";
done
} # listremotes
function listops()
{
echo -e "\n${INF} Operations Performed\n";
while read -r line; do
eval $(echo $line | sed -e 's/^<.* n/n/g' -e 's/\/>//g');
case "$(echo $line | awk '{print $1}')" in
"<project")
echo -e "${INF} ${CL_LGN}Add${NONE} Project ${CL_WYT}${name}${NONE}\n"
echo -e "${INDENT}Checkout Path : $path";
echo -e "${INDENT}Revision (Branch) : $revision";
echo -e "${INDENT}Remote : $remote\n";
;;
"<remove-project")
echo -e "${INF} ${CL_LRD}Remove${NONE} Project ${CL_WYT}${name}${NONE}\n";
;;
"<remote")
echo -e "${INF} ${CL_WYT}Add${NONE} remote ${CL_WYT}${name}${NONE}";
echo -e "${INDENT}Fetch URL : $fetch";
echo -e "${INDENT}Default Revision (branch) : $revision\n";
;;
esac
unset name path remote revision fetch;
done <<< "$(awk 'f;/<manifest>/{f=1}' ${FILE})";
} # listops
function save_me()
{
echo -e "\n${QN} Provide a name for this manifest [Just the name]\n";
prompt NAME;
echo -e "</manifest>" >> "${FILE}";
if mv -f "${FILE}" ".repo/local_manifests/${NAME}.xml"; then
echo -e "\n${SCS} Custom Manifest successfully saved\n";
else
echo -e "\n${FLD} Couldn't save the manifest";
echo -e "\n${INF} Manually copy ${CL_WYT}file.xml${NONE} to .repo/local_manifests/${NAME}.xml\n";
fi
# Delete intermediate manifest
rm -f "${MANIFEST}";
unset CT NAME;
} # save_me
function manifest_gen_menu()
{
unset OP;
center_it "${CL_LGN}[!]${NONE} ${CL_WYT}Manifest Generator${NONE} ${CL_LGN}[!]${NONE}" "1eq1";
echo -e "1) Add a repository/project";
echo -e "2) Remove a repository/project";
echo -e "3) Add a remote";
echo -e "4) List remotes";
echo -e "5) List performed operations";
echo -e "6) Save Custom Manifest && Return to Quick-Menu";
echo -e "\nTo ${CL_WYT}Replace${NONE} a Repo -> Remove the repo, then add it's replacement";
dash_it;
prompt OP;
unset CT repo_path;
case "${OP}" in
1) add_repo ;;
2) remove_repo ;;
3) add_remote ;;
4) listremotes ;;
5) listops ;;
6) save_me ;;
esac
[[ "$OP" != "6" ]] && manifest_gen_menu;
} # manifest_gen_menu
if [[ ! -d "${CALL_ME_ROOT}.repo" ]]; then
echo -e "\n${FLD} ROM Source not initialized\n";
return 1;
fi
# Grab the manifest
MANIFEST="${CALL_ME_ROOT}manifest.xml";
rm -f "${MANIFEST}";
repo manifest > "${MANIFEST}";
# Our file
FILE="${CALL_ME_ROOT}file.xml";
rm -f "${FILE}";
# `while' equivalent of this loop brings all test cases in ONE line
# And additionally distinguishes each test case by a newline between them
# Not what I wanted (seperate lines), So...
# shellcheck disable=SC2013
for line in $(grep '<remote' "${MANIFEST}" | sed -e 's/<remote//g' -e 's/ /X/g' -e 's/\/>//g'); do
line="${line//X/ }";
eval "$line";
if [[ "${fetch}" == ".." ]]; then
cd "${CALL_ME_ROOT}.repo/manifests";
# Poor awk logic :/, won't burn down the world tho :)
fetch=$(git config --get remote.origin.url | awk -F "/" '{print $1"//"$3}');
cd "${CALL_ME_ROOT}";
fi
REMN+=( "$name" );
REMF+=( "$fetch" );
done
unset line fetch name review revision;
mkdir -p "${CALL_ME_ROOT}.repo/local_manifests/";
touch "${FILE}";
echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<manifest>" > "${FILE}";
manifest_gen_menu;
} # manifest_gen
function it_is_apt() # D pkgmgr_check
{
while read -r path; do
if apt moo &> /dev/null; then
APTPATH="${path}";
fi
done <<< "$(which apt-get)
$(which apt)";
if [[ -z "${APTPATH}" ]]; then
return 1;
else
return 0;
fi
} # it_is_apt
function pkgmgr_check() # ID
{
if which pacman &> /dev/null; then
PKGMGR="pacman";
elif it_is_apt; then
PKGMGR="${APTPATH}";
else
echo -e "${FLD} No supported package manager has been found.";
echo -e "\n${INF} Arch Linux or a Debian/Ubuntu based Distribution is required to run ScriBt.";
exitScriBt 1;
fi
echo -e "\n${SCS} Package manager ${CL_WYT}${PKGMGR//*apt/apt}${NONE} detected.\033[0m";
} # pkgmgr_check
function quick_menu()
{
unset ACTION;
echo -ne '\033]0;ScriBt : Quick Menu\007';
center_it "${CL_PNK}Quick-Menu${NONE}" "1eq";
center_it "1. Init | 2. Sync | 3. Pre-Build | 4. Build | 5. Tools" "sp";
center_it "6. About ScriBt | 7. Exit" "sp";
dash_it "0";
prompt ACTION;
} # quick_menu
function rom_check() # D 1,2,3
{
if ! echo $1 | grep -q 'A'; then
FILE=$(eval "echo \${CAFR[$1]}" | sed 's/ /_/g');
else
FILE=$(eval "echo \${AOSPR[${1//A/}]}" | sed 's/ /_/g');
fi
if [[ -f "${FILE}" ]]; then
source "${FILE}";
else
echo -e "\n${FLD} Invalid Selection\n";
rom_select;
fi
} # rom_check
function rom_select() # D 1,2
{
dash_it;
echo -e "${CL_YEL}[?]${NONE} ${CL_WYT}Which ROM are you trying to build\nChoose among these (Number Selection)\n";
for (( CT=1; CT<"${#CAFR[*]}"; CT++ )); do
echo -n "${CT}. ";
eval "echo -en \${CAFR[$CT]//.rc/}" | awk -F "/" '{print $NF}' | sed -e 's/_/ /g';
done | pr -t -2;
echo -e "\n${INF} ${CL_WYT}Non-CAF / Google-Family ROMs${NONE}";
echo -e "${INF} ${CL_WYT}Choose among these ONLY if you're building for a Nexus/Pixel Device\n";
for (( CT=1; CT<"${#AOSPR[*]}"; CT++ )); do
echo -n "A${CT}. ";
eval "echo -en \${AOSPR[$CT]//.rc/}" | awk -F "/" '{print $NF}' | sed -e 's/_/ /g';
done | pr -t -2;
dash_it;
[[ -z "$automate" ]] && unset SBRN && prompt SBRN;
rom_check "$SBRN";
ROM_FN="$(echo ${FILE//.rc/} | awk -F "/" '{print $NF}' | sed -e 's/_/ /g')";
echo -e "\n${INF} You have chosen -> ${CL_WYT}${ROM_FN}${NONE}\n";
unset CT;
} # rom_select
function shut_my_mouth() # ID
{
if [[ ! -z "$automate" ]]; then
local RST="SB$1";
echo -e "${ATBT} $2 : ${!RST}";
else
prompt SB2;
if [[ -z "$3" ]]; then
read -r "SB$1" <<< "${SB2}";
else
eval "SB$1=${SB2}";
fi
export "SB${1//\[*\]}";
unset SB2;
fi
echo;
} # shut_my_mouth
function set_ccvars() # D 4,5
{
echo -e "\n${INF} Specify the Size (Number) for Reservation of CCACHE (in GB)";
echo -e "\n${INF} CCACHE Size must be >15-20 GB for ONE ROM\n";
prompt CCSIZE;
echo -e "\n${INF} Create a New Folder for CCACHE and Specify it's location from /\n";
prompt CCDIR;
for RC in .profile .bashrc; do
if [[ -f "${HOME}/${RC}" ]]; then
if grep -q 'USE_CCACHE\|CCACHE_DIR' "${HOME}/${RC}"; then
echo -e "export USE_CCACHE=1\nexport CCACHE_DIR=${CCDIR}" >> "${HOME}/${RC}";
source "${HOME}/${RC}";
echo -e "\n${SCS} CCACHE Specific exports added in ${CL_WYT}${RC}${NONE}";
else
echo -e "\n${SCS} CCACHE Specific exports already enabled in ${CL_WYT}${RC}${NONE}";
fi
break; # One file, and its done
fi
done
echo -e "\n${EXE} Setting up CCACHE\n";
ccache -M "${CCSIZE}G";
echo -e "\n${SCS} CCACHE Setup Successful.\n";
unset CCSIZE CCDIR;
} # set_ccvars
function init() # 1
{
# change terminal title
echo -ne '\033]0;ScriBt : Init\007';
rom_select;
pause "4";
echo -e "${EXE} Detecting Available Branches in ${ROM_FN} Repository";
RCT=$(( ${#ROM_NAME[*]} - 1 ));
for CT in $(eval "echo {0..$RCT}"); do
echo -e "\nOn ${ROM_NAME[$CT]} (ID->$CT)\n";
local BRANCHES=$(git ls-remote -h "https://github.com/${ROM_NAME[$CT]}/${MAN[$CT]}" |\
awk -F "/" '{if (length($4) != 0) {print $3"/"$4} else {print $3}}');
if [[ ! -z "$CNS" && "$SBRN" != A* ]]; then
echo "$BRANCHES" | grep --color=never 'caf' | column;
else
echo "$BRANCHES" | column;
fi
done
unset CT;
echo -e "\n${INF} These Branches are available at the moment";
echo -e "\n${QN} Specify the ID and Branch you're going to sync";
echo -e "\n${INDENT}Format : [ID] [BRANCH]\n";
ST="Branch"; shut_my_mouth NBR "$ST";
local CT="${SBNBR/ */}"; # Count
local SBBR="${SBNBR/* /}"; # Branch
local MNF="${MAN[$CT]}"; # Orgn manifest name at count
local RNM="${ROM_NAME[$CT]}"; # Orgn name at count
echo -e "${QN} Any Source you have already synced ${YES_NO}\n"; get "info" "refer";
ST="Use Reference Source"; shut_my_mouth RF "$ST";
if [[ "$SBRF" == [Yy] ]]; then
echo -e "\n${QN} Provide me the Synced Source's Location from /\n";
ST="Reference Location"; shut_my_mouth RFL "$ST";
REF="--reference=\"${SBRFL}\"";
fi
echo -e "${QN} Set clone-depth ${YES_NO}\n"; get "info" "cldp";
ST="Use clone-depth"; shut_my_mouth CD "$ST";
if [[ "$SBCD" == [Yy] ]]; then
echo -e "${QN} Depth Value ${CL_WYT}[Default - 1]${NONE}\n";
ST="clone-depth Value"; shut_my_mouth DEP "$ST";
CDP="--depth=${SBDEP:-1}";
fi
# Check for Presence of Repo Binary
if [[ ! $(which repo) ]]; then
echo -e "${FLD} ${CL_WYT}repo${NONE} binary isn't installed";
echo -e "\n${EXE} Installing ${CL_WYT}repo${CL_WYT}";
[[ ! -d "${HOME}/bin" ]] && mkdir -pv ${HOME}/bin;
cmdprex \
"Tool/Lib to transfer data with URL syntax<->curl" \
"repo dwnld URL<->https://storage.googleapis.com/git-repo-downloads/repo" \
"Output Redirection Operator<->>" \
"Redirection file<->${HOME}/bin/repo";
cmdprex \
"Change Permissions on an Entity<->chmod" \
"Add executable permission<->a+x" \
"File to be chmod-ed<->${HOME}/bin/repo";
echo -e "${SCS} Repo Binary Installed";
echo -e "\n${EXE} Adding ${HOME}/bin to PATH\n";
if grep 'PATH=["]*' ${HOME}/.profile | grep -q '$HOME/bin'; then
echo -e "${SCS} $HOME/bin is in PATH";
else
{
echo -e "\n# set PATH so it includes user's private bin if it exists";
echo -e "if [ -d \"\$HOME/bin\" ]; then\n${INDENT}PATH=\"\$HOME/bin:\$PATH\"\nfi";
} >> "${HOME}/.profile";
source ${HOME}/.profile;
echo -e "\n${SCS} $HOME/bin added to PATH";
fi
echo -e "${SCS} Done. Ready to Initialize Repo";
fi
local MURL="https://github.com/${RNM}/${MNF}";
cmdprex --out="${STMP}" \
"repository management tool<->repo" \
"initialze in current directory<->init" \
"reference source directory<->${REF}" \
"clone depth<->${CDP}" \
"manifest URL specifier<->-u" \
"URL<->${MURL}" \
"manifest branch specifier<->-b" \
"branch<->${SBBR}";
if [[ -z "$STS" ]]; then
if [[ ! -f "${CALL_ME_ROOT}.repo/local_manifests" ]]; then
mkdir -pv "${CALL_ME_ROOT}.repo/local_manifests";
fi
if [[ -z "$automate" ]]; then
echo -e "\n${QN} Generate a Custom manifest ${YES_NO}\n";
prompt SBGCM;
[[ "$SBGCM" == [Yy] ]] && manifest_gen;
fi
else
unset STS;
fi
} # init
function sync() # 2
{
if [[ ! -f "${CALL_ME_ROOT}.repo/manifest.xml" ]]; then init; fi;
get_rom_info;
# Change terminal title
echo -ne "\033]0;ScriBt : Syncing ${ROM_FN}\007";
echo -e "\n${EXE} Preparing for Sync\n";
echo -e "${QN} Number of Threads for Sync \n"; get "info" "jobs";
ST="Number of Threads"; shut_my_mouth JOBS "$ST";
echo -e "${QN} Force Sync needed ${YES_NO}\n"; get "info" "fsync";
ST="Force Sync"; shut_my_mouth F "$ST";
echo -e "${QN} Need some Silence in the Terminal ${YES_NO}\n"; get "info" "silsync";
ST="Silent Sync"; shut_my_mouth S "$ST";
echo -e "${QN} Sync only Current Branch ${YES_NO}\n"; get "info" "syncrt";
ST="Sync Current Branch"; shut_my_mouth C "$ST";
echo -e "${QN} Sync with clone-bundle ${YES_NO}\n"; get "info" "clnbun";
ST="Use clone-bundle"; shut_my_mouth B "$ST";
dash_it;
#Sync-Options
[[ "$SBS" == "y" ]] && local SILENT="-q";
[[ "$SBF" == "y" ]] && local FORCE="--force-sync";
[[ "$SBC" == "y" ]] && local SYNC_CRNT="-c";
[[ "$SBB" == "y" ]] || local CLN_BUN="--no-clone-bundle";
echo -e "${EXE} Starting Sync for ${ROM_FN}";
cmdprex --out="${STMP}" \
"repository management tool<->repo" \
"update working tree<->sync" \
"no. of jobs<->-j${SBJOBS:-1}" \
"silent sync<->${SILENT}" \
"force sync<->${FORCE}" \
"sync current branch only<->${SYNC_CRNT}" \
"use clone.bundle<->${CLN_BUN}";
} # sync
function device_info() # D 3,4
{
echo -ne "\033]0;ScriBt : Device Info\007";
# Change ROMNIS to ROMV if ROMV is non-zero
[[ ! -z "${ROMV}" ]] && export ROMNIS="${ROMV}";
if [[ -d "${CALL_ME_ROOT}vendor/${ROMNIS}/config" ]]; then
CNF="vendor/${ROMNIS}/config";
elif [[ -d "${CALL_ME_ROOT}vendor/${ROMNIS}/configs" ]]; then
CNF="vendor/${ROMNIS}/configs";
elif [[ -d "${CALL_ME_ROOT}vendor/${ROMNIS}/products" ]]; then
CNF="vendor/${ROMNIS}/products";
else
CNF="vendor/${ROMNIS}";
fi
get_rom_info; # Restore ROMNIS
center_it "${CL_PRP}Device Info${NONE}" "1eq1";
echo -e "${QN} What's your Device's CodeName";
echo -e "\n${INF} Refer Device Tree - All Lowercases\n";
ST="Device CodeName"; shut_my_mouth DEV "$ST";
SBCM=$(find device/*/"${SBDEV}" -maxdepth 0 -type d | awk -F "/" '{print $2}');
if [[ -z "${SBCM}" ]]; then
echo -e "\n${FLD} Device Tree not found";
echo -e "${INDENT}Invalid Details OR Missing Source";
echo -e "\n${QN} Correct the provided details ${YES_NO}";
prompt PD;
case "$PD" in
[Yy])
unset PD;
device_info;
;;
*)
return 1;
;;
esac
fi
echo -e "${QN} Build type";
echo -e "\n${INF} Valid types : userdebug, user, eng\n";
ST="Build type"; shut_my_mouth BT "$ST";
if ! [[ "$SBBT" =~ (userdebug|user|eng) ]]; then
echo -e "\n${FLD} Invalid build type specified";
echo -e "\n${EXE} Falling back to ${CL_WYT}userdebug${NONE}";
SBBT="userdebug";
fi
echo -e "\n${QN} Choose your Device type among these";
get "info" "devtype";
get "misc" "device_types";
for TYP in ${TYPES[*]}; do
if [[ -f "${CNF}/${TYP}.mk" ]]; then echo -e "$TYP"; fi;
done | pr -t -2;
unset CT;
echo;
ST="Device Type"; shut_my_mouth DTP "$ST";
dash_it;
} # device_info
function start_venv()
{
# Create a Virtual Python2 Environment
if [[ "${PKGMGR}" == "pacman" ]] && [[ -z "${ACTIVE_VENV}" ]]; then
if python -V | grep -i -q "Python 3."; then
echo -e "${INF} Python 3 Detected";
echo -e "\n${INF} Android BuildSystem requires a Python 2.x Environment to function properly";
if ! which virtualenv2 &> /dev/null; then
echo -e "\n${FLD} Python2 not found";
echo -e "\n${EXE} Attempting to install Python2\n";
cmdprex \
"Execute command as 'root'<->execroot" \
"Arch Linux Package Mgr.<->${PKGMGR}" \
"Sync Pkgs.<->-S" \
"Answer 'yes' to prompts<->--noconfirm" \
"virtual env. (python2) package<->python2-virtualenv";
fi
echo -e "\n${EXE} Creating Python2 virtual environment";
cmdprex \
"Python2 Virtual EnvSetup<->virtualenv2" \
"Location of Virtual Env<->${HOME}/venv";
if [[ -z "$STS" ]]; then
cmdprex \
"Execute in current shell<->source" \
"Shell script to activate Virtual Env<->${HOME}/venv/bin/activate";
echo -e "${SCS} Python2 environment created\n";
ACTIVE_VENV="true";
else
echo -e "${FLD} An error occured while trying to start the Environment";
echo -e "\n${EXE} Aborting\n";
exitScriBt 1;
fi
fi
fi
} # start_venv
function stop_venv()
{
if [[ "${ACTIVE_VENV}" == "true" ]]; then
echo -e "\n${EXE} Exiting virtual environment\n";
deactivate && rm -rf "${HOME}/venv" && echo -e "${SCS} Python2 virtual environment deleted";
fi
} # stop_venv
function init_bld() # D 3,4
{
echo -e "\n${EXE} Initializing Build Environment";
cmdprex \
"Execute in current shell<->source" \
"Environment Setup Script<->build/envsetup.sh";
} # init_bld
function choose_target() # D 3,4
{
case "$ROMNIS" in
eos|pure) TARGET="${SBDEV}-${SBBT}" ;;
*) TARGET="${ROMNIS}_${SBDEV}-${SBBT}" ;;
esac
} # choose_target
function pre_build() # 3
{
# To prevent missing information, if user starts directly from here
get_rom_info;
init_bld;
if ! device_info; then
echo -e "${FLD} Failed to get Device Info";
return 1;
fi
# Change terminal title
echo -ne '\033]0;ScriBt : Pre-Build\007'
DEVDIR="device/${SBCM}/${SBDEV}/";
function vendor_strat_all()
{
if [[ ! -z "$ROMV" ]]; then cd "vendor/${ROMV}"; else cd "vendor/${ROMNIS}"; fi;
dash_it;
function dtree_add()
{ # AOSP-CAF|RRO|F-AOSP|Flayr|OmniROM|Zephyr
echo -e "\n${EXE} Adding Lunch Combo in Device Tree";
[[ ! -f "${CALL_ME_ROOT}${DEVDIR}vendorsetup.sh" ]] && touch "${CALL_ME_ROOT}${DEVDIR}vendorsetup.sh";
if ! grep -q "${ROMNIS}_${SBDEV}" "${CALL_ME_ROOT}${DEVDIR}vendorsetup.sh"; then
echo -e "add_lunch_combo ${TARGET}" >> "${CALL_ME_ROOT}${DEVDIR}vendorsetup.sh";
else
echo -e "\n${SCS} Lunch combo already added to vendorsetup.sh";
fi
} # dtree_add
if [[ "$ROMNIS" == "du" ]] && [[ "$CNS" == "y" ]]; then
VSTP="caf-vendorsetup.sh";
else
VSTP="vendorsetup.sh";
fi
echo -e "\n${EXE} Adding Device to ROM Vendor";
for STRAT_FILE in "${ROMNIS}.devices" "${ROMNIS}-device-targets" "${VSTP}"; do
# Found file && Strat Not Performed
if [[ -f "${STRAT_FILE}" ]] && [[ -z "${STRAT_DONE}" ]]; then
if ! grep -q "${SBDEV}" "${STRAT_FILE}"; then
case "${STRAT_FILE}" in
"${ROMNIS}.devices")
echo -e "${SBDEV}" >> "${STRAT_FILE}" ;;
"${ROMNIS}-device-targets")
echo -e "${TARGET}" >> "${STRAT_FILE}" ;;
"${VSTP}")
echo -e "add_lunch_combo ${TARGET}" >> "${STRAT_FILE}" ;;
esac
else
echo -e "\n${INF} Device already added to ${STRAT_FILE}";
fi
export STRAT_DONE="y"; # File Found, Strat Performed
fi
done
[[ -z "${STRAT_DONE}" ]] && dtree_add; # If none of the Strats Worked
echo -e "\n${SCS} Done";
cd "${CALL_ME_ROOT}";
dash_it;
} # vendor_strat_all
function vendor_strat_kpa() # AOKP-4.4|AICP|PAC-5.1|Krexus-CAF|AOSPA|Non-CAFs
{
cd "${CALL_ME_ROOT}vendor/${ROMNIS}/products";
function bootanim()
{
echo -e "\n${INF} Device Resolution\n";
if [[ ! -z "$automate" ]]; then
get "info" "bootres";
echo -e "\n${QN} Enter the Desired Highlighted Number\n";
prompt SBBTR;
else
echo -e "${ATBT} Resolution Chosen : ${SBBTR}";
fi
} # bootanim
#Vendor-Calls
get "strat" "${ROMNIS}";
get "strat" "common";
} # vendor_strat_kpa
function find_ddc() # For Finding Default Device Configuration file
{
# used by :- interactive_mk, src/strat/common.rc
# Collect a list of makefiles containing the string PRODUCT_NAME
local DDCS=( $(grep -rl "PRODUCT_NAME" | sed 's/.mk//g') );
# If required file is present && function was called by 'interactive_mk'; then
if (echo "${DDCS[*]}" | grep -q "${INTF}") && [[ $1 == "intm" ]]; then
export DDC="NULL";
else
# Add grep expression entries
for file in ${DDCS[*]}; do
GREP+=( "-e ${file}.mk " );
done
# Get a count of other DDCs inherited by the makefile
for file in ${DDCS[*]}; do
read -r "C_${file}" <<< $(grep -c ${GREP[*]} "${file}".mk);
done
local max=0;
# DDC should be the file inheriting maximum product makefiles
for file in ${DDCS[*]}; do
if [[ $(eval "echo \${C_${file}}") -ge "$max" ]]; then
DDC="${file}.mk";
max=$(eval "echo \${C_${file}}");
fi
done
fi
unset file GREP;
} # find_ddc
function print_makefile_addition()
{
echo -e "\n${EXE} Adding the following makefile call under ${CL_WYT}${2}${NONE}";
echo -e "\n\$(${CL_LRD}call${NONE} ${CL_YEL}inherit-product${NONE}, ${CL_LGN}${1}${NONE})";
echo -e "\n${CL_LRD}call a function${NONE}";
echo -e "${CL_YEL}function which inherits a product's makefile${NONE}";
echo -e "${CL_LGN}makefile to be called${NONE}\n";
pause "1";
} # print_makefile_addition
function interactive_mk()
{
dash_it;
echo -e "${EXE} Creating Interactive Makefile";
echo -e "${INDENT}So that device tree gets identified by the ROM's BuildSystem";
pause "4";
cd "${CALL_ME_ROOT}${DEVDIR}";
function create_imk()
{
[[ -z "$INTF" ]] && INTF="${ROMNIS}.mk";
get "misc" "intmake";
print_makefile_addition "${CNF}/${SBDTP}.mk" "${INTF}";
print_makefile_addition "${DEVDIR}${DDC}" "${INTF}";
{
echo -e "\n# Inherit ${ROMNIS} common stuff";
echo -e "\$(call inherit-product, ${CNF}/${SBDTP}.mk)";
echo -e "\n# Calling Default Device Configuration File";
echo -e "# File which contains ROM Identifiers, Vital Device info";
echo -e "# And inherits from other product makefiles";
echo -e "\$(call inherit-product, ${DEVDIR}${DDC})";
} >> "${INTF}";
# To prevent Missing Vendor Calls in DDC-File
echo -e "\n${INF} In file ${CL_WYT}${DDC}${NONE}";
echo -e "${INDENT}${CL_WYT}inherit-product${NONE} is replaced by ${CL_WYT}inherit-product-if-exists${NONE}"
echo -e "${INDENT}Since ${CL_WYT}${DDC}${NONE} may inherit makefiles ${CL_WYT}from a different ROM${NONE} that might not exist";
echo -e "\n${INF} This is being done so that the build won't fail even when other ROM's makefile(s) go missing\n";
pause "4";
# Search for makefile calls |\
# Invert match 'vendor/${name-of-vendor}' |\
# Perform the replacement on remaining matches;
grep 'call inherit-product' "${DDC}" |\
grep -v "vendor/${SBCM}" |\
sed -i 's/inherit-product, vendor/inherit-product-if-exists, vendor/g' "${DDC}";
# Add User-desired Makefile Calls
echo -e "${QN} Enter number of desired Makefile calls";
echo -e "\n${INF} Enter 0 if you don't want to add any\n";
ST="No of Makefile Calls"; shut_my_mouth NMK "$ST";
for (( CT=0; CT<"${SBNMK}"; CT++ )); do
echo -e "\n${QN} Enter Makefile location from Root of BuildSystem\n";
ST="Makefile"; shut_my_mouth LOC[$CT] "$ST" array;
if [[ -f "${CALL_ME_ROOT}${SBLOC[$CT]}" ]]; then
echo -e "\n${EXE} Adding Makefile $(( CT + 1 ))";
print_makefile_addition "${SBLOC[$CT]}" "${INTF}";
echo -e "\n\$(call inherit-product, ${SBLOC[$CT]})" >> "${INTF}";
else
echo -e "\n${FLD} Makefile ${SBLOC[$CT]} not Found. Aborting";
fi
done
unset CT;
echo -e "\n${INF} Adding ROM specific identification variable";
{
echo -e "\n# ROM Specific Identifier";
echo -e "PRODUCT_NAME := ${ROMNIS}_${SBDEV}";
} >> "${INTF}";
echo -e "\n${SCS} Interactive Makefile ${CL_WYT}${INTF}${NONE} created successfully";
echo -e "\n${INF} Please take a look at ${CL_WYT}${DEVDIR}${INTF}${NONE} later on how it was made";
cd "${CALL_ME_ROOT}";
dash_it;
} # create_imk
find_ddc "intm";
if [[ "$DDC" != "NULL" ]]; then create_imk; else echo "$NOINT"; fi;
cd "${CALL_ME_ROOT}";
} # interactive_mk
function need_for_int()
{
if [[ -f "${CALL_ME_ROOT}${DEVDIR}${INTF}" ]]; then
echo "$NOINT";
else
interactive_mk;
fi
} # need_for_int
function add_prdt_makefile_to_apmk()
{
echo -e "\n${INF} Adding line under ${CL_WYT}${APMK}${NONE} to include makefile ${CL_WYT}${INTF}${NONE}";
{
echo -e "\nPRODUCT_MAKEFILES $S \\";
echo -e "\t\$(LOCAL_DIR)/${INTF}";
} >> "${APMK}";
} # add_prdt_makefile_to_apmk
echo -e "\n${EXE} ${ROMNIS}-fying Device Tree";
NOINT=$(echo -e "\n${SCS} Interactive Makefile Unneeded, continuing\n");
APMK="${CALL_ME_ROOT}${DEVDIR}AndroidProducts.mk";
if [[ -f "$APMK" ]]; then S="+="; else S=":="; fi;
case "$ROMNIS" in
aosp|carbon|nitrogen|omni|zos)
# AEX|AOSP-CAF/RRO|Carbon|F-AOSP|Flayr|Nitrogen|OmniROM|Parallax|Zephyr
INTF="${ROMNIS}_${SBDEV}.mk";
need_for_int;
add_prdt_makefile_to_apmk;
;;
eos)
INTF="${ROMNIS}.mk";
need_for_int;
add_prdt_makefile_to_apmk;
;;
aosip)
# AOSiP-CAF
if [[ ! -f "vendor/${ROMNIS}/products" ]]; then
INTF="${ROMNIS}.mk";
need_for_int;
else
echo "$NOINT";
fi
;;
aokp|pac)
# AOKP-4.4|PAC-5.1
if [[ ! -f "vendor/${ROMNIS}/products" ]]; then
INTF="${ROMNIS}.mk";
need_for_int;
else
echo "$NOINT";
fi
;;
aicp|krexus|pa|pure|krexus|pure)
# AICP|Krexus-CAF|AOSPA|Non-CAFs except DU
echo "$NOINT";
;;
*)
# Rest of the ROMs
INTF="${ROMNIS}.mk";
need_for_int;
;;
esac
unset S;
choose_target;
if [[ -d "vendor/${ROMNIS}/products" ]]; then
if [[ ! -f "vendor/${ROMNIS}/products/${ROMNIS}_${SBDEV}.mk" ]] ||
[[ ! -f "vendor/${ROMNIS}/products/${SBDEV}.mk" ]] ||
[[ ! -f "vendor/${ROMNIS}/products/${SBDEV}/${ROMNIS}_${SBDEV}.mk" ]]; then
vendor_strat_kpa; # if found products folder, go ahead
else
echo -e "\n${SCS} Looks like ${SBDEV} has been already added to ${ROM_FN} vendor. Good to go\n";
fi
else
vendor_strat_all; # if not found, normal strategies