forked from jfloff/docker-lineageos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineageos
executable file
·304 lines (259 loc) · 8.17 KB
/
lineageos
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
#!/bin/bash -li
############################
# References:
# - Lineage KLTE build instructions:
# https://wiki.lineageos.org/devices/klte/build
# - User setup for building:
# http://android-rebuilds.beuc.net/SDK_6.0.0/
# - Parameter expansion:
# http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html (2.6.2)
# ARGUMENTS
INIT=0
SYNC=0
BUILD=0
FORCE_CLEAN=0
CLEAN=0
INSTALL_CLEAN=0
USAGE="$(basename "$0") <arg> -- Helper for lineage compilation tool
where <arg> can be :
-fc|--force-clean -- Cleans the LineageOS repository folder
-c|--clean -- Runs 'make clean'
-ic|--install-clean -- Runs 'make installclean'
i|init -- Init lineage repo
b|build -- Compiles LineageOS
s|sync -- Syncs LineageOS repo
all -- shortcut for performing 'lineageos init build'
"
# Argparse
while [[ $# > 0 ]]; do
key="$1"
shift
case $key in
i|init)
INIT=1
;;
b|build)
BUILD=1
;;
all)
INIT=1
BUILD=1
;;
s|sync)
SYNC=1
;;
-fc|--force-clean)
FORCE_CLEAN=1
;;
-c|--clean)
CLEAN=1
;;
-ic|--install-clean)
INSTALL_CLEAN=1
;;
-h|--help)
echo "$USAGE"
;;
*)
echo "[ERROR] Options not found."
echo "$USAGE"
;;
esac
done
############################
# VARS
#
BASHRC=$BASE_DIR/.bashrc
LINEAGEOS_DEV_INIT=$BASE_DIR/.lineageos_dev_init
############################
# Functions
#
function force_clean {
echo "[INFO] Cleaning repo ..."
# remove everything in the repo
rm -rf ..?* .[!.]* *
# redo the .keep file
mkdir -p $CCACHE_DIR
# removing init file
rm -f $LINEAGEOS_DEV_INIT
}
function clean {
source $BASE_DIR/build/envsetup.sh
if [[ $INSTALL_CLEAN == 1 ]]; then
echo "[INFO] Run 'make installclean'"
mka installclean
else
echo "[INFO] Run 'make clean'"
mka clean
fi
}
function reload_bashrc {
PS1='foobar'
source $BASHRC
}
function config_git {
if [[ ! -z $GIT_USER_NAME ]]; then
git config --global user.name "$GIT_USER_NAME";
fi
if [[ ! -z $GIT_USER_EMAIL ]]; then
git config --global user.email "$GIT_USER_EMAIL";
fi
# if [[ (! $(git config --global --get user.name)) || (! $(git config --global --get user.email)) ]]; then
# echo "[WARNING] No git identity defined. Provide them as env variables (more info @ README)."
# echo " As an alternative you can input them directly next ..."
# YN='no'
# while [[ $YN != 'yes' ]] ; do
# read -p "Git user name: " GIT_USER_NAME
# read -p "Git user email: " GIT_USER_EMAIL
# read -p "Accept the input [$GIT_USER_NAME/$GIT_USER_EMAIL] (yes/no)? " YN
# done
# sudo git config --global user.name "$GIT_USER_NAME";
# sudo git config --global user.email "$GIT_USER_EMAIL";
# fi;
}
function init {
# EVERYTHING BELOW NEEDS INIT FIRST
if [ -s $LINEAGEOS_DEV_INIT ]; then
echo "[INFO] Repository already initialized. Use [-fc|--force-clean] for a clean init."
fi
config_git;
echo "[INFO] Initializing repository."
# forces yes to the anoying color output prompt
yes | repo init -u $LINEAGEOS_REPO -b $LINEAGEOS_BRANCH
# Update tree with the local manifest (if provided)
if [[ ! -z $LINEAGEOS_LOCAL_MANIFEST_REPO ]]; then
echo "[INFO] Updating Lineage with local manifest repositories."
git clone $LINEAGEOS_LOCAL_MANIFEST_REPO .repo/local_manifests -b $LINEAGEOS_LOCAL_MANIFEST_BRANCH
fi
# download repo
sync
if [[ ! -z $PROPRIETARY_BLOBS_REPO ]]; then
echo "[INFO] Cloning device's proprietary blobs"
# We could possibly improve this by clever search in the device/ folder
# but that would be too much work
# - https://stackoverflow.com/a/18194523/1700053
#
# AS A USER: - if you don't want to download a whole repo, use the EXTRA_DOWNLOAD_X variables
# - if you have the device itself you can use EXTRA_DOWNLOADS_* var
if [ ! -d "$PROPRIETARY_BLOBS_DIR" ]; then
git clone -b $LINEAGEOS_BRANCH --single-branch $PROPRIETARY_BLOBS_REPO $PROPRIETARY_BLOBS_DIR
else
pushd $PROPRIETARY_BLOBS_DIR > /dev/null 2>&1
git pull
popd > /dev/null 2>&1
fi
fi
echo "[INFO] Downloading extra files"
while read -r download ; do
if [[ ! -z $download ]]; then
URL=$download[0]
TARGET=$download[1]
echo "- Downloading '${!URL}' to '${!TARGET}' ..."
curl -#L --create-dirs -o ${!TARGET} ${!URL}
fi
done <<< "$(set | grep -oP '^\w*EXTRA_DOWNLOAD_\w*(?==)')"
if [[ "$USE_CCACHE" == "1" ]]; then
echo "[INFO] Enable caching at '$CCACHE_DIR' with $CCACHE_SIZE"
prebuilts/misc/linux-x86/ccache/ccache -M $CCACHE_SIZE
fi
echo "[INFO] Setup 'build/envsetup.sh'"
# https://askubuntu.com/questions/650820/permission-denied-when-running-sh-file
chmod u+x build/envsetup.sh
shopt -s expand_aliases
source $BASE_DIR/build/envsetup.sh
if [[ ! -z $BUILD_FLAVOR ]]; then
breakfast lineage_$DEVICE_CODENAME-$BUILD_FLAVOR
else
breakfast $DEVICE_CODENAME
fi
echo "[INFO] Export environment setup into '$LINEAGEOS_DEV_INIT'."
# Create own script so we user is free to modify its .bashrc
echo "
# expand envsetup at startup if its avalable
if [[ -f $BASE_DIR/build/envsetup.sh ]]; then
shopt -s expand_aliases
source $BASE_DIR/build/envsetup.sh
fi
" > $LINEAGEOS_DEV_INIT
# Add script to .bashrc
sudo touch $BASHRC
declare -a lines=("[[ -f $LINEAGEOS_DEV_INIT ]] && source $LINEAGEOS_DEV_INIT")
for line in "${lines[@]}"; do
grep -qF "$line" "$BASHRC" || echo "$line" | sudo tee --append $BASHRC
done
echo "[DONE] Init done."
}
function sync {
if [[ ! -z $PRE_SYNC_SCRIPT ]]; then
echo "[INFO] Run pre-sync script"
source "$PRE_SYNC_SCRIPT"
fi
if [[ ! -z $LINEAGEOS_LOCAL_MANIFEST_REPO ]]; then
if [[ ! -d .repo/local_manifests ]]; then
echo "[INFO] Updating Lineage with local manifest repositories."
git clone $LINEAGEOS_LOCAL_MANIFEST_REPO .repo/local_manifests -b $LINEAGEOS_LOCAL_MANIFEST_BRANCH
fi
fi
echo "[INFO] Sync repository"
repo sync --force-sync -c -j $(nproc --all)
if [[ ! -z $PROPRIETARY_BLOBS_REPO ]]; then
# update mupets
echo "[INFO] Updating device's proprietary blobs repository"
pushd $PROPRIETARY_BLOBS_DIR > /dev/null 2>&1
git pull
popd > /dev/null 2>&1
fi
}
function build {
if [[ ! -z $PRE_BUILD_SCRIPT ]]; then
echo "[INFO] Run pre-build script"
source "$PRE_BUILD_SCRIPT"
fi
echo "[INFO] Building LineageOS ..."
shopt -s expand_aliases
source $BASE_DIR/build/envsetup.sh
if [[ "$USE_CCACHE" == "1" ]]; then
prebuilts/misc/linux-x86/ccache/ccache -M $CCACHE_SIZE
fi
# starts configuration
if [[ ! -z $BUILD_FLAVOR ]]; then
breakfast lineage_$DEVICE_CODENAME-$BUILD_FLAVOR
else
breakfast $DEVICE_CODENAME
fi
# starts building
croot
if [[ ! -z $BUILD_FLAVOR ]]; then
brunch lineage_$DEVICE_CODENAME-$BUILD_FLAVOR
else
brunch $DEVICE_CODENAME
fi
if [[ ! -z $POST_BUILD_SCRIPT ]]; then
echo "[INFO] Run post-build script"
source "$POST_BUILD_SCRIPT"
fi
}
############################
# Script options
#
pushd $BASE_DIR > /dev/null 2>&1
if [[ $FORCE_CLEAN == 1 ]]; then
force_clean;
fi
if [[ $INIT == 1 ]]; then
init;
fi
if [[ $CLEAN == 1 ]]; then
clean;
elif [[ $INSTALL_CLEAN == 1 ]]; then
clean;
fi
# if sync repo passes forces a lineage repo sync
if [[ $SYNC == 1 ]]; then
sync;
fi
# if sync repo passes forces a lineage repo sync
if [[ $BUILD == 1 ]]; then
build;
fi
popd > /dev/null 2>&1