-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild
executable file
·292 lines (266 loc) · 10.6 KB
/
build
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
#!/bin/bash
# Build crDroid and optionally upload to remote FTP server
# Author: Gwolf2u (gwolfu@xda)
script_version=8.0.0
# 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
#detect path where the script is running
script_path="`dirname \"$0\"`"
script_path="`( cd \"$script_path\" && pwd )`"
if [ -z "$script_path" ] ; 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
arg=$1
case $arg in
"add" )
echo "Add a new device:"
echo "Format: <device codename>,<build type>,<remote upload path>"
read newdevice
echo $newdevice >> devices.conf
echo "Added"
exit 0 ;;
"remove" )
if [ ! -f devices.conf ]; then
echo "There are no devices saved"
exit 0
fi
echo "Enter line number to delete"
awk '$0!=""{print NR, $0}' devices.conf
read delline
sed -i $delline'd' devices.conf
echo "Deleted"
exit 0 ;;
"list" )
if [ ! -f devices.conf ]; then
echo "There are no devices saved"
exit 0
fi
echo "Listing all devices:"
cat $script_path"/devices.conf"
exit 0 ;;
"clean" )
echo "Cleaned up configuration"
rm -f $script_path"/config.conf"
exit 0 ;;
"clear" )
echo "Cleaned up all devices"
rm -f $script_path"/devices.conf"
exit 0 ;;
"help" )
echo "This build script is used to be able to build crDroid and upload the builds to remote server"
echo "Usage: ./build [OPTION]"
echo ""
echo "Commands supported:"
echo "add - adds a device to be built"
echo "remove - removes a device from build list"
echo "list - lists all devices that are configured to be built"
echo "clean - cleans up the configuration"
echo "clear - clears up all the devices on build list"
exit 0 ;;
esac
clear
echo "==========================================="
echo "${cya}Initiate build script - v$script_version for crDroid"${txtrst}
echo "==========================================="
#check script updates
echo "Running update check..."
wget -O check -q https://raw.githubusercontent.com/crdroidandroid/crdroid_build/14.0/build
linenr=$(grep -n "script_version" check | grep -Eo '^[^:]+')
array=( $linenr )
online_version=$(sed -n ${array[0]}'p' < check | cut -d "=" -f 2 | sed -r 's/[.]+//g')
rm -f check
script_version=$(echo $script_version | sed -r 's/[.]+//g')
if [ "$online_version" -gt "$script_version" ]; then
echo "${ylr}A new version of this build script is available on GitHub"
echo "Run below command to update before re-attempting to run again"
echo "${rer}curl -LJO https://raw.githubusercontent.com/crdroidandroid/crdroid_build/14.0/build${txtrst}"
read -p "${ylr}Press enter to exit${txtrst}"
exit 0
else
echo "${grr}Seems you are running latest build script version available ㋡${txtrst}"
fi
config=$script_path"/config.conf"
if [ ! -f $config ]; then
echo "Configuration file is missing"
echo "Creating..."
echo "Please enter the path where crDroid folder is located (full path ex:/home/<user>/crDroid)"
read set_crDroid_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 "Enter remote hostname (ex: upme.crdroid.net): "
read set_remote_hostname
echo "Enter remote username:"
read set_remote_username
echo "Enter remote password:"
read set_remote_password
fi
#create config file
echo "config_version=3" >> $config
echo "crDroid_path="$set_crDroid_path >> $config
echo "upload_build="$set_upload_build >> $config
echo "remote_hostname="$set_remote_hostname >> $config
echo "remote_username="$set_remote_username >> $config
echo "remote_password="$set_remote_password >> $config
echo "${grn}Successfully created configuration file at ${ylw}$script_path/config.conf${txtrst}"
echo "Please run \"${grn}./build add${txtrst}\" to add new devices for build script"
echo "For a list of availble commands, run \"${grn}./build help${txtrst}\""
exit 0
fi
#read configuration
source config.conf
if [[ -z ${config_version+x} ]] || (( "$config_version" < "3" )); then
echo "${red}Configuration file is outdated. Please run ${ylw}./build clean ${red}followed by ${ylw}./build ${red}to regenerate it"
exit 1
fi
devices=$script_path"/devices.conf"
if [ ! -f $devices ]; then
echo "${red}There are no devices configured to be built"
echo "Run \"./build add\" to add a new device"${txtrst}
exit 1 # fail
fi
#check if already synced
crdroid_synced=$crDroid_path/vendor/lineage/config/version.mk
if [ ! -f $crdroid_synced ]; then
echo "${ylw}Detected missing first sync... atempting first time sync..."${txtrst}
cd $crDroid_path
repo sync --force-sync --no-clone-bundle -j$(nproc) --fail-fast
fi
if [ ! -f $crdroid_synced ]; then
read -p "${red}Something went wrong :( - Maybe misconfigured script!?"
exit
fi
PATH=~/bin:$PATH
export LC_ALL=C
function repopicking()
{
#create a repopick.txt file and run after repo sync
picks=$script_path/repopick.txt
if [ -f $picks ]; then
. build/envsetup.sh
cat $picks | while read line
do
$line
done
fi
}
cd $crDroid_path
echo "${blu}Run sync?${txtrst}"
select yn in "Yes" "No"; do
case $yn in
Yes ) repo sync --force-sync --no-clone-bundle --fail-fast; repopicking; break;;
No ) break;;
esac
done
echo "${blu}For how many days you want changelog to be generated?${txtrst}"
read days
until [[ $days =~ ^-?[0-9]+$ ]]; do
echo "Invalid input - only numbers are allowed"
read days
done
export changelog_days=$days
echo "${grn}Roger... $days days will be set for changelog generation${txtrst}"
echo "${blu}Make clean build?${txtrst}"
select yn in "Yes" "No"; do
case $yn in
Yes ) rm -rf out; break;;
No ) break;;
esac
done
#detect android version based on common.mk
major_check=$(grep -n "PRODUCT_VERSION_MAJOR" $crDroid_path/vendor/lineage/config/version.mk | grep -Eo '^[^:]+')
array=( $major_check )
android_major=$(sed -n ${array[0]}'p' < $crDroid_path/vendor/lineage/config/version.mk | cut -d "=" -f 2 | sed -r 's/[.]+//g' | tr -d '[:space:]')
minor_check=$(grep -n "PRODUCT_VERSION_MINOR" $crDroid_path/vendor/lineage/config/version.mk | grep -Eo '^[^:]+')
array=( $minor_check )
android_minor=$(sed -n ${array[0]}'p' < $crDroid_path/vendor/lineage/config/version.mk | cut -d "=" -f 2 | sed -r 's/[.]+//g' | tr -d '[:space:]')
android=$android_major"."$android_minor
cr_check=$(grep -n "CR_VERSION" $crDroid_path/vendor/lineage/config/version.mk | grep -Eo '^[^:]+')
array=( $cr_check )
crDroid=$(sed -n ${array[0]}'p' < $crDroid_path/vendor/lineage/config/version.mk | cut -d "=" -f 2 | tr -d '[:space:]')
INFO=()
echo "==========================================="
echo "${ylr}Setting build environment"${txtrst}
echo "-------------------------------------------"
echo "Script path set to: "${grn}$script_path${txtrst}
echo "crDroid path set to: "${grn}$crDroid_path${txtrst}
echo "Upload complete build to remote server?: "${grn}$upload_build${txtrst}
echo "Trying to compile crDroid "${grn}$crDroid${txtrst}" based on Android "${grn}$android${txtrst}
echo "==========================================="
echo ""
echo "${ylw}Initiate build for all devices...${txtrst}"
file=$devices
while IFS= read -r line
do
IFS=', ' read -r -a device_uploadpath <<< "$line"
#set device name
device=${device_uploadpath[0]}
buildtype=${device_uploadpath[1]}
if [[ $device == *"#"* ]]; then
device="${device//#}"
echo "${red}Found comment (#): Skipping build for ${ylw}$device ${red}${txtrst}"
INFO+=('1 '$device' (Reason: instruction to skip found in devices)')
else
echo "${grn}Now building "${ylw}$device${txtrst}
#set BuildID - aka name of the zip file from OUT folder at the end of the build
BuildID="crDroidAndroid-"$android"-"$(date -d "$D" '+%Y')$(date -d "$D" '+%m')$(date -d "$D" '+%d')"-"$device"-v"$crDroid".zip"
#initiate build script and start actual build
. build/envsetup.sh
source ${ANDROID_BUILD_TOP}/vendor/lineage/vars/aosp_target_release
#lunch lineage_$1-$aosp_target_release-$branch
lunch lineage_$device-$aosp_target_release-$buildtype
m bacon
#define upload file path
uploadfile=$crDroid_path/out/target/product/$device/$BuildID
echo "Checking build result status..."
if [ -e "$uploadfile" ]; then
echo "${grn}Seems compilation is ready for $device${txtrst}"
if [ "$upload_build" = true ] ; then
echo "${grn}Uploading new $device build to $remote_hostname${txtrst}"
curl --ssl -k -T $uploadfile ftp://$remote_hostname/${device_uploadpath[2]}/ --user $remote_username:$remote_password
INFO+=('2 '$device)
else
INFO+=('3 '$device)
fi
else
echo "${red}Device "$device "did not produce a proper build${txtrst}"
INFO+=('0 '$device' (Reason: unknown - better run a new build manually)')
fi
fi
done < "$file"
echo ${grr}"Script finished with following results"${txtrst}
for i in "${INFO[@]}"
do
#echo $i
if [[ $i == *"0"* ]]; then
codename=${i//0}
echo "${red}Compilation error for device" $codename${txtrst}
elif [[ $i == *"1"* ]]; then
codename=${i//1}
echo "${ylw}Warning for device" $codename${txtrst}
elif [[ $i == *"2"* ]]; then
codename=${i//2}
echo "${grn}Device" $codename "compiled and uploaded successfully ㋡${txtrst}"
else
codename=${i//3}
echo "${grn}Device" $codename "compiled successfully ㋡ (consider uploading build?)${txtrst}"
fi
done
read -p "Press enter to exit"