This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel_build.sh
125 lines (102 loc) · 3.3 KB
/
kernel_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
#! /bin/bash
# Copyright (C) 2020 KenHV
# Copyright (C) 2020 Starlight
# Copyright (C) 2021 CloudedQuartz
#
# Config
DEVICE="beryllium"
DEFCONFIG="${DEVICE}_defconfig"
LOG="$HOME/log.txt"
VERSION="1.0"
# Export arch and subarch
ARCH="arm64"
SUBARCH="arm64"
export ARCH SUBARCH
export KBUILD_BUILD_USER=HadeS
export KBUILD_BUILD_HOST=DroneCI
export TZ='CEST'
KERNEL_IMG=$KERNEL_DIR/out/arch/$ARCH/boot/Image.gz-dtb
TG_CHAT_ID="$CHAT_ID"
TG_BOT_TOKEN="$BOT_API_KEY"
# End config
# Function definitions
# tg_sendinfo - sends text through telegram
tg_sendinfo() {
curl -s "https://api.telegram.org/bot$TG_BOT_TOKEN/sendMessage" \
-F parse_mode=html \
-F text="${1}" \
-F chat_id="${TG_CHAT_ID}" &> /dev/null
}
# tg_pushzip - uploads final zip to telegram
tg_pushzip() {
curl -F document=@"$1" "https://api.telegram.org/bot$TG_BOT_TOKEN/sendDocument" \
-F chat_id=$TG_CHAT_ID \
-F caption="$2" \
-F parse_mode=html &> /dev/null
}
# tg_failed - uploads build log to telegram
tg_failed() {
curl -F document=@"$LOG" "https://api.telegram.org/bot$TG_BOT_TOKEN/sendDocument" \
-F chat_id=$TG_CHAT_ID \
-F parse_mode=html &> /dev/null
}
# build_setup - enter kernel directory and get info for caption.
# also removes the previous kernel image, if one exists.
build_setup() {
cd "$KERNEL_DIR" || echo -e "\nKernel directory ($KERNEL_DIR) does not exist" || exit 1
[[ ! -d out ]] && mkdir out
[[ -f "$KERNEL_IMG" ]] && rm "$KERNEL_IMG"
find . -name "*.dtb" -type f -delete
}
# build_config - builds .config file for device.
build_config() {
make O=out $1 -j$(nproc --all)
}
# build_kernel - builds defconfig and kernel image using llvm tools, while saving the output to a specified log location
# only use after runing build_setup()
build_kernel() {
BUILD_START=$(date +"%s")
make -j$(nproc --all) O=out \
PATH="$TC_DIR/arm64/bin:$TC_DIR/arm/bin:$PATH" \
CROSS_COMPILE=$TC_DIR/arm64/bin/aarch64-elf- \
CROSS_COMPILE_ARM32=$TC_DIR/arm/bin/arm-eabi- |& tee $LOG
BUILD_END=$(date +"%s")
DIFF=$((BUILD_END - BUILD_START))
}
# build_end - creates and sends zip
build_end() {
if ! [ -a "$KERNEL_IMG" ]; then
echo -e "\n> Build failed, sending logs to Telegram."
tg_failed
tg_buildtime
exit 1
fi
echo -e "\n> Build successful! generating flashable zip..."
cd "$AK_DIR" || echo -e "\nAnykernel directory ($AK_DIR) does not exist" || exit 1
git clean -fd
mv "$KERNEL_IMG" "$AK_DIR"/zImage
ZIP_NAME=${KERNELNAME}_${VERSION}_${1}_$(date +%H%M).zip
zip -r9 "$ZIP_NAME" ./* -x .git README.md ./*placeholder
tg_pushzip "$ZIP_NAME" "Time taken: <code>$((DIFF / 60))m $((DIFF % 60))s</code>"
echo -e "\n> Sent zip through Telegram.\n> File: $ZIP_NAME"
}
# End function definitions
COMMIT=$(git log --pretty=format:"%s" -1)
COMMIT_SHA=$(git rev-parse --short HEAD)
KERNEL_BRANCH=$(git rev-parse --abbrev-ref HEAD)
CAPTION=$(echo -e \
"HEAD: <code>$COMMIT_SHA: </code><code>$COMMIT</code>
Branch: <code>$KERNEL_BRANCH</code>")
tg_sendinfo "-- Build Triggered --
$CAPTION"
# Build device
build_setup
build_config $DEFCONFIG
build_kernel
build_end $DEVICE
# Build with old touch firmware
build_setup
git apply old_touch_fw.patch
build_config $DEFCONFIG
build_kernel
build_end ${DEVICE}_old_touch_fw