forked from ParanoidAndroid/paranoid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·156 lines (133 loc) · 4.12 KB
/
build.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
#!/bin/bash
# get current path
reldir=`dirname $0`
cd $reldir
DIR=`pwd`
# Colorize and add text parameters
red=$(tput setaf 1) # red
grn=$(tput setaf 2) # green
cya=$(tput setaf 6) # cyan
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldgrn=${txtbld}$(tput setaf 2) # green
bldblu=${txtbld}$(tput setaf 4) # blue
bldcya=${txtbld}$(tput setaf 6) # cyan
txtrst=$(tput sgr0) # Reset
THREADS="16"
DEVICE="$1"
EXTRAS="$2"
# get current version
MAJOR=$(cat $DIR/vendor/pa/config/pa_common.mk | grep 'PA_VERSION_MAJOR = *' | sed 's/PA_VERSION_MAJOR = //g')
MINOR=$(cat $DIR/vendor/pa/config/pa_common.mk | grep 'PA_VERSION_MINOR = *' | sed 's/PA_VERSION_MINOR = //g')
VERSION=$MAJOR.$MINOR
# check if buildtool exist on the environment
if [ -f $DIR/ParanoidTools.jar ]
then
TOOL="true"
else
TOOL="false"
fi
# send interrupted status to server
on_interrupt() {
if [ "$TOOL" == "true" ] && [ "$UPLOAD" == "true" ]
then
java -jar $DIR/ParanoidTools.jar $device 3
fi
exit 0
}
# trap interrupt behaviour
trap on_interrupt SIGINT
# if we have not extras, reduce parameter index by 1
if [ "$EXTRAS" == "true" ] || [ "$EXTRAS" == "false" ]
then
SYNC="$2"
UPLOAD="$3"
else
SYNC="$3"
UPLOAD="$4"
fi
# get time of startup
res1=$(date +%s.%N)
# we don't allow scrollback buffer
echo -e '\0033\0143'
clear
# decide what device to build for
case "$DEVICE" in
galaxys2)
device="i9100"
echo -e "${cya}Building ${bldcya}ParanoidAndroid v$VERSION ${txtrst}${cya}for International Samsung Galaxy S2 ${txtrst}";;
maguro)
device="maguro"
echo -e "${cya}Building ${bldcya}ParanoidAndroid v$VERSION ${txtrst}${cya}for International Samsung Galaxy Nexus ${txtrst}";;
galaxys3)
device="i9300"
echo -e "${cya}Building ${bldcya}ParanoidAndroid v$VERSION ${txtrst}${cya}for International Samsung Galaxy S3 ${txtrst}";;
toro)
device="toro"
echo -e "${cya}Building ${bldcya}ParanoidAndroid v$VERSION ${txtrst}${cya}for Verizon Samsung Galaxy Nexus ${txtrst}";;
toroplus)
device="toroplus"
echo -e "${cya}Building ${bldcya}ParanoidAndroid v$VERSION ${txtrst}${cya}for Sprint Samsung Galaxy Nexus ${txtrst}";;
grouper)
device="grouper"
echo -e "${cya}Building ${bldcya}ParanoidAndroid v$VERSION ${txtrst}${cya}for Asus Nexus 7 ${txtrst}";;
epicmtd)
device="epicmtd"
echo -e "${cya}Building ${bldcya}ParanoidAndroid v$VERSION ${txtrst}${cya}for Samsung Epic4g ${txtrst}";;
*)
echo -e "${bldred}Wrong input, please select a valid device ${txtrst}"
exit;;
esac
echo -e "${cya}"
./vendor/pa/tools/getdevicetree.py $device
echo -e "${txtrst}"
# decide what command to execute
case "$EXTRAS" in
threads)
echo -e "${bldblu}Please write desired threads followed by [ENTER] ${txtrst}"
read threads
THREADS=$threads;;
clean)
echo -e ""
echo -e "${bldblu}Cleaning intermediates and output files ${txtrst}"
make clean > /dev/null;;
esac
# download prebuilt files
echo -e ""
echo -e "${bldblu}Downloading prebuilts ${txtrst}"
cd vendor/cm
./get-prebuilts
cd ./../..
# sync with latest sources
echo -e ""
if [ "$SYNC" == "true" ]
then
echo -e "${bldblu}Fetching latest sources ${txtrst}"
repo sync -j"$THREADS"
echo -e ""
fi
# send building status to server
if [ "$TOOL" == "true" ] && [ "$UPLOAD" == "true" ]
then
java -jar $DIR/ParanoidTools.jar $device 0
fi
# setup environment
echo -e "${bldblu}Setting up environment ${txtrst}"
. build/envsetup.sh
# lunch device
echo -e ""
echo -e "${bldblu}Lunching device ${txtrst}"
lunch "pa_$device-userdebug";
echo -e ""
echo -e "${bldblu}Starting compilation ${txtrst}"
# start compilation
brunch "pa_$device-userdebug";
echo -e ""
# if we cant upload the file, status 4 will be sent
if [ "$TOOL" == "true" ] && [ "$UPLOAD" == "true" ]
then
java -jar $DIR/ParanoidTools.jar $device 1
fi
# finished? get elapsed time
res2=$(date +%s.%N)
echo "${bldgrn}Total time elapsed: ${txtrst}${grn}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds) ${txtrst}"