-
Notifications
You must be signed in to change notification settings - Fork 13
/
kramel.sh
633 lines (587 loc) · 17.5 KB
/
kramel.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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
#!/usr/bin/bash
# Written by: cyberknight777
# YAKB v1.0
# Copyright (c) 2022-2023 Cyber Knight <[email protected]>
#
# GNU GENERAL PUBLIC LICENSE
# Version 3, 29 June 2007
#
# Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
# Some Placeholders: [!] [*] [✓] [✗]
# Default defconfig to use for builds.
export CONFIG=neternels_defconfig
# Default directory where kernel is located in.
KDIR=$(pwd)
export KDIR
# Default linker to use for builds.
export LINKER="ld.lld"
# Device name.
export DEVICE="Redmi Note 10"
# Date of build.
DATE=$(date +"%Y-%m-%d")
export DATE
# Device codename.
export CODENAME="mojito"
# Builder name.
export BUILDER="cyberknight777"
# Kernel repository URL.
export REPO_URL="https://github.com/neternels/android_kernel_xiaomi_mojito"
# Commit hash of HEAD.
COMMIT_HASH=$(git rev-parse --short HEAD)
export COMMIT_HASH
# Build status. Set 1 for release builds. | Set 0 for bleeding edge builds.
export RELEASE=$rel
if [ "${RELEASE}" == 1 ]; then
export STATUS="Release"
export CHATID=-1001301508914
export re="rc"
else
export STATUS="Bleeding-Edge"
export CHATID=-1001522330051
export re="r"
fi
# Telegram Information. Set 1 to enable. | Set 0 to disable.
export TGI=1
# Necessary variables to be exported.
export ci
export version
# Number of jobs to run.
PROCS=$(nproc --all)
export PROCS
# Compiler to use for builds.
export COMPILER=gcc
# Module building support. Set 1 to enable. | Set 0 to disable.
export MODULE=1
# Requirements
if [ "${ci}" == 0 ]; then
if ! hash dialog make curl wget unzip find 2>/dev/null; then
echo -e "\n\e[1;31m[✗] Install dialog, make, curl, wget, unzip, and find! \e[0m"
exit 1
fi
fi
if [[ "${COMPILER}" == gcc ]]; then
if [ ! -d "${KDIR}/gcc64" ]; then
curl -sL https://github.com/cyberknight777/gcc-arm64/archive/refs/heads/master.tar.gz | tar -xzf -
mv "${KDIR}"/gcc-arm64-master "${KDIR}"/gcc64
fi
if [ ! -d "${KDIR}/gcc32" ]; then
curl -sL https://github.com/cyberknight777/gcc-arm/archive/refs/heads/master.tar.gz | tar -xzf -
mv "${KDIR}"/gcc-arm-master "${KDIR}"/gcc32
fi
KBUILD_COMPILER_STRING=$("${KDIR}"/gcc64/bin/aarch64-elf-gcc --version | head -n 1)
export KBUILD_COMPILER_STRING
export PATH="${KDIR}"/gcc32/bin:"${KDIR}"/gcc64/bin:/usr/bin/:${PATH}
MAKE+=(
ARCH=arm64
O=out
CROSS_COMPILE=aarch64-elf-
CROSS_COMPILE_ARM32=arm-eabi-
LD="${KDIR}"/gcc64/bin/aarch64-elf-"${LINKER}"
AR=llvm-ar
NM=llvm-nm
OBJDUMP=llvm-objdump
OBJCOPY=llvm-objcopy
OBJSIZE=llvm-objsize
STRIP=llvm-strip
HOSTAR=llvm-ar
HOSTCC=gcc
HOSTCXX=aarch64-elf-g++
CC=aarch64-elf-gcc
)
elif [[ "${COMPILER}" == clang ]]; then
if [ ! -d "${KDIR}/proton-clang" ]; then
wget https://github.com/kdrag0n/proton-clang/archive/refs/heads/master.zip
unzip "${KDIR}"/master.zip
mv "${KDIR}"/proton-clang-master "${KDIR}"/proton-clang
fi
KBUILD_COMPILER_STRING=$("${KDIR}"/proton-clang/bin/clang -v 2>&1 | head -n 1 | sed 's/(https..*//' | sed 's/ version//')
export KBUILD_COMPILER_STRING
export PATH=$KDIR/proton-clang/bin/:/usr/bin/:${PATH}
MAKE+=(
ARCH=arm64
O=out
CROSS_COMPILE=aarch64-linux-gnu-
CROSS_COMPILE_ARM32=arm-linux-gnueabi-
LD="${LINKER}"
AR=llvm-ar
AS=llvm-as
NM=llvm-nm
OBJDUMP=llvm-objdump
STRIP=llvm-strip
CC=clang
)
fi
if [[ "${MODULE}" = 1 ]]; then
if [ ! -d "${KDIR}"/modules ]; then
git clone --depth=1 https://github.com/neternels/neternels-modules "${KDIR}"/modules
fi
fi
if [ ! -d "${KDIR}/anykernel3-mojito/" ]; then
git clone --depth=1 https://github.com/neternels/anykernel3 -b mojito anykernel3-mojito
fi
if [ "${ci}" != 1 ]; then
if [ -z "${kver}" ]; then
echo -ne "\e[1mEnter kver: \e[0m"
read -r kver
else
export KBUILD_BUILD_VERSION=${kver}
fi
if [ -z "${zipn}" ]; then
echo -ne "\e[1mEnter zipname: \e[0m"
read -r zipn
fi
else
export KBUILD_BUILD_VERSION=$DRONE_BUILD_NUMBER
export KBUILD_BUILD_HOST=$DRONE_SYSTEM_HOST
export KBUILD_BUILD_USER=$BUILDER
export VERSION=$version
kver=$KBUILD_BUILD_VERSION
zipn=NetErnels-mojito-${VERSION}
if [[ "${MODULE}" = "1" ]]; then
modn="${zipn}-modules"
fi
fi
# A function to exit on SIGINT.
exit_on_signal_SIGINT() {
echo -e "\n\n\e[1;31m[✗] Received INTR call - Exiting...\e[0m"
exit 0
}
trap exit_on_signal_SIGINT SIGINT
# A function to send message(s) via Telegram's BOT api.
tg() {
curl -sX POST https://api.telegram.org/bot"${TOKEN}"/sendMessage \
-d chat_id="${CHATID}" \
-d parse_mode=Markdown \
-d disable_web_page_preview=true \
-d text="$1" &>/dev/null
}
# A function to send file(s) via Telegram's BOT api.
tgs() {
MD5=$(md5sum "$1" | cut -d' ' -f1)
curl -fsSL -X POST -F document=@"$1" https://api.telegram.org/bot"${TOKEN}"/sendDocument \
-F "chat_id=${CHATID}" \
-F "parse_mode=Markdown" \
-F "caption=$2 | *MD5*: \`$MD5\`"
}
# A function to clean kernel source prior building.
clean() {
echo -e "\n\e[1;93m[*] Cleaning source and out/ directory! \e[0m"
make clean && make mrproper && rm -rf "${KDIR}"/out
echo -e "\n\e[1;32m[✓] Source cleaned and out/ removed! \e[0m"
}
# A function to regenerate defconfig.
rgn() {
echo -e "\n\e[1;93m[*] Regenerating defconfig! \e[0m"
make "${MAKE[@]}" $CONFIG
cp -rf "${KDIR}"/out/.config "${KDIR}"/arch/arm64/configs/$CONFIG
echo -e "\n\e[1;32m[✓] Defconfig regenerated! \e[0m"
}
# A function to open a menu based program to update current config.
mcfg() {
rgn
echo -e "\n\e[1;93m[*] Making Menuconfig! \e[0m"
make "${MAKE[@]}" menuconfig
cp -rf "${KDIR}"/out/.config "${KDIR}"/arch/arm64/configs/$CONFIG
echo -e "\n\e[1;32m[✓] Saved Modifications! \e[0m"
}
# A function to build the kernel.
img() {
if [[ "${TGI}" == "1" ]]; then
if [[ "${RELEASE}" != "1" ]]; then
wget https://raw.githubusercontent.com/cyberknight777/my-stuffs/main/img/net.jpg
curl -F [email protected] https://api.telegram.org/bot"${TOKEN}"/sendPhoto -F chat_id=-1001522330051
rm net.jpg
fi
tg "
*Build Number*: \`${kver}\`
*Status*: \`${STATUS}\`
*Builder*: \`${BUILDER}\`
*Core count*: \`$(nproc --all)\`
*Device*: \`${DEVICE} [${CODENAME}]\`
*Kernel Version*: \`$(make kernelversion 2>/dev/null)\`
*Date*: \`$(date)\`
*Zip Name*: \`${zipn}\`
*Compiler*: \`${KBUILD_COMPILER_STRING}\`
*Linker*: \`$("${KDIR}"/gcc64/bin/aarch64-elf-${LINKER} -v | head -n1 | sed 's/(compatible with [^)]*)//' |
head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')\`
*Branch*: \`$(git rev-parse --abbrev-ref HEAD)\`
*Last Commit*: [${COMMIT_HASH}](${REPO_URL}/commit/${COMMIT_HASH})
"
fi
rgn
echo -e "\n\e[1;93m[*] Building Kernel! \e[0m"
BUILD_START=$(date +"%s")
time make -j"$PROCS" "${MAKE[@]}" Image dtbo.img 2>&1 | tee log.txt
BUILD_END=$(date +"%s")
DIFF=$((BUILD_END - BUILD_START))
if [ -f "${KDIR}/out/arch/arm64/boot/Image" ]; then
if [[ "${TGI}" == "1" ]]; then
tg "*Kernel Built after $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)*"
fi
echo -e "\n\e[1;32m[✓] Kernel built after $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! \e[0m"
else
if [[ "${TGI}" == "1" ]]; then
tgs "log.txt" "*Build failed*"
fi
echo -e "\n\e[1;31m[✗] Build Failed! \e[0m"
exit 1
fi
}
# A function to build DTBs.
dtb() {
rgn
echo -e "\n\e[1;93m[*] Building DTBS! \e[0m"
time make -j"$PROCS" "${MAKE[@]}" dtbs dtbo.img
echo -e "\n\e[1;32m[✓] Built DTBS! \e[0m"
}
# A function to build out-of-tree modules.
mod() {
if [[ "${TGI}" == "1" ]]; then
tg "*Building Modules!*"
fi
rgn
echo -e "\n\e[1;93m[*] Building Modules! \e[0m"
mkdir -p "${KDIR}"/out/modules
make "${MAKE[@]}" modules_prepare
make -j"$PROCS" "${MAKE[@]}" modules INSTALL_MOD_PATH="${KDIR}"/out/modules
make "${MAKE[@]}" modules_install INSTALL_MOD_PATH="${KDIR}"/out/modules
find "${KDIR}"/out/modules -type f -iname '*.ko' -exec cp {} "${KDIR}"/modules/system/lib/modules/ \;
cd "${KDIR}"/modules || exit 1
zip -r9 "${modn}".zip . -x ".git*" -x "README.md" -x "LICENSE" -x "*.zip"
cd ../
echo -e "\n\e[1;32m[✓] Built Modules! \e[0m"
}
# A function to build an AnyKernel3 zip.
mkzip() {
if [[ "${TGI}" == "1" ]]; then
tg "*Building zip!*"
fi
echo -e "\n\e[1;93m[*] Building zip! \e[0m"
mkdir -p "${KDIR}"/anykernel3-mojito/dtbs
mv "${KDIR}"/out/arch/arm64/boot/dtbo.img "${KDIR}"/anykernel3-mojito
cat "${KDIR}"/out/arch/arm64/boot/dts/qcom/sm6150.dtb > "${KDIR}"/anykernel3-mojito/dtb
mv "${KDIR}"/out/arch/arm64/boot/Image "${KDIR}"/anykernel3-mojito
cd "${KDIR}"/anykernel3-mojito || exit 1
zip -r9 "$zipn".zip . -x ".git*" -x "README.md" -x "LICENSE" -x "*.zip"
echo -e "\n\e[1;32m[✓] Built zip! \e[0m"
if [[ "${ci}" == "1" ]]; then
git clone https://github.com/NetErnels/devices.git
cd devices || exit 1
echo "https://cyberknight777:[email protected]" > .pwd
git config credential.helper "store --file .pwd"
sha1=$(sha1sum ../"${zipn}".zip | cut -d ' ' -f1)
if [[ "${RELEASE}" != "1" ]]; then
rm mojito/changelog_r.md
wget "${link}/raw" -O mojito/changelog_r.md
echo "
{
\"kernel\": {
\"name\": \"NetErnels\",
\"version\": \"$version\",
\"link\": \"https://github.com/NetErnels/devices/releases/download/$version/$zipn.zip\",
\"changelog_url\": \"https://raw.githubusercontent.com/NetErnels/devices/master/mojito/changelog_r.md\",
\"date\": \"$DATE\",
\"sha1\": \"$sha1\"
},
\"support\": {
\"link\": \"https://t.me/neternels_chat\"
}
}
" > mojito/NetErnels-r.json
git add mojito/NetErnels-r.json mojito/changelog_r.md || exit 1
git commit -s -m "NetErnels: Update $CODENAME to $version release" -m "- This is a bleeding edge release."
git commit --amend --reset-author --no-edit
git push
gh release create "${version}" -t "NetErnels for $CODENAME [BLEEDING EDGE] - $version"
gh release upload "${version}" ../"${zipn}.zip"
else
rm mojito/changelog.md
wget "${link}"/raw -O mojito/changelog.md
echo "
{
\"kernel\": {
\"name\": \"NetErnels\",
\"version\": \"$version\",
\"link\": \"https://github.com/NetErnels/devices/releases/download/$version/$zipn.zip\",
\"changelog_url\": \"https://raw.githubusercontent.com/NetErnels/devices/master/mojito/changelog.md\",
\"date\": \"$DATE\",
\"sha1\": \"$sha1\"
},
\"support\": {
\"link\": \"https://t.me/neternels_chat\"
}
}
" > mojito/NetErnels-v.json
git add mojito/NetErnels-v.json mojito/changelog.md || exit 1
git commit -s -m "NetErnels: Update $CODENAME to $version release" -m "- This is a stable release."
git commit --amend --reset-author --no-edit
git push
gh release create "${version}" -t "NetErnels for $CODENAME [RELEASE] - $version"
gh release upload "${version}" ../"${zipn}.zip"
fi
cd ../ || exit 1
fi
if [[ "${TGI}" == "1" ]]; then
tgs "${zipn}.zip" "*#${kver} ${KBUILD_COMPILER_STRING}*"
if [[ "${MODULE}" = "1" ]]; then
cd ../modules || exit 1
tgs "${modn}.zip" "*#${kver} ${KBUILD_COMPILER_STRING}*"
fi
tg "
*Build*: https://github.com/NetErnels/devices/releases/download/$version/$zipn.zip
*Changelog*: https://github.com/NetErnels/devices/blob/master/mojito/changelog\_${re}.md
*OTA*: https://raw.githubusercontent.com/NetErnels/devices/master/mojito/NetErnels-${re}.json
"
fi
}
# A function to build specific objects.
obj() {
rgn
echo -e "\n\e[1;93m[*] Building ${1}! \e[0m"
time make -j"$PROCS" "${MAKE[@]}" "$1"
echo -e "\n\e[1;32m[✓] Built ${1}! \e[0m"
}
# A function to uprev localversion in defconfig.
upr() {
echo -e "\n\e[1;93m[*] Bumping localversion to -NetErnels-${1}! \e[0m"
"${KDIR}"/scripts/config --file "${KDIR}"/arch/arm64/configs/$CONFIG --set-str CONFIG_LOCALVERSION "-NetErnels-${1}"
rgn
if [ "${ci}" == 0 ]; then
git add arch/arm64/configs/$CONFIG
git commit -S -s -m "neternels_defconfig: Bump to \`${1}\`"
fi
echo -e "\n\e[1;32m[✓] Bumped localversion to -NetErnels-${1}! \e[0m"
}
# A function to showcase the options provided for args-based usage.
helpmenu() {
echo -e "\n\e[1m
usage: kver=<version number> zipn=<zip name> $0 <arg>
example: $0 --kver=69 --zipn=Kernel-Beta mcfg
example: $0 --kver=420 --zipn=Kernel-Beta mcfg img
example: $0 --kver=69420 --zipn=Kernel-Beta mcfg img mkzip
example: $0 --kver=1 --zipn=Kernel-Beta --obj=drivers/android/binder.o
example: $0 --kver=2 --zipn=Kernel-Beta --obj=kernel/sched/
example: $0 --kver=3 --zipn=Kernel-Beta--upr=r16
mcfg Runs make menuconfig
img Builds Kernel
dtb Builds dtb(o).img
mod Builds out-of-tree modules
mkzip Builds anykernel3 zip
--obj Builds specific driver/subsystem
rgn Regenerates defconfig
--upr Uprevs kernel version in defconfig
--kver kernel buildversion
--zipn zip name
\e[0m"
}
# A function to setup menu-based usage.
ndialog() {
HEIGHT=16
WIDTH=40
CHOICE_HEIGHT=30
BACKTITLE="Yet Another Kernel Builder"
TITLE="YAKB v1.0"
MENU="Choose one of the following options: "
OPTIONS=(1 "Build kernel"
2 "Build DTBs"
3 "Build modules"
4 "Open menuconfig"
5 "Regenerate defconfig"
6 "Uprev localversion"
7 "Build AnyKernel3 zip"
8 "Build a specific object"
9 "Clean"
10 "Exit"
)
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case "$CHOICE" in
1)
clear
img
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
2)
clear
dtb
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
3)
clear
mod
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
4)
clear
mcfg
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
5)
clear
rgn
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
6)
dialog --inputbox --stdout "Enter version number: " 15 50 | tee .t
ver=$(cat .t)
clear
upr "$ver"
rm .t
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
7)
mkzip
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
8)
dialog --inputbox --stdout "Enter object path: " 15 50 | tee .f
ob=$(cat .f)
if [ -z "$ob" ]; then
dialog --inputbox --stdout "Enter object path: " 15 50 | tee .f
fi
clear
obj "$ob"
rm .f
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
9)
clear
clean
img
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
10)
echo -e "\n\e[1m Exiting YAKB...\e[0m"
sleep 3
exit 0
;;
esac
}
if [ "${ci}" == 1 ]; then
upr "${version}"
fi
if [[ -z $* ]]; then
ndialog
fi
for arg in "$@"; do
case "${arg}" in
"mcfg")
mcfg
;;
"img")
img
;;
"dtb")
dtb
;;
"mod")
mod
;;
"mkzip")
mkzip
;;
"--obj="*)
object="${arg#*=}"
if [[ -z "$object" ]]; then
echo "Use --obj=filename.o"
exit 1
else
obj "$object"
fi
;;
"rgn")
rgn
;;
"--upr="*)
vers="${arg#*=}"
if [[ -z "$vers" ]]; then
echo "Use --upr=version"
exit 1
else
upr "$vers"
fi
;;
"clean")
clean
;;
"help")
helpmenu
exit 1
;;
*)
helpmenu
exit 1
;;
esac
done