forked from JonasCardoso/android_.repo_local_manifest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
279 lines (252 loc) · 8.18 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
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
#!/bin/bash
# New Live/Menu by Caio Oliveira aka Caio99BR <caiooliveirafarias0@gmail.com>
# Support for msm8996 by JonasCardoso aka JonasCardoso <jonascard60@gmail.com>
# Generic Variables
_android="9.0.0"
_android_version="Pie"
_android_java="8"
_custom_android="lineage-16.0"
_custom_android_version="LineageOS-16.0"
_github_custom_android_place="LineageOS"
_github_device_place="JonasCardoso"
# Make loop for usage of 'break' to recursive exit
while true
do
_unset_and_stop() {
unset _device _device_build _device_echo
break
}
_if_fail_break() {
${1}
if [ "${?}" != "0" ]
then
echo " |"
echo " | Something failed!"
echo " | Exiting from script!"
_unset_and_stop
fi
}
_java_install() {
echo " |"
echo " | Let's install dependencies!"
echo " | Adding OpenJDK Repository!"
sudo apt-add-repository ppa:openjdk-r/ppa -y
sudo apt-get update
}
_java_select() {
echo " |"
echo " | Opening Java Selection Screen!"
echo " | Select 'open-jdk-${_android_java}' in both screens"
echo " | to continue using this script"
sudo update-alternatives --config java
sudo update-alternatives --config javac
}
_check_java() {
_java=$(java -version 2>&1 | head -1)
_javac=$(javac -version 2>&1 | head -1)
if [ "$(echo ${_java} | grep -o 1.${_android_java})" != "1.${_android_java}" ]
[ "$(echo ${_javac} | grep -o 1.${_android_java})" != "1.${_android_java}" ]
then
echo " |"
echo " | OpenJDK ${_android_java} not is default Java!"
echo " | Default Java is ('${_java}')!"
echo " | And default JavaC is ('${_javac}')!"
${1}
fi
}
# Unset devices variables for not have any problem
unset _device _device_build _device_echo _option_exit
# Check if 'curl' is installed
if [ ! "$(which curl)" ]
then
echo " |"
echo " | You will need 'curl'"
echo " | Use 'sudo apt-get install curl' to install 'curl'"
echo " | Exiting from script!"
_unset_and_stop
fi
# Check if 'repo' is installed
if [ ! "$(which repo)" ]
then
# Load this value
export PATH=~/bin:$PATH
# Check again for repo
if [ ! "$(which repo)" ]
then
echo " |"
echo " | Installing 'repo'"
# Download repo inside of bin dir
_if_fail_break "curl -# --create-dirs -L -o ~/bin/repo -O -L http://commondatastorage.googleapis.com/git-repo-downloads/repo"
# Make it executable
chmod a+x ~/bin/repo
# Let's check if repo is include
if [ $(cat $(ls .bash* | grep -v -e history -e logout) | grep "export PATH=~/bin:\$PATH" | wc -l) == "0" ]
then
# Add it to bashrc
echo "export PATH=~/bin:\$PATH" >> ~/.bashrc
fi
fi
fi
# Name of script
echo " |"
echo " | Live Android Sync and Build Script"
echo " | For Android ${_android_version} (${_android}) | ${_custom_android_version} (${_custom_android})"
# Check option of user and transform to script
for _u2t in "${@}"
do
if [[ "${_u2t}" == *"h" ]] || [[ "${_u2t}" == *"help" ]]
then
echo " |"
echo " | Usage:"
echo " | -h | --help | To show this message"
echo " |"
echo " | -0 | --Mi5 | To build only for Mi5/Gemini"
echo " | -1 | --Mi5S | To build only for Mi5S/Capricorn"
echo " | -2 | --Mi5S Plus | To build only for Mi5S Plus/Natrium"
echo " | -3 | --Mi Mix | To build only for Mi Mix/Lithium"
echo " | -4 | --Mi Note 2 | To build only for Mi Note 2/Scorpio"
echo " |"
echo " | -a | --all | To build for all devices"
_option_exit="1"
_unset_and_stop
fi
# Choose device before menu
if [[ "${_u2t}" == *"0" ]] || [[ "${_u2t}" == *"gemini" ]]
then
_device_build="gemini" _device_echo="Mi5"
fi
if [[ "${_u2t}" == *"1" ]] || [[ "${_u2t}" == *"capricorn" ]]
then
_device_build="capricorn" _device_echo="Mi5S"
fi
if [[ "${_u2t}" == *"2" ]] || [[ "${_u2t}" == *"natrium" ]]
then
_device_build="natrium" _device_echo="Mi5S Plus"
fi
if [[ "${_u2t}" == *"3" ]] || [[ "${_u2t}" == *"lithium" ]]
then
_device_build="lithium" _device_echo="Mi Mix"
fi
if [[ "${_u2t}" == *"4" ]] || [[ "${_u2t}" == *"scorpio" ]]
then
_device_build="scorpio" _device_echo="Mi Note 2"
fi
if [[ "${_u2t}" == *"a" ]] || [[ "${_u2t}" == *"all" ]]
then
_device_build="all" _device_echo="All Devices"
fi
done
# Exit if option is 'help'
if [ "${_option_exit}" != "" ]
then
_unset_and_stop
fi
# Install dependencies for building Android
# Pulled from:
# <https://source.android.com/source/initializing.html>
# <https://github.com/akhilnarang/scripts>
# <https://github.com/a7r3/ScriBt>
# Check Java
_check_java _java_select
_check_java _java_install
echo " |"
echo " | Downloading dependencies!"
sudo apt-get -y install git-core python gnupg flex bison gperf \
libsdl1.2-dev libesd0-dev libwxgtk2.8-dev squashfs-tools \
build-essential zip curl libncurses5-dev zlib1g-dev \
openjdk-${_android_java}-jre openjdk-${_android_java}-jdk \
pngcrush schedtool libxml2 libxml2-utils xsltproc lzop \
libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev \
gcc-multilib liblz4-* pngquant ncurses-dev texinfo gcc gperf \
patch libtool automake g++ gawk subversion expat libexpat1-dev \
python-all-dev binutils-static bc libcloog-isl-dev libcap-dev \
autoconf libgmp-dev build-essential gcc-multilib g++-multilib \
pkg-config libmpc-dev libmpfr-dev lzma* liblzma* w3m \
android-tools-adb maven ncftp figlet
sudo apt-get -f -y install
# Select Java
_check_java _java_select
_check_java _unset_and_stop
# Repo Sync
echo " |"
echo " | Starting Sync of Android Tree Manifest"
# Remove old Manifest of Android Tree
echo " |"
echo " | Removing old Manifest before download new one"
rm -rf .repo/manifests .repo/manifests.git .repo/manifest.xml .repo/local_manifests/
# Initialization of Android Tree
echo " |"
echo " | Downloading Android Tree Manifest from ${_github_custom_android_place} (${_custom_android})"
_if_fail_break "repo init -u https://github.com/${_github_custom_android_place}/android.git -b ${_custom_android}"
# Device manifest download
echo " |"
echo " | Downloading local manifest"
echo " | From ${_github_device_place} (${_custom_android})"
_if_fail_break "curl -# --create-dirs -L -o .repo/local_manifests/xiaomi_msm8996_default.xml -O -L https://raw.github.com/${_github_device_place}/android_.repo_local_manifest/${_custom_android}/xiaomi_msm8996_default.xml"
# Use optimized reposync
echo " |"
echo " | Starting Sync:"
_if_fail_break "repo sync -c -f --force-sync -q"
# Initialize environment
echo " |"
echo " | Initializing the environment"
_if_fail_break "source build/envsetup.sh"
# Another device choice
echo " |"
echo " | For what device you want to build:"
echo " |"
echo " | 0 | Xiaomi Mi5 | Gemini"
echo " | 1 | Xiaomi Mi5S | Capricorn"
echo " | 2 | Xiaomi Mi5S Plus | Natrium"
echo " | 3 | Xiaomi Mix Mix | Lithium"
echo " | 4 | Xiaomi Mi Note 2 | Scorpio"
echo " |"
echo " | a | All devices"
echo " |"
if [ "${_device_build}" == "" ]
then
read -p " | Choice | 0/1/2/3/4/a or * to exit | " -n 1 -s x
case "${x}" in
0) _device_build="gemini" _device_echo="Gemini";;
1) _device_build="capricorn" _device_echo="Capricorn";;
2) _device_build="natrium" _device_echo="Natrium";;
3) _device_build="lithium" _device_echo="Lithium";;
4) _device_build="scorpio" _device_echo="Scorpio";;
a) _device_build="all" _device_echo="All Devices";;
*) echo "${x} | Exiting from script!";;
esac
fi
if [ "${_device_build}" == "" ]
then
_unset_and_stop
fi
echo " | Building to ${_device_echo}"
# Builing Android
echo " |"
echo " | Starting Android Building!"
if [ "${_device_build}" == "gemini" ] || [ "${_device_build}" == "all" ]
then
_if_fail_break "brunch gemini"
fi
if [ "${_device_build}" == "capricorn" ] || [ "${_device_build}" == "all" ]
then
_if_fail_break "brunch capricorn"
fi
if [ "${_device_build}" == "natrium" ] || [ "${_device_build}" == "all" ]
then
_if_fail_break "brunch natrium"
fi
if [ "${_device_build}" == "lithium" ] || [ "${_device_build}" == "all" ]
then
_if_fail_break "brunch lithium"
fi
if [ "${_device_build}" == "scorpio" ] || [ "${_device_build}" == "all" ]
then
_if_fail_break "brunch scorpio"
fi
# Exit
_unset_and_stop
done
# Goodbye!
echo " |"
echo " | Thanks for using this script!"