forked from byf3332/sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorangefox_sync.sh
502 lines (426 loc) · 16.5 KB
/
orangefox_sync.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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#!/bin/bash
# ***************************************************************************************
# - Script to set up things for building OrangeFox with a minimal build system
# - Syncs the relevant twrp minimal manifest, and patches it for building OrangeFox
# - Pulls in the OrangeFox recovery sources and vendor tree
# - Author: DarthJabba9
# - Version: generic:014
# - Date: 08 September 2022
#
# * Changes for v007 (20220430) - make it clear that fox_12.1 is not ready
# * Changes for v008 (20220708) - fox_12.1 is now ready
# * Changes for v009 (20220708A) - try to cherry-pick the system vold stuff from gerrit
# * Changes for v010 (20220708B) - move the cherry-pick call
# * Changes for v011 (20220731) - update the system vold patchset number to 10
# * Changes for v012 (20220806) - update the system vold patchset number to 12
# * Changes for v013 (20220803) - try to ensure that the submodules are updated
# * Changes for v014 (20220908) - don't apply the system vold patch: it is no longer needed
#
# ***************************************************************************************
# the version number of this script
SCRIPT_VERSION="20220908";
# the base version of the current OrangeFox
FOX_BASE_VERSION="R11.1";
# Our starting point (Fox base dir)
BASE_DIR="$PWD";
# default directory for the new manifest
MANIFEST_DIR="";
# functions to set up things for each supported manifest branch
do_fox_121() {
BASE_VER=12;
FOX_BRANCH="fox_12.1";
FOX_DEF_BRANCH="fox_12.1";
TWRP_BRANCH="twrp-12.1";
DEVICE_BRANCH="android-12.1";
test_build_device="miatoll"; # the device whose tree we can clone for compiling a test build
MIN_MANIFEST="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_aosp.git";
[ -z "$MANIFEST_DIR" ] && MANIFEST_DIR="$BASE_DIR/$FOX_DEF_BRANCH";
echo "-- NOTE: the \"$FOX_BRANCH\" branch is still work-in-progress, and will stay for some time at the Beta stage. Treat it as such.";
}
do_fox_110() {
BASE_VER=11;
FOX_BRANCH="fox_11.0";
FOX_DEF_BRANCH="fox_11.0";
TWRP_BRANCH="twrp-11";
DEVICE_BRANCH="android-11";
test_build_device="vayu"; # the device whose tree we can clone for compiling a test build
MIN_MANIFEST="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_aosp.git";
[ -z "$MANIFEST_DIR" ] && MANIFEST_DIR="$BASE_DIR/$FOX_DEF_BRANCH";
echo "-- NOTE: the \"$FOX_BRANCH\" branch is still BETA as far as Virtual A/B (\"VAB\") devices are concerned. Treat it as such.";
}
do_fox_100() {
BASE_VER=10;
FOX_BRANCH="fox_10.0";
FOX_DEF_BRANCH="fox_10.0";
TWRP_BRANCH="twrp-10.0-deprecated";
DEVICE_BRANCH="android-10";
test_build_device="miatoll";
MIN_MANIFEST="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git";
[ -z "$MANIFEST_DIR" ] && MANIFEST_DIR="$BASE_DIR/$FOX_DEF_BRANCH";
}
do_fox_90() {
BASE_VER=9;
FOX_BRANCH="fox_9.0";
FOX_DEF_BRANCH="fox_9.0";
TWRP_BRANCH="twrp-9.0";
DEVICE_BRANCH="android-9.0";
test_build_device="mido";
MIN_MANIFEST="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git";
[ -z "$MANIFEST_DIR" ] && MANIFEST_DIR="$BASE_DIR/$FOX_DEF_BRANCH";
}
do_fox_81() {
BASE_VER=8;
FOX_BRANCH="fox_9.0";
FOX_DEF_BRANCH="fox_8.1";
TWRP_BRANCH="twrp-8.1";
DEVICE_BRANCH="android-8.1";
test_build_device="kenzo";
MIN_MANIFEST="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git";
[ -z "$MANIFEST_DIR" ] && MANIFEST_DIR="$BASE_DIR/$FOX_DEF_BRANCH";
}
do_fox_71() {
BASE_VER=6;
FOX_BRANCH="fox_9.0";
FOX_DEF_BRANCH="fox_7.1";
TWRP_BRANCH="twrp-7.1";
DEVICE_BRANCH="android-7.1";
test_build_device="hermes";
MIN_MANIFEST="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git";
[ -z "$MANIFEST_DIR" ] && MANIFEST_DIR="$BASE_DIR/$FOX_DEF_BRANCH";
}
do_fox_60() {
BASE_VER=6;
FOX_BRANCH="fox_9.0";
FOX_DEF_BRANCH="fox_6.0";
TWRP_BRANCH="twrp-6.0";
DEVICE_BRANCH="android-6.0";
test_build_device="klte";
MIN_MANIFEST="https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git";
[ -z "$MANIFEST_DIR" ] && MANIFEST_DIR="$BASE_DIR/$FOX_DEF_BRANCH";
}
# help
help_screen() {
echo "Script to set up things for building OrangeFox with a twrp minimal manifest";
echo "Usage = $0 <arguments>";
echo "Arguments:";
echo " -h, -H, --help print this help screen and quit";
echo " -d, -D, --debug debug mode: print each command being executed";
echo " -s, -S, --ssh <'0' or '1'> set 'USE_SSH' to '0' or '1'";
echo " -p, -P, --path <absolute_path> sync the minimal manifest into the directory '<absolute_path>'";
echo " -b, -B, --branch <branch> get the minimal manifest for '<branch>'";
echo " '<branch>' must be one of the following branches:";
echo " 12.1";
echo " 11.0";
echo " 10.0";
echo " 9.0";
echo " 8.1";
echo " 7.1";
echo " 6.0";
echo "Examples:";
echo " $0 --branch 12.1 --path ~/OrangeFox_12.1";
echo " $0 --branch 11.0 --path ~/OrangeFox_11.0";
echo " $0 --branch 10.0 --path ~/OrangeFox_10 --ssh 1";
echo " $0 --branch 9.0 --path ~/OrangeFox/9.0 --debug";
echo "";
echo "- You *MUST* supply an *ABSOLUTE* path for the '--path' switch";
exit 0;
}
#######################################################################
# test the command line arguments
Process_CMD_Line() {
if [ -z "$1" ]; then
help_screen;
fi
while (( "$#" )); do
case "$1" in
# debug mode - show some verbose outputs
-d | -D | --debug)
set -o xtrace;
;;
# help
-h | -H | --help)
help_screen;
;;
# ssh
-s | -S | --ssh)
shift;
[ "$1" = "0" -o "$1" = "1" ] && USE_SSH=$1 || USE_SSH=0;
;;
# path
-p | -P | --path)
shift;
[ -n "$1" ] && MANIFEST_DIR=$1;
;;
# branch
-b | -B | --branch)
shift;
if [ "$1" = "12.1" ]; then do_fox_121;
elif [ "$1" = "11.0" ]; then do_fox_110;
elif [ "$1" = "10.0" ]; then do_fox_100;
elif [ "$1" = "9.0" ]; then do_fox_90;
elif [ "$1" = "8.1" ]; then do_fox_81;
elif [ "$1" = "7.1" ]; then do_fox_71;
elif [ "$1" = "6.0" ]; then do_fox_60;
else
echo "Invalid branch \"$1\". Read the help screen below.";
echo "";
help_screen;
fi
;;
esac
shift
done
# do we have all the necessary branch information?
if [ -z "$FOX_BRANCH" -o -z "$TWRP_BRANCH" -o -z "$DEVICE_BRANCH" -o -z "$FOX_DEF_BRANCH" ]; then
echo "No branch has been specified. Read the help screen below.";
echo "";
help_screen;
fi
# do we have a manifest directory?
if [ -z "$MANIFEST_DIR" ]; then
echo "No path has been specified for the manifest. Read the help screen below.";
echo "";
help_screen;
fi
}
#######################################################################
# print message and quit
abort() {
echo "$@";
exit 1;
}
# update the environment after processing the command line
update_environment() {
# where to log the location of the manifest directory upon successful sync and patch
SYNC_LOG="$BASE_DIR"/"$FOX_DEF_BRANCH"_"manifest.sav";
# by default, don't use SSH for the "git clone" commands; to use SSH, you can also export USE_SSH=1 before starting
[ -z "$USE_SSH" ] && USE_SSH="0";
# the "diff" file that will be used to patch the original manifest
PATCH_FILE="$BASE_DIR/patches/patch-manifest-$FOX_DEF_BRANCH.diff";
# the directory in which the patch of the manifest will be executed
MANIFEST_BUILD_DIR="$MANIFEST_DIR/build";
}
# init the script, ensure we have the patch file, and create the manifest directory
init_script() {
echo "-- Starting the script ...";
[ ! -f "$PATCH_FILE" ] && abort "-- I cannot find the patch file: $PATCH_FILE - quitting!";
echo "-- The new build system will be located in \"$MANIFEST_DIR\"";
mkdir -p $MANIFEST_DIR;
[ "$?" != "0" -a ! -d $MANIFEST_DIR ] && {
abort "-- Invalid directory: \"$MANIFEST_DIR\". Quitting.";
}
}
# repo init and repo sync
get_twrp_minimal_manifest() {
cd $MANIFEST_DIR;
echo "-- Initialising the $TWRP_BRANCH minimal manifest repo ...";
repo init --depth=1 -u $MIN_MANIFEST -b $TWRP_BRANCH;
[ "$?" != "0" ] && {
abort "-- Failed to initialise the minimal manifest repo. Quitting.";
}
echo "-- Done.";
echo "-- Syncing the $TWRP_BRANCH minimal manifest repo ...";
repo sync;
[ "$?" != "0" ] && {
abort "-- Failed to Sync the minimal manifest repo. Quitting.";
}
echo "-- Done.";
}
# patch the build system for OrangeFox
patch_minimal_manifest() {
echo "-- Patching the $TWRP_BRANCH minimal manifest for building OrangeFox for native $DEVICE_BRANCH devices ...";
cd $MANIFEST_BUILD_DIR;
patch -p1 < $PATCH_FILE;
[ "$?" = "0" ] && echo "-- The $TWRP_BRANCH minimal manifest has been patched successfully" || abort "-- Failed to patch the $TWRP_BRANCH minimal manifest! Quitting.";
# save location of manifest dir
echo "#" &> $SYNC_LOG;
echo "MANIFEST_DIR=$MANIFEST_DIR" >> $SYNC_LOG;
echo "#" >> $SYNC_LOG;
}
# get the qcom/twrp common stuff
clone_common() {
cd $MANIFEST_DIR/;
if [ ! -d "device/qcom/common" ]; then
echo "-- Cloning qcom common ...";
git clone https://github.com/TeamWin/android_device_qcom_common -b $DEVICE_BRANCH device/qcom/common;
fi
if [ ! -d "device/qcom/twrp-common" ]; then
echo "-- Cloning twrp-common ...";
git clone https://github.com/TeamWin/android_device_qcom_twrp-common -b $DEVICE_BRANCH device/qcom/twrp-common;
fi
}
# get the OrangeFox recovery sources
clone_fox_recovery() {
local URL="";
local BRANCH=$FOX_BRANCH;
if [ "$USE_SSH" = "0" ]; then
URL="https://gitlab.com/OrangeFox/bootable/Recovery.git";
else
URL="[email protected]:OrangeFox/bootable/Recovery.git";
fi
mkdir -p $MANIFEST_DIR/bootable;
[ ! -d $MANIFEST_DIR/bootable ] && {
echo "-- Invalid directory: $MANIFEST_DIR/bootable";
return;
}
cd $MANIFEST_DIR/bootable/;
[ -d recovery/ ] && {
echo "-- Moving the TWRP recovery sources to /tmp";
rm -rf /tmp/recovery;
mv recovery /tmp;
}
echo "-- Pulling the OrangeFox recovery sources ...";
git clone --recurse-submodules $URL -b $BRANCH recovery;
[ "$?" = "0" ] && echo "-- The OrangeFox sources have been cloned successfully" || echo "-- Failed to clone the OrangeFox sources!";
# check that the themes are correctly downloaded
if [ ! -f recovery/gui/theme/portrait_hdpi/ui.xml ]; then
echo "-- Themes not found! Trying again to pull the themes ...";
if [ "$USE_SSH" = "0" ]; then
URL="https://gitlab.com/OrangeFox/misc/theme.git";
else
URL="[email protected]:OrangeFox/misc/theme.git";
fi
[ -d recovery/gui/theme ] && rm -rf recovery/gui/theme;
git clone $URL recovery/gui/theme;
[ "$?" = "0" ] && echo "-- The themes have been cloned successfully" || echo "-- Failed to clone the themes!";
fi
# ensure that the submodules are updated
if [ -d $MANIFEST_DIR/bootable/recovery/gui/theme ]; then
cd $MANIFEST_DIR/bootable/recovery/;
git submodule foreach --recursive git pull origin master;
cd $MANIFEST_DIR/bootable/;
fi
# cleanup /tmp/recovery/
echo "-- Cleaning up the TWRP recovery sources from /tmp";
rm -rf /tmp/recovery;
# create the directory for Xiaomi device trees
mkdir -p $MANIFEST_DIR/device/xiaomi;
}
# get the OrangeFox vendor
clone_fox_vendor() {
local URL="";
local BRANCH=$FOX_BRANCH;
[ "$BASE_VER" -lt 10 ] && BRANCH="master"; # less than fox_10.0 use the "master" branch
if [ "$USE_SSH" = "0" ]; then
URL="https://gitlab.com/OrangeFox/vendor/recovery.git";
else
URL="[email protected]:OrangeFox/vendor/recovery.git";
fi
echo "-- Preparing for cloning the OrangeFox vendor tree ...";
rm -rf $MANIFEST_DIR/vendor/recovery;
mkdir -p $MANIFEST_DIR/vendor;
[ ! -d $MANIFEST_DIR/vendor ] && {
echo "-- Invalid directory: $MANIFEST_DIR/vendor";
return;
}
cd $MANIFEST_DIR/vendor;
echo "-- Pulling the OrangeFox vendor tree ...";
git clone $URL -b $BRANCH recovery;
[ "$?" = "0" ] && echo "-- The OrangeFox vendor tree has been cloned successfully" || echo "-- Failed to clone the OrangeFox vendor tree!";
}
# get the OrangeFox busybox sources
clone_fox_busybox() {
local URL="";
local BRANCH="android-9.0";
[ "$BASE_VER" != "9" ] && return; # only clone busybox for 9.0
if [ "$USE_SSH" = "0" ]; then
URL="https://gitlab.com/OrangeFox/external/busybox.git";
else
URL="[email protected]:OrangeFox/external/busybox.git";
fi
echo "-- Preparing for cloning the OrangeFox busybox sources ...";
cd $MANIFEST_DIR/external;
echo "-- Pulling the OrangeFox busybox sources ...";
git clone $URL -b $BRANCH busybox;
[ "$?" = "0" ] && echo "-- The OrangeFox busybox sources have been cloned successfully" || echo "-- Failed to clone the OrangeFox busybox sources!";
}
# get device trees
get_device_tree() {
local DIR=$MANIFEST_DIR/device/xiaomi;
mkdir -p $DIR;
cd $DIR;
[ "$?" != "0" ] && {
abort "-- get_device_tree() - Invalid directory: $DIR";
}
# test device
local [email protected]:OrangeFox/device/"$test_build_device".git;
[ "$USE_SSH" = "0" ] && URL=https://gitlab.com/OrangeFox/device/"$test_build_device".git;
echo "-- Pulling the $test_build_device device tree ...";
git clone $URL -b "$FOX_DEF_BRANCH" "$test_build_device";
# done
if [ -d "$test_build_device" -a -d "$test_build_device/recovery" ]; then
echo "-- Finished fetching the OrangeFox $test_build_device device tree.";
else
abort "-- get_device_tree() - could not fetch the OrangeFox $test_build_device device tree.";
fi
}
# [temporary fix - WiP] cherry-pick system/vold stuff from the twrp gerrit;
# will require amending if the patch set changes on gerrit (which will definitely happen sooner or later)
cherry_picks() {
[ "$BASE_VER" != "12" ] && return; # this is for fox_12.1 only
echo "You need to cherry-pick this commit into system/vold/: https://gerrit.twrp.me/c/android_system_vold/+/5540";
echo "I will try to do so now. If any errors occur, then you should abort the cherry-pick and then do it manually.";
local patchset=12; # the current patch set number
cd $MANIFEST_DIR/system/vold/;
git fetch https://gerrit.twrp.me/android_system_vold refs/changes/40/5540/$patchset && git cherry-pick FETCH_HEAD;
echo ""
echo "Every time you run 'repo sync', you must also cherry-pick this commit into system/vold/: https://gerrit.twrp.me/c/android_system_vold/+/5540";
}
# test build
test_build() {
# clone the device tree
get_device_tree;
# proceed with the test build
export FOX_VERSION="$FOX_BASE_VERSION"_"$FOX_DEF_BRANCH";
export LC_ALL="C";
export FOX_BUILD_TYPE="Alpha";
export ALLOW_MISSING_DEPENDENCIES=true;
export FOX_BUILD_DEVICE="$test_build_device";
export OUT_DIR=$BASE_DIR/BUILDS/"$test_build_device";
cd $BASE_DIR/;
mkdir -p $OUT_DIR;
cd $MANIFEST_DIR/;
echo "-- Compiling a test build for device \"$test_build_device\". This will take a *VERY* long time ...";
echo "-- Start compiling: ";
. build/envsetup.sh;
# what are we lunching (AOSP or Omni)>
if [ "$BASE_VER" -gt 10 ]; then
lunch twrp_"$test_build_device"-eng;
else
lunch omni_"$test_build_device"-eng;
fi
# build for the device
# are we building for a virtual A/B (VAB) device? (default is "no")
local FOX_VAB_DEVICE=0;
if [ "$FOX_VAB_DEVICE" = "1" ]; then
mka adbd bootimage;
else
mka adbd recoveryimage;
fi
# any results?
ls -all $(find "$OUT_DIR" -name "OrangeFox-*");
}
# do all the work!
WorkNow() {
echo "$0, v$SCRIPT_VERSION";
local START=$(date);
Process_CMD_Line "$@";
update_environment;
init_script;
get_twrp_minimal_manifest;
patch_minimal_manifest;
clone_common;
clone_fox_recovery;
clone_fox_vendor;
clone_fox_busybox;
# cherry_picks; # 20220908 - comment this out: no longer needed
# test_build; # comment this out - don't do a test build by default
local STOP=$(date);
echo "-- Stop time =$STOP";
echo "-- Start time=$START";
echo "-- Now, clone your device trees to the correct locations!";
exit 0;
}
# --- main() ---
WorkNow "$@";
# --- end main() ---