-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_aex.sh
More file actions
executable file
·225 lines (202 loc) · 5.99 KB
/
Copy pathbuild_aex.sh
File metadata and controls
executable file
·225 lines (202 loc) · 5.99 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
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
TG_BOT_API_KEY=$BOT_API_KEY
TG_CHAT_ID=172556296
#detect path where the script is running
SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
if [ -z "$SCRIPT_DIR" ] ; then
# error; for some reason, the path is not accessible
echo "${red}Can not read run path"
echo "Build can not continue"${txtrst}
exit 1 # fail
fi
# Source common functions
source "${SCRIPT_DIR}"/common
trap 'exit 1' INT TERM
# Create binaries directory
mkdir -p ~/bin/
# Specify colors utilized in the terminal
red=$(tput setaf 1) # red
grn=$(tput setaf 2) # green
ylw=$(tput setaf 3) # yellow
blu=$(tput setaf 4) # blue
cya=$(tput rev)$(tput bold)$(tput setaf 6) # bold cyan reversed
ylr=$(tput rev)$(tput bold)$(tput setaf 3) # bold yellow reversed
grr=$(tput rev)$(tput bold)$(tput setaf 2) # bold green reversed
rer=$(tput rev)$(tput bold)$(tput setaf 1) # bold red reversed
txtrst=$(tput sgr0) # Reset
[[ -z "${1}" ]] && echo "Device code name not passed as parameter, exiting!" && exit 1
DEVICE=$1
[[ -z "${TG_BOT_API_KEY}" ]] && echo "BOT_API_KEY not defined, exiting!" && exit 1
function sendTG() {
curl -s "https://api.telegram.org/bot${TG_BOT_API_KEY}/sendmessage" --data "text=${*}&chat_id=${TG_CHAT_ID}&parse_mode=Markdown" >/dev/null
}
config=$SCRIPT_DIR"/config.conf"
if [ ! -f $config ]; then
echo "Configuration file is missing"
echo "Creating..."
echo "Please enter the path where AEX folder is located (full path ex:/home/<user>/aex)"
read aex_path
echo "Upload compilation to remote server at end of build?"
set_upload_build=false
select yn in "Yes" "No"; do
case $yn in
Yes)
set_upload_build=true
break
;;
No)
set_upload_build=false
break
;;
esac
done
if [ "$set_upload_build" = true ]; then
echo 'Please choose where to upload your build: '
options=("Gdrive" "Source Forge")
select opt in "${options[@]}"; do
case $opt in
"Gdrive")
set_upload_build_server="gdrive"
echo "Checking gdrive installed or not"
GDRIVE="$(command -v gdrive)"
if [ -z "${GDRIVE}" ]; then
echo "Installing gdrive"
bash -i "${SCRIPT_DIR}"/gdrive.sh
else
INSTALLED_VERSION="$(gdrive version | grep gdrive | awk '{print $2}')"
reportWarning "gdrive ${INSTALLED_VERSION} is already installed!"
fi
break
;;
"Source Forge")
echo "Comming soon..."
# echo "Enter remote hostname (ex: web.sourceforge.net): "
# read set_remote_hostname
# echo "Enter remote username:"
# read set_remote_username
# echo "Enter remote password:"
# read set_remote_password
break
;;
esac
done
fi
echo "${blu}Run repo sync?${txtrst}"
select yn in "Yes" "No"; do
case $yn in
Yes)
repo_sync = true
break
;;
No) break ;;
esac
done
echo "${blu}Select Build Type?${txtrst}"
select yn in "eng" "userdebug"; do
case $yn in
eng)
device_build_type=aosp_${DEVICE}-eng
break
;;
userdebug)
device_build_type=aosp_${DEVICE}-userdebug
break
;;
esac
done
#create config file
echo "aex_path="$aex_path >> config.conf
echo "set_upload_build="$set_upload_build >> config.conf
echo "set_upload_build_server="$set_upload_build_server >> config.conf
echo "repo_sync="$repo_sync >> config.conf
echo "device_build_type="$device_build_type >> config.conf
echo "${grn}Successfully created configuration file at ${ylw}$SCRIPT_DIR/config.conf${txtrst}"
fi
#read configuration
source config.conf
echoText "Changing dir to ${aex_path}"
cd $aex_path
# Check aex version
aex_check=$(grep -n "EXTENDED_VERSION" $aex_path/vendor/aosp/config/version.mk | grep -Eo '^[^:]+')
array=($aex_check)
AEX_VERSION=$(sed -n ${array[0]}'p' <$aex_path/vendor/aosp/config/version.mk | cut -d "=" -f 2 | tr -d '[:space:]')
if [ -z "$AEX_VERSION" ] || [ -z "$aex_check" ]; then
echo -e ${red}"Couldn't detect AEX version exiting...."${txtrst};
exit 1
fi
if [ "$repo_sync" = true ]; then
repo sync -c -j$(nproc --all) --force-sync --no-clone-bundle --no-tags
fi
echo "${blu}Gapps or Non-gapps Build?${txtrst}"
select yn in "gapps" "nongapps"; do
case $yn in
gapps)
export CURRENT_BUILD_TYPE=gapps
break
;;
nongapps)
export CURRENT_BUILD_TYPE=xyzzzz
break
;;
esac
done
source build/envsetup.sh
echo "${blu}Make clean build?${txtrst}"
select yn in "yes" "no"; do
case $yn in
yes)
cd $aex_path
make clean
break
;;
no) break ;;
esac
done
export CCACHE_EXEC=$(which ccache)
export USE_CCACHE=1
export CCACHE_COMPRESS=1
export CCACHE_MAXSIZE=50G # 50 GB
cd $aex_path
if ! lunch "${device_build_type:?}"; then
echo "Lunching $DEVICE failed"
sendTG "Lunching $mydevice failed."
exit 1
fi
echo "${blu}Please confirm do you want to start build?${txtrst}"
select yn in "yes" "no"; do
case $yn in
yes)
cd $aex_path
echo "${ylw}Initiating AEX ${AEX_VERSION} build for ${DEVICE}...${txtrst}"
if ! mka aex; then
echo "$DEVICE Build failed"
sendTG "$DEVICE build failed."
exit 1
else
cd $aex_path/out/target/product/$DEVICE
ZIP=$(ls AospExtended-${AEX_VERSION}-$DEVICE-*.zip)
ZIP_SIZE="$(du -h "${ZIP}" | awk '{print $1}')"
MD5="$(md5sum "${ZIP}" | awk '{print $1}')"
if [ "$set_upload_build" = true -a "$set_upload_build_server" == "gdrive" ]; then
# Upload file
GDRIVE_UPLOAD_URL=$(gdrive upload --share $ZIP | awk '/https/ {print $7}')
GDRIVE_UPLOAD_ID="$(echo "${GDRIVE_UPLOAD_URL}" | sed -r -e 's/(.*)&export.*/\1/' -e 's/https.*id=(.*)/\1/' -e 's/https.*\/d\/(.*)\/view/\1/')"
if [ -z "$GDRIVE_UPLOAD_URL" ] || [ -z "$GDRIVE_UPLOAD_ID" ]; then
echo -e ${cya}"Couldn't upload build...."${txtrst};
sendTG "$mydevice build is done, but couldn't upload."
else
UPLOAD_INFO="
File: [$(basename "${ZIP}")](${GDRIVE_UPLOAD_URL})
Size: ${ZIP_SIZE}
MD5: \`${MD5}\`
GDrive ID: \`${GDRIVE_UPLOAD_ID}\`"
sendTG "${UPLOAD_INFO}"
fi
else
sendTG "$DEVICE build is done."
fi
fi
break
;;
no) break ;;
esac
done