forked from mahajant99/kernel_xiaomi_surya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_script.sh
201 lines (179 loc) · 6.7 KB
/
build_script.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
#!/bin/bash
#
# Copyright (C) 2020 azrim.
# All rights reserved.
# Init
KERNEL_DIR="${PWD}"
cd "$KERNEL_DIR" || exit
DTB_TYPE="single" # define as "single" if want use single file
KERN_IMG=/root/project/kernel_xiaomi_surya-2/out/arch/arm64/boot/Image.gz-dtb # if use single file define as Image.gz-dtb instead
# KERN_DTB="${KERNEL_DIR}"/out/arch/arm64/boot/dtbo.img # and comment this variable
ANYKERNEL="${HOME}"/anykernel
LOGS="${HOME}"/${CHEAD}.log
# Repo URL
ANYKERNEL_REPO="https://github.com/dekukamikix/anykernel3.git"
ANYKERNEL_BRANCH="master"
# Repo info
PARSE_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
PARSE_ORIGIN="$(git config --get remote.origin.url)"
COMMIT_POINT="$(git log --pretty=format:'%h : %s' -1)"
CHEAD="$(git rev-parse --short HEAD)"
LATEST_COMMIT="[$COMMIT_POINT](https://github.com/dekukamikix/kernel_xiaomi_surya-2/commit/$CHEAD)"
LOGS_URL="[See Circle CI Build Logs Here](https://circleci.com/gh/dekukamikix/kernel_xiaomi_surya-2/$CIRCLE_BUILD_NUM)"
# Compiler
mkdir -p "/mnt/workdir/proton-clang"
COMP_TYPE="clang" # unset if want to use gcc as compiler
CLANG_DIR="/mnt/workdir/proton-clang"
CLANG_URL="https://github.com/silont-project/silont-clang/archive/20210117.tar.gz"
GCC_DIR="" # Doesn't needed if use proton-clang
GCC32_DIR="" # Doesn't needed if use proton-clang
CLANG_FILE="/mnt/workdir/clang.tar.gz"
git clone https://github.com/kdrag0n/proton-clang.git --depth=1 --single-branch $CLANG_DIR -b master
if [[ "${COMP_TYPE}" =~ "clang" ]]; then
CSTRING=$("$CLANG_DIR"/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
COMP_PATH="$CLANG_DIR/bin:${PATH}"
else
COMP_PATH="${GCC_DIR}/bin:${GCC32_DIR}/bin:${PATH}"
fi
# Defconfig
DEFCONFIG="vendor/surya-perf_defconfig"
REGENERATE_DEFCONFIG="true" # unset if don't want to regenerate defconfig
# Telegram
CHATID="$CHANNEL_ID" # Group/channel chatid (use rose/userbot to get it)
TELEGRAM_TOKEN="${TG_TOKEN}"
# Export Telegram.sh
TELEGRAM_FOLDER="${HOME}"/telegram
if ! [ -d "${TELEGRAM_FOLDER}" ]; then
git clone https://github.com/fabianonline/telegram.sh/ "${TELEGRAM_FOLDER}"
fi
TELEGRAM="${TELEGRAM_FOLDER}"/telegram
tg_cast() {
curl -s -X POST https://api.telegram.org/bot"$TELEGRAM_TOKEN"/sendMessage -d disable_web_page_preview="true" -d chat_id="$CHATID" -d "parse_mode=MARKDOWN" -d text="$(
for POST in "${@}"; do
echo "${POST}"
done
)" &> /dev/null
}
tg_ship() {
"${TELEGRAM}" -f "${ZIPNAME}" -t "${TELEGRAM_TOKEN}" -c "${CHATID}" -H \
"$(
for POST in "${@}"; do
echo "${POST}"
done
)"
}
tg_fail() {
"${TELEGRAM}" -f "${LOGS}" -t "${TELEGRAM_TOKEN}" -c "${CHATID}" -H \
"$(
for POST in "${@}"; do
echo "${POST}"
done
)"
}
# Versioning
versioning() {
cat arch/arm64/configs/"${DEFCONFIG}" | grep CONFIG_LOCALVERSION= | tee /mnt/workdir/name.sh
sed -i 's/-Mechatron-Alternative-//g' /mnt/workdir/name.sh
source /mnt/workdir/name.sh
}
# Costumize
versioning
KERNEL="Mechatron-Alternative"
DEVICE="Surya"
KERNELTYPE="$CONFIG_LOCALVERSION"
KERNELNAME="${KERNEL}-${KERNELTYPE}-${DEVICE}-$(date +%d%m%Y-%H%M)"
TEMPZIPNAME="${KERNELNAME}-unsigned.zip"
ZIPNAME="${KERNELNAME}.zip"
# Regenerating Defconfig
regenerate() {
cp out/.config arch/arm64/configs/"${DEFCONFIG}"
git add arch/arm64/configs/"${DEFCONFIG}"
git commit -m "defconfig: Regenerate"
}
# Build Failed
build_failed() {
END=$(date +"%s")
DIFF=$(( END - START ))
echo -e "Kernel compilation failed, See build log to fix errors"
tg_fail "Build for ${DEVICE} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)!"
exit 1
}
# Building
makekernel() {
sed -i "s/${KERNELTYPE}/${KERNELTYPE}/g" "${KERNEL_DIR}/arch/arm64/configs/${DEFCONFIG}"
echo "ichiro@MacBook-Pro-2012" > "$KERNEL_DIR"/.builderdata
export PATH="${COMP_PATH}"
make O=out ARCH=arm64 ${DEFCONFIG} savedefconfig
if [[ "${REGENERATE_DEFCONFIG}" =~ "true" ]]; then
regenerate
fi
if [[ "${COMP_TYPE}" =~ "clang" ]]; then
make -j$(nproc --all) CC=clang CROSS_COMPILE=aarch64-linux-gnu- CROSS_COMPILE_ARM32=arm-linux-gnueabi- O=out ARCH=arm64 LLVM=1 2>&1 LD=ld.lld | tee "$LOGS"
else
make -j$(nproc --all) O=out ARCH=arm64 CROSS_COMPILE="${GCC_DIR}/bin/aarch64-elf-" CROSS_COMPILE_ARM32="${GCC32_DIR}/bin/arm-eabi-"
fi
# Check If compilation is success
packingkernel
}
# Packing kranul
packingkernel() {
# Copy compiled kernel
if [ -d "${ANYKERNEL}" ]; then
rm -rf "${ANYKERNEL}"
fi
git clone "$ANYKERNEL_REPO" -b "$ANYKERNEL_BRANCH" "${ANYKERNEL}"
if ! [ -f /root/project/kernel_xiaomi_surya-2/out/arch/arm64/boot/Image.gz-dtb ]; then
build_failed
fi
cp /root/project/kernel_xiaomi_surya-2/out/arch/arm64/boot/Image.gz-dtb /root/anykernel/Image.gz-dtb
cp /root/project/kernel_xiaomi_surya-2/out/arch/arm64/boot/dtbo.img /root/anykernel/dtbo.img
: 'if ! [ -f "${KERN_IMG}" ]; then
build_failed
fi
if ! [ -f "${KERN_DTB}" ]; then
build_failed
fi
if [[ "${DTB_TYPE}" =~ "single" ]]; then
cp "${KERN_IMG}" "${ANYKERNEL}"/Image.gz-dtb
else
cp "${KERN_IMG}" "${ANYKERNEL}"/Image.gz-dtb
cp "${KERN_DTB}" "${ANYKERNEL}"/dtbo.img
fi
'
# Zip the kernel, or fail
cd "${ANYKERNEL}" || exit
zip -r9 "${TEMPZIPNAME}" ./*
# Sign the zip before sending it to Telegram
curl -sLo zipsigner-4.0.jar https://raw.githubusercontent.com/baalajimaestro/AnyKernel3/master/zipsigner-4.0.jar
java -jar zipsigner-4.0.jar "${TEMPZIPNAME}" "${ZIPNAME}"
END=$(date +"%s")
DIFF=$(( END - START ))
# Ship it to the CI channel
tg_ship "<b>Build #$CIRCLE_BUILD_NUM for *${KERNEL}* succeeded</b>" \
"" \
"<b>Device:</b> ${DEVICE}" \
"<b>Build version:</b> ${KERNELTYPE}" \
"<b>HEAD Commit:</b> ${CHEAD}" \
"<b>Build time elapsed:</b> $((DIFF / 60)):$((DIFF % 60))" \
"" \
"*Backup Boot and DTBO first before installing!*" \
"In case of kernel not booting 😆" \
"" \
"Try it and give me some thoughts!"
}
# Starting
NOW=$(date +%d/%m/%Y-%H:%M)
START=$(date +"%s")
tg_cast "*CI build #$CIRCLE_BUILD_NUM triggered*" \
"Compiling ${KERNEL} with *$(nproc --all)* CPUs" \
"-----------------------------------------" \
"*Compiler:* ${CSTRING}" \
"*Device:* ${DEVICE}" \
"*Build version:* ${KERNELTYPE}" \
"*Tag version:* $(make kernelversion)" \
"*Branch:* ${CIRCLE_BRANCH}" \
"*Start build from:* ${NOW}" \
"*Latest git commit:* ${LATEST_COMMIT}" \
"------------------------------------------" \
"${LOGS_URL}"
makekernel