-
Notifications
You must be signed in to change notification settings - Fork 8
/
er.sh
executable file
·596 lines (522 loc) · 23.8 KB
/
er.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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#!/bin/bash
############################################################################
#
# Copyright (C) 2017-2018 Andreas Schneider <asn@crytpomilk.org>
# Copyright (C) 2020-2024 steadfasterX <steadfasterX@binbash.rocks>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
############################################################################
# be strict on failures
set -e
# colored (optional) output
PRINT(){
MSG="$2"
case $1 in
ERROR)
echo -e "\e[0;31mERROR: ${MSG}\e[0m" ;;
INFO)
echo -e "\e[1;34mINFO: ${MSG}\e[0m" ;;
OK)
echo -e "\e[0;32mOK: ${MSG}\e[0m" ;;
*)
echo -e "${MSG}" ;;
esac
}
# trap and print errors
_fetchError(){
local cnt=1
local last_status="$1"
local error_line_number="$2"
local last_func="$3"
local file="$4"
echo -e "\n\e[0;31mbash stack trace (first occurence is likely where you should look at):\e[0m\n"
if [ ! -z "$last_func" ] && [ ! -z "$file" ];then
PRINT ERROR "$file -> function: ${last_func}() ended with status >${last_status}< at line >$((error_line_number -1))< of that function"
else
PRINT ERROR "last command ended with status >${last_status}< at line >$((error_line_number -1))<"
fi
trap - EXIT ERR
}; export -f _fetchError
# ERR: needed to fetch aborts when set -e is set
trap 'ret=$?; _fetchError $ret $LINENO $FUNCNAME $BASH_SOURCE' EXIT ERR
#SIGINT SIGHUP TERM
######################
# parse through all supported makefile options and set them as env variable
# vendorsetup.sh will always take precedence though
MKOPTS="ENABLE_EXTENDROM \
EXTENDROM_SIGNING_PATCHES \
EXTENDROM_SIGNING_FORCE_PDIR \
EXTENDROM_PACKAGES \
EXTENDROM_PACKAGES_SKIP_DL \
EXTENDROM_BOOT_DEBUG \
EXTENDROM_DEBUG_PATH \
EXTENDROM_DEBUG_PATH_SIZE_FULL \
EXTENDROM_DEBUG_PATH_SIZE_CRASH \
EXTENDROM_DEBUG_PATH_SIZE_KERNEL \
EXTENDROM_DEBUG_PATH_SIZE_SELINUX \
EXTENDROM_PREROOT_BOOT \
EXTENDROM_FDROID_REPOS \
EXTENDROM_SIGNATURE_SPOOFING \
EXTENDROM_PATCHER_RESET \
EXTENDROM_SIGSPOOF_FORCE_PDIR"
for opt in $MKOPTS; do
[ -z "${!opt}" ] && export ${opt}="$(build/soong/soong_ui.bash --dumpvar-mode $opt 2>/dev/null)" && [ ! -z "${!opt}" ] && echo ".. setting $opt=${!opt} by makefile"
done
# check first if we want extendrom at all
if [ "$ENABLE_EXTENDROM" != "true" ];then echo "extendrom is disabled so no further processing" && exit;fi
echo -e "\n\n************************************************** STARTING EXTENDROM **************************************************\n\n"
####################
# base info
echo "extendrom version: $(repo forall vendor/extendrom -c 'git rev-parse --symbolic-full-name HEAD; git rev-parse --short=7 HEAD' 2>/dev/null | tr '\n' ' ')"
echo -e "\n\n"
echo "ENABLE_EXTENDROM: $ENABLE_EXTENDROM"
echo "EXTENDROM_PREROOT_BOOT: $EXTENDROM_PREROOT_BOOT"
echo "EXTENDROM_PACKAGES: $EXTENDROM_PACKAGES"
echo "EOS_EDITION: $EOS_EDITION"
echo "EXTENDROM_SIGNING_PATCHES: $EXTENDROM_SIGNING_PATCHES"
echo "EXTENDROM_SIGNING_FORCE_PDIR: $EXTENDROM_SIGNING_FORCE_PDIR"
echo "EXTENDROM_SIGNATURE_SPOOFING: $EXTENDROM_SIGNATURE_SPOOFING"
echo "EXTENDROM_SIGSPOOF_RESET: $EXTENDROM_SIGSPOOF_RESET"
echo "EXTENDROM_SIGSPOOF_FORCE_PDIR: $EXTENDROM_SIGSPOOF_FORCE_PDIR"
export EXTENDROM_TARGET_VERSION=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION 2>/dev/null)
echo "EXTENDROM_TARGET_VERSION: $EXTENDROM_TARGET_VERSION"
EXTENDROM_TARGET_PRODUCT_F=$(build/soong/soong_ui.bash --dumpvar-mode TARGET_PRODUCT 2>/dev/null)
export EXTENDROM_TARGET_PRODUCT=${EXTENDROM_TARGET_PRODUCT_F/_*}
echo "EXTENDROM_TARGET_PRODUCT: $EXTENDROM_TARGET_PRODUCT"
export SRC_TOP=$(build/soong/soong_ui.bash --dumpvar-mode TOP 2>/dev/null)
echo "SRC_TOP: ${SRC_TOP}/"
SRC_TOP_FULL=$(pwd)
echo SRC_TOP_FULL: $SRC_TOP_FULL
# boot debug log
export EXTENDROM_PRODUCT_DEVICE=$(build/soong/soong_ui.bash --dumpvar-mode PRODUCT_DEVICE 2>/dev/null)
echo "EXTENDROM_PRODUCT_DEVICE=$EXTENDROM_PRODUCT_DEVICE"
echo "EXTENDROM_BOOT_DEBUG=$EXTENDROM_BOOT_DEBUG"
# set default debug path if unset
[ -z "$EXTENDROM_DEBUG_PATH" ] && export EXTENDROM_DEBUG_PATH=/data/vendor_de
echo "EXTENDROM_DEBUG_PATH=$EXTENDROM_DEBUG_PATH (will be suffixed with /boot_debug)"
# set default file sizes for debug logs
[ -z "$EXTENDROM_DEBUG_PATH_SIZE_FULL" ] && export EXTENDROM_DEBUG_PATH_SIZE_FULL=5000
[ -z "$EXTENDROM_DEBUG_PATH_SIZE_CRASH" ] && export EXTENDROM_DEBUG_PATH_SIZE_CRASH=500
[ -z "$EXTENDROM_DEBUG_PATH_SIZE_KERNEL" ] && export EXTENDROM_DEBUG_PATH_SIZE_KERNEL=500
[ -z "$EXTENDROM_DEBUG_PATH_SIZE_SELINUX" ] && export EXTENDROM_DEBUG_PATH_SIZE_SELINUX=500
echo "EXTENDROM_DEBUG_PATH_SIZE_FULL=$EXTENDROM_DEBUG_PATH_SIZE_FULL KB"
echo "EXTENDROM_DEBUG_PATH_SIZE_CRASH=$EXTENDROM_DEBUG_PATH_SIZE_CRASH KB"
echo "EXTENDROM_DEBUG_PATH_SIZE_KERNEL=$EXTENDROM_DEBUG_PATH_SIZE_KERNEL KB"
echo "EXTENDROM_DEBUG_PATH_SIZE_SELINUX=$EXTENDROM_DEBUG_PATH_SIZE_SELINUX KB"
# main repo used for downloading F-Droid apk's
FDROID_REPO_URL="https://mirror.cyberbits.eu/fdroid/repo/"
# list of keyservers for importing gpg pub keys
# space separated
GPG_KEYSERVER="keyserver.ubuntu.com pgp.mit.edu keys.openpgp.org keyring.debian.org"
# gpg keys to import
# space separated
# f-droid: 7A029E54DD5DCE7A
# microg: 22F796D6E62E6625A0BCEFEA7F979A66F3E08422
GPG_KEYS="7A029E54DD5DCE7A 22F796D6E62E6625A0BCEFEA7F979A66F3E08422"
# force a gpg pub key refresh
# 0: will only download pub key when not installed
# 1: will always download pub key even when installed already
GPG_FORCE_DL=0
###########################################################
REQ_BINARIES="aapt"
for bin in $REQ_BINARIES;do
which $bin || (PRINT ERROR "missing required binary: $bin" && false)
done
MY_DIR="$1"
[ -z "$MY_DIR" ] && MY_DIR=vendor/extendrom
echo MY_DIR: $MY_DIR
_OUTDIR="$MY_DIR/out"
[ ! -d "$_OUTDIR" ] && mkdir $_OUTDIR
FDROID_REPO_DIR="$MY_DIR/fdroid_repos"
# write $PRODUCTMK so all EXTENDROM_PACKAGES (except Magisk) will be built by the Android build process
export PRODUCTMK="$MY_DIR/packages.mk"
# write mk vars
export ERMKVARS="ENABLE_EXTENDROM EXTENDROM_BOOT_DEBUG EXTENDROM_PREROOT_BOOT EXTENDROM_SIGNATURE_SPOOFING
"
> $MY_DIR/mkvars.mk
for ermk in $ERMKVARS;do
echo "$ermk := ${!ermk}" >> $MY_DIR/mkvars.mk
done
# prepare to remove Magisk from EXTENDROM_PACKAGES as we don't build it
# see https://github.com/sfX-android/android_vendor_extendrom/wiki/FAQ#extendrom_preroot_boot
if [ "$EXTENDROM_PREROOT_BOOT" == "true" ];then
export MAGNAME=$(echo "$EXTENDROM_PACKAGES" | tr ' ' '\n' | grep -E '^Magisk$|Magisk_v[0-9]+\.[0-9]+$|SignMagisk$')
export EXTENDROM_PACKAGES_CLEANED=$(echo "$EXTENDROM_PACKAGES" | tr ' ' '\n' | sed "s/$MAGNAME//g" | tr '\n' ' ')
echo "PRODUCT_PACKAGES += $EXTENDROM_PACKAGES_CLEANED" > $PRODUCTMK
else
echo "PRODUCT_PACKAGES += $EXTENDROM_PACKAGES" > $PRODUCTMK
fi
unset CURLDNS
CUSTDNS="$2"
[ ! -z "$CUSTDNS" ] && CURLDNS="--dns-servers $CUSTDNS"
PREBUILT_DIR="$MY_DIR/prebuilt"
PARSEAPK="$MY_DIR/tools/get_latest_apkname.py"
CURLARGS=" -L $CURLDNS"
CURL="$MY_DIR/tools/curl_x64_static $CURLARGS"
source $MY_DIR/tools/extract_utils.sh
if [ -d "$PREBUILT_DIR" ] && [ "$EXTENDROM_PACKAGES_SKIP_DL" != "true" ]; then
rm -rf "$PREBUILT_DIR"
fi
mkdir $PREBUILT_DIR $PREBUILT_DIR/app $PREBUILT_DIR/priv-app
function download_package() {
local repo="$1"
local pkg_path="$2"
local pkg_dir=$(dirname $pkg_path)
local pkg="$(basename $pkg_path)"
local pkg_sig="$pkg.asc"
local cmd=""
local out=""
local ret=0
if [ ! -d "$pkg_dir" ]; then
mkdir -p "$pkg_dir"
fi
# skip download if the file exists locally and the user wants to
if [ -s "$pkg_path" ] && [ "$EXTENDROM_PACKAGES_SKIP_DL" == "true" ];then
echo "[$FUNCNAME] ... skipping $pkg, as EXTENDROM_PACKAGES_SKIP_DL=true and pkg exists"
return
fi
echo "[$FUNCNAME] ... downloading package: $pkg"
cmd=$($CURL --fail -o $pkg_path $repo 2>&1)
ret=$?
if [ $ret -ne 0 ]; then
echo "[$FUNCNAME] ERROR: Failed to download $pkg (returned: $ret)"
echo
echo "$CURL --fail -o $pkg_path $repo"
echo "$cmd"
return $ret
fi
if [ "$should_verify" == "true" ];then
echo "[$FUNCNAME] ... downloading signature: ${repo}.asc"
cmd="$CURL -o $pkg_dir/$pkg_sig ${repo}.asc 2>&1"
out=$(eval $cmd)
ret=$?
if [ $ret -ne 0 ]; then
echo "[$FUNCNAME] ERROR: Failed to download $repo/$pkg_sig (returned: $ret)"
echo
echo "$out"
return $ret
fi
fi
}
function verify_package() {
local pkg_path="$1"
local cmd=""
local out=""
local ret=0
echo -n "[$FUNCNAME] ... verifing package signature for $pkg_path: "
cmd="gpg --verify $pkg_path.asc 2>&1"
out=$(eval $cmd)
ret=$?
if [ $ret -ne 0 ]; then
echo "INVALID"
echo
echo "$out"
exit 1
fi
echo "VALID"
}
function get_packages() {
local package_file_list="$1"
for line in $(grep -v '^#' $package_file_list); do
if [ -z "$line" ]; then
continue;
fi
unset repo
local package_name=$(echo ${line} |cut -d "|" -f1)
local package_baseuri=$(echo ${line} |cut -d "|" -f2)
if [ "$package_baseuri" == "FDROIDREPO" ];then
local repouri="${FDROID_REPO_URL}"
else
local repouri="${package_baseuri}"
fi
local package="$PREBUILT_DIR/$package_name"
local target_split=$(echo ${line} |cut -d "|" -f4)
target_pkg="$PREBUILT_DIR/$(target_file $target_split | sed 's/\;.*//')"
local package_human=$(echo $(target_file $target_split | sed 's/\;.*//;s/\.apk//g;s/\.zip//g'))
# do not download what we do not want to build
if [[ ! "$EXTENDROM_PACKAGES" =~ "$package_human" ]];then
echo "[$FUNCNAME] ... skipping $package_human as not requested by EXTENDROM_PACKAGES"
continue
else
for i in $EXTENDROM_PACKAGES; do
if [ "$i" != "$package_human" ];then
EXACTM=0
else
EXACTM=1
break
fi
done
if [ "$EXACTM" -ne 1 ];then
echo "[$FUNCNAME] ... skipping $package_human as not requested by EXTENDROM_PACKAGES"
continue
fi
fi
ERR=0
echo "$package_name" | grep -q "LATEST" || ERR=1
if [ $ERR -eq 0 ];then
echo "[$FUNCNAME] ... parsing repo to find latest apk file name"
old_package_name="$package_name"
#echo "PARSEAPK -repourl ${repouri} -apkname $package_name"
package_name=$(python3 $PARSEAPK -repourl "${repouri}" -apkname "$package_name")
PERR=$?
if [ $PERR -eq 0 ];then
echo "[$FUNCNAME] ... parsing result: $old_package_name -> $package_name"
else
echo "[$FUNCNAME] ... ERROR $PERR occured while identifying the latest apk name from ${FDROID_REPO_URL}"
exit 3
fi
fi
local repo="${repouri}/${package_name}"
should_verify=$(echo ${line} |cut -d "|" -f5)
download_package "$repo" "$package"
if [ $? -ne 0 ];then echo "[$FUNCNAME] ERROR occured while downloading, aborted" && exit 3; fi
if [ "$should_verify" == "true" ];then
verify_package "$package"
fi
local target_split=$(echo ${line} |cut -d "|" -f4)
target_pkg="$PREBUILT_DIR/$(target_file $target_split | sed 's/\;.*//')"
echo "[$FUNCNAME] ... target package: $target_pkg"
if [ "$package" != "$target_pkg" ];then cp $package $target_pkg; fi
if [ $? -ne 0 ];then echo "[$FUNCNAME] ERROR occured during copying, aborted" && exit 3;fi
echo
done
}
F_GET_GPG_KEYS(){
# import all required gpg pub keys
for k in $GPG_KEYS;do
if [ $GPG_FORCE_DL -eq 0 ];then
gpg -k $k 2>&1 >> /dev/null && echo "[$FUNCNAME] ... skipping already imported gpg pub key ($k)" && continue
fi
for s in $GPG_KEYSERVER;do
echo "- trying $k from $s"
gpg --keyserver $s --recv-key $k >> /dev/null 2>&1 && echo "[$FUNCNAME] ... imported gpg key $k from $s" && continue 2
done
echo "[$FUNCNAME] ERROR: Cannot download a required gpg pub key: $k"
exit 3
done
}
# the ultimate boot debugger
F_BOOT_DEBUG(){
export EXTENDROM_DEBUG_PATH_ORIGIN="${EXTENDROM_DEBUG_PATH}"
export EXTENDROM_DEBUG_PATH="${EXTENDROM_DEBUG_PATH}/boot_debug"
# check conflicts first
ERR=0
grep -qr "type boot_debug" ${SRC_TOP}device/ >/dev/null 2>&1|| ERR=1
if [ $ERR -ne 0 ];then
rm -rf $MY_DIR/sepolicy/boot_debug && echo "[$FUNCNAME] ... cleaned sepolicy dir"
mkdir -p $MY_DIR/sepolicy/boot_debug && echo "[$FUNCNAME] ... created sepolicy dir"
for p in $(find $MY_DIR/config/boot_debug/ $MY_DIR/config/boot_debug/${EXTENDROM_PRODUCT_DEVICE}/ -maxdepth 1 -type f -name '*.sepolicy' 2>/dev/null);do
pf=$(basename $p)
cp $p $MY_DIR/sepolicy/boot_debug/${pf/\.sepolicy/} && echo "[$FUNCNAME] ... copied sepolicy file: $pf"
done
# special handling for dedicated /cache partition
if [ "${EXTENDROM_DEBUG_PATH_ORIGIN}" == "/cache" ];then
for p in $(find $MY_DIR/config/boot_debug/cache -maxdepth 1 -type f -name '*.sepolicy' 2>/dev/null);do
pf=$(basename $p)
cp $p $MY_DIR/sepolicy/boot_debug/${pf/\.sepolicy/} && echo "[$FUNCNAME] ... copied sepolicy file: $pf"
done
fi
# special handling for /mnt/vendor/persist
if [ "${EXTENDROM_DEBUG_PATH_ORIGIN}" == "/mnt/vendor/persist" ];then
for p in $(find $MY_DIR/config/boot_debug/persist -maxdepth 1 -type f -name '*.sepolicy' 2>/dev/null);do
pf=$(basename $p)
cp $p $MY_DIR/sepolicy/boot_debug/${pf/\.sepolicy/} && echo "[$FUNCNAME] ... copied sepolicy file: $pf"
done
fi
# special flag since A11 to disable encryption on EXTENDROM_DEBUG_PATH
if [ $EXTENDROM_TARGET_VERSION -ge 11 ];then
MKDARG="encryption=None"
else
MKDARG=""
fi
#sed "s#%%DEBUGLOG_DEVICE%%#$EXTENDROM_DEBUG_DEVICE#g;s#%%DEBUGLOG_PATH%%#$EXTENDROM_DEBUG_PATH#g;s#%%DEBUGLOG_MKDARG%%#$MKDARG#g" $MY_DIR/config/init.er.rc.in > $MY_DIR/config/init.er.rc && echo "[$FUNCNAME] ... configured EXTENDROM_DEBUG_PATH (init.er.rc) to $EXTENDROM_DEBUG_PATH"
#sed "s#%%DEBUGLOG_PATH%%#$EXTENDROM_DEBUG_PATH#g;s#%%DEBUGLOG_MKDARG%%#$MKDARG#g" $MY_DIR/config/init.er.rc.in > $MY_DIR/config/init.er.rc && echo "[$FUNCNAME] ... configured EXTENDROM_DEBUG_PATH (init.er.rc) to $EXTENDROM_DEBUG_PATH"
sed "s#%%DEBUGLOG_PATH%%#$EXTENDROM_DEBUG_PATH#g;s#%%DEBUGLOG_MKDARG%%#$MKDARG#g;\
s#%%DEBUGLOG_PATH_SIZE_FULL%%#$EXTENDROM_DEBUG_PATH_SIZE_FULL#g;\
s#%%DEBUGLOG_PATH_SIZE_CRASH%%#$EXTENDROM_DEBUG_PATH_SIZE_CRASH#g;\
s#%%DEBUGLOG_PATH_SIZE_KERNEL%%#$EXTENDROM_DEBUG_PATH_SIZE_KERNEL#g;\
s#%%DEBUGLOG_PATH_SIZE_SELINUX%%#$EXTENDROM_DEBUG_PATH_SIZE_SELINUX#g" \
$MY_DIR/config/init.er.rc.in > $MY_DIR/config/init.er.rc
echo "[$FUNCNAME] ... configured EXTENDROM_DEBUG_PATH (init.er.rc) to $EXTENDROM_DEBUG_PATH"
echo "[$FUNCNAME] ... configured EXTENDROM_DEBUG_PATH_SIZE's (init.er.rc):"
echo "[$FUNCNAME] ... EXTENDROM_DEBUG_PATH_SIZE_FULL=$EXTENDROM_DEBUG_PATH_SIZE_FULL KB"
echo "[$FUNCNAME] ... EXTENDROM_DEBUG_PATH_SIZE_CRASH=$EXTENDROM_DEBUG_PATH_SIZE_CRASH KB"
echo "[$FUNCNAME] ... EXTENDROM_DEBUG_PATH_SIZE_KERNEL=$EXTENDROM_DEBUG_PATH_SIZE_KERNEL KB"
echo "[$FUNCNAME] ... EXTENDROM_DEBUG_PATH_SIZE_SELINUX=$EXTENDROM_DEBUG_PATH_SIZE_SELINUX KB"
sed -i "s#%%DEBUGLOG_PATH%%#$EXTENDROM_DEBUG_PATH#g" $MY_DIR/sepolicy/boot_debug/* && echo "[$FUNCNAME] ... configured EXTENDROM_DEBUG_PATH (sepolicies) to $EXTENDROM_DEBUG_PATH"
echo "[$FUNCNAME] ... enabled and configured EXTENDROM_BOOT_DEBUG"
else
echo -e "[$FUNCNAME] ... ERROR: it seems you have legacy code in your device/ path!\nFix this first before enabling EXTENDROM_BOOT_DEBUG"
fi
}
# signature spoofing patch
F_SIGPATCH(){
echo "[$FUNCNAME] Signature spoofing patch requested ..."
# revert LOS patches
case ${EXTENDROM_TARGET_VERSION} in
14) MGCOMMITS="6b793fa98a40dd6c2d6eb02988161ed123439428" ;;
13) MGCOMMITS="6d2955f0bd55e9938d5d49415182c27b50900b95" ;;
12) MGCOMMITS="83fe523914728a3674debba17a6019cb74803045" ;;
11) MGCOMMITS="438d9feacfcad73d3ee918541574132928a93644" ;;
esac
if [ ! -z "$MGCOMMITS" ] && [ "$EXTENDROM_SIGSPOOF_RESET" != "false" ];then
cd frameworks/base
echo "[$FUNCNAME] reverting DOS commit to allow sigspoofing"
git revert --no-edit $MGCOMMITS
cd ../..
fi
PATCHX="/bin/bash $MY_DIR/tools/apply_patches.sh"
PDIR="$SRC_TOP_FULL/$MY_DIR/config/sigspoof/$EXTENDROM_TARGET_PRODUCT/A${EXTENDROM_TARGET_VERSION}"
[ ! -z "$EXTENDROM_SIGSPOOF_FORCE_PDIR" ] && [ -d "$EXTENDROM_SIGSPOOF_FORCE_PDIR" ] && PDIR=$EXTENDROM_SIGSPOOF_FORCE_PDIR
$PATCHX $PDIR $EXTENDROM_PATCHER_RESET
ERR=$?
echo "[$FUNCNAME] Signature spoofing patching ended with $ERR"
echo "[$FUNCNAME] adding signature spoof controller"
cp $PDIR/*-packages-apps-Settings-src-com-android-settings-development-SpoofSignaturePreferenceController.java ${SRC_TOP}/packages/apps/Settings/src/com/android/settings/development/SpoofSignaturePreferenceController.java || exit 3
cp $PDIR/*-packages-apps-Settings-src-com-android-settings-development-SpoofSignatureInfo.java ${SRC_TOP}/packages/apps/Settings/src/com/android/settings/development/SpoofSignatureInfo.java || exit 3
echo "[$FUNCNAME] adding signature spoof controller ended with $?"
if [ $ERR -eq 0 ];then echo "[$FUNCNAME] finished successfully" && return; else exit 3;fi
}
# signing patches
F_SIGNINGPATCHES(){
echo "[$FUNCNAME] Signing patches requested ..."
PATCHX="/bin/bash $MY_DIR/tools/apply_patches.sh"
PDIR="$SRC_TOP_FULL/$MY_DIR/config/signing/$EXTENDROM_TARGET_PRODUCT/A${EXTENDROM_TARGET_VERSION}"
[ ! -z "$EXTENDROM_SIGNING_FORCE_PDIR" ] && [ -d "$EXTENDROM_SIGNING_FORCE_PDIR" ] && PDIR=$EXTENDROM_SIGNING_FORCE_PDIR
$PATCHX $PDIR $EXTENDROM_PATCHER_RESET
ERR=$?
echo "[$FUNCNAME] addding signing patches ended with $ERR"
if [ $ERR -eq 0 ];then echo "[$FUNCNAME] finished successfully" && return; else exit 3;fi
}
if [ "$EXTENDROM_SIGNATURE_SPOOFING" == "true" ];then F_SIGPATCH ;fi
if [ "$EXTENDROM_SIGNING_PATCHES" == "true" ];then F_SIGNINGPATCHES ;fi
F_GET_GPG_KEYS
get_packages "$MY_DIR/repo/packages.txt"
if [ ! -z "$EXTENDROM_BOOT_DEBUG" -a "$EXTENDROM_BOOT_DEBUG" == "true" ];then
F_BOOT_DEBUG
fi
# clean tmp
find $_OUTDIR -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;
INITIAL_COPYRIGHT_YEAR=2021
VENDOR="extendrom"
ANDROIDMK="$MY_DIR/Android.mk"
DEVICE="true"
write_headers "" ENABLE_EXTENDROM
DEVICE=
# special handling for locked bootloaders
if [ "$EXTENDROM_SIGN_ALL_APKS" == "true" ];then
sed -i 's#PRESIGNED#user-keys/shared#g' $MY_DIR/repo/packages.txt
fi
# MAGISK rooting preparation
if [ "$EXTENDROM_PREROOT_BOOT" == "true" ];then
echo "[MAGISK] preparing the root process as requested"
# inject magisk patcher to releasetools
PATCHX="/bin/bash $MY_DIR/tools/apply_patches.sh"
PDIR="$SRC_TOP_FULL/$MY_DIR/config/magisk/$EXTENDROM_TARGET_PRODUCT/A${EXTENDROM_TARGET_VERSION}"
echo "[MAGISK] using patch dir: $PDIR"
$PATCHX $PDIR $EXTENDROM_PATCHER_RESET
ERR=$?
echo "[MAGISK] Injecting Magisk patcher ended with $ERR"
[ "$ERR" -ne 0 ] && exit $ERR
MAGISKOUT=$(realpath $MY_DIR/../../out/.magisk)
[ -d "$MAGISKOUT" ] && rm -rf $MAGISKOUT
mkdir -p $MAGISKOUT
[ -z $MAGISK_TARGET_ARCH ] && MAGISK_TARGET_ARCH=arm64
if [ ! -f $MY_DIR/prebuilt/${MAGNAME}.apk ];then
echo "[MAGISK] ERROR: apk cannot be found! Keep in mind that extendrom supports v22 and later only!"
echo "[MAGISK] ERROR: Do you have set 'Magisk' or 'SignMagisk' in your vendorsetup.sh??"
exit 4
else
MAGZIP=$MY_DIR/prebuilt/${MAGNAME}.apk
fi
echo "[MAGISK] ... Magisk found!"
unzip -q $MAGZIP -d $MAGISKOUT/src
cp $MAGISKOUT/src/lib/x86/libmagiskboot.so $MAGISKOUT/magiskboot
chmod 755 $MAGISKOUT/magiskboot
echo "[MAGISK] ... MAGISK_TARGET_ARCH specified as $MAGISK_TARGET_ARCH"
cp $MAGISKOUT/src/lib/armeabi-v7a/libmagisk32.so $MAGISKOUT/magisk32
if [ $MAGISK_TARGET_ARCH == "arm64" ];then
cp $MAGISKOUT/src/lib/arm64-v8a/libmagisk64.so $MAGISKOUT/magisk64
cp $MAGISKOUT/src/lib/arm64-v8a/libmagiskinit.so $MAGISKOUT/magiskinit
else
cp $MAGISKOUT/src/lib/armeabi-v7a/libmagiskinit.so $MAGISKOUT/magiskinit
fi
chmod 755 $MAGISKOUT/src/assets/boot_patch.sh
rm -rf $MAGISKOUT/src/assets/dexopt $MAGISKOUT/src/assets/chromeos
cp $MAGISKOUT/src/assets/* $MAGISKOUT/
# keep backwards compability
cp $MAGISKOUT/src/assets/boot_patch.sh $MAGISKOUT/root_boot.sh
# remove Magisk from Android mk list - as we do not build/add the Magisk app
# see https://github.com/sfX-android/android_vendor_extendrom/wiki/FAQ#extendrom_preroot_boot
export EXTENDROM_PACKAGES="$EXTENDROM_PACKAGES_CLEANED"
echo -e "[MAGISK] removed >$MAGNAME< from Android makefile generation:\nEXTENDROM_PACKAGES is now: $EXTENDROM_PACKAGES"
echo "[MAGISK] preparing root finished"
fi
# write specific F-Droid module
F_WRITE_MAKEFILE_FDROID(){
echo "[$FUNCNAME] writing additional_repos.xml makefile"
cat >> $ANDROIDMK << _EOFFD
# additional F-Droid repos
include \$(CLEAR_VARS)
LOCAL_MODULE := additional_repos.xml
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := \$(TARGET_OUT_VENDOR_ETC)/org.fdroid.fdroid
LOCAL_SRC_FILES := out/_additional_repos.xml
include \$(BUILD_PREBUILT)
_EOFFD
echo "[$FUNCNAME] constructing additional_repos.xml"
cat > $_OUTDIR/_additional_repos.xml <<_EOFF
<?xml version="1.0" encoding="utf-8"?>
<resources>
_EOFF
cat $FDROID_REPO_DIR/additional_repos.xml >> $_OUTDIR/_additional_repos.xml
if [ ! -z "$EXTENDROM_FDROID_REPOS" ];then
for repo in $EXTENDROM_FDROID_REPOS;do
if [ ! -f "$FDROID_REPO_DIR/$repo" ];then echo "[$FUNCNAME] ERROR: missing $FDROID_REPO_DIR/$repo" && exit 4;fi
cat $FDROID_REPO_DIR/$repo >> $_OUTDIR/_additional_repos.xml && echo "[$FUNCNAME] ... added $repo to additional_repos.xml"
done
echo '</resources>' >> $_OUTDIR/_additional_repos.xml
fi
echo "[$FUNCNAME] constructing additional_repos.xml completed"
}
echo "[main] Writing makefiles (if needed)"
F_WRITE_MAKEFILE "$MY_DIR/repo/packages.txt"
if [[ "$EXTENDROM_PACKAGES" =~ "additional_repos.xml" ]];then F_WRITE_MAKEFILE_FDROID; fi
cat >> $ANDROIDMK <<EOMK
# include additional static configs
include $MY_DIR/extra/Android.mk
EOMK
write_footers
# special handling for /e/ OS gestures support
if [ "$EOS_GESTURES" == "true" ];then
TBMK="packages/apps/Trebuchet/Android.mk"
TBTESTMK="packages/apps/Trebuchet/tests/Android.mk"
ICOLIB="packages/apps/iconloaderlib"
LOSMK="vendor/lineage/config/common.mk"
if [ -f $TBMK ];then
sed -i 's/LOCAL_PACKAGE_NAME := TrebuchetQuickStep$/LOCAL_PACKAGE_NAME := eOSTrebuchetQuickStep/g' $TBMK
else
echo -e "\n*** ERROR ***\n/e/ OS gesture support is enabled (EOS_GESTURES=true) but a required file is missing:\n\n\t>${TBMK}<\n\nCheck if your local manifest contains the source for 'TrebuchetQuickStep'!"
echo -e "For testing purposes you can clone it manually like this \n\ngit clone https://github.com/LineageOS/android_packages_apps_Trebuchet.git packages/apps/Trebuchet -b lineage-<version>\n"
exit 3
fi
# remove duplicated tests causing build errors
if [ -f "$TBTESTMK" ];then rm $TBTESTMK;fi
# remove duplicated iconloaderlib causing build errors
if [ -d "$ICOLIB" ];then rm -rf $ICOLIB;fi
# remove legacy recents activated in /e/
if [ -f "$LOSMK" ];then sed -E -i '/SystemUIWithLegacyRecents\s+\\/d' $LOSMK;fi
fi
trap - EXIT ERR
echo -e "\n\n************************************************** EXTENDROM FINISHED **************************************************\n\n"