forked from jagogardiner/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kernel.sh
executable file
·229 lines (189 loc) · 7.39 KB
/
kernel.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
#!/usr/bin/env bash
#
# Copyright (C) 2019 nysascape
#
# Licensed under the Raphielscape Public License, Version 1.d (the "License");
# you may not use this file except in compliance with the License.
#
# Local build script for Acrux.
function cleanupfail1
{
rm -rf ${ANYKERNEL}
rm -rf ${TELEGRAM}
cd ../
rm -rf telegram
cd $1
git reset --hard HEAD^
}
function cleanupfail2
{
rm -rf ${ANYKERNEL}
rm -rf ${TELEGRAM}
cd ../
rm -rf telegram
cd $1
git reset --hard HEAD~2
}
ACRUXPATH=$1
KERNELRELEASE=$2
SCRIPTSPATH=$(pwd)
OUTDIR=${ACRUXPATH}/out
# Make sure our fekking token is exported ig?
export TELEGRAM_TOKEN=$3
# Some misc enviroment vars
DEVICE=Platina
CIPROVIDER=Local
KERNELFW=Global
# Clone our AnyKernel3 branch to KERNELDIR
git clone https://github.com/nysascape/Acrux-AK3 -b master ${ACRUXPATH}/anykernel3
export ANYKERNEL=${ACRUXPATH}/anykernel3
git clone https://github.com/fabianonline/telegram.sh/ telegram
# Export Telegram.sh
TELEGRAM=${SCRIPTSPATH}/telegram/telegram
# Examine our compilation threads
# 2x of our available CPUs
# Kanged from @raphielscape <3
CPU="$(grep -c '^processor' /proc/cpuinfo)"
JOBS="$(( CPU * 2 ))"
COMPILER_STRING='GCC 9.x'
COMPILER_TYPE='GCC9.x'
cd ${ACRUXPATH}
# Always clean build
rm -rf ${OUTDIR}
# Parse git things
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)"
# Do some silly defconfig replacements
if [[ "${PARSE_BRANCH}" =~ "staging"* ]]; then
# For staging branch
KERNELTYPE=nightly
KERNELNAME="Acrux-${KERNELRELEASE}-Nightly-${KERNELFW}-$(date +%Y%m%d-%H%M)"
sed -i "51s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/acrux_defconfig
elif [[ "${PARSE_BRANCH}" =~ "pie"* ]]; then
# For stable (pie) branch
KERNELTYPE=stable
KERNELNAME="Acrux-${KERNELRELEASE}-Release-${KERNELFW}-$(date +%Y%m%d-%H%M)"
sed -i "51s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/acrux_defconfig
else
# Dunno when this will happen but we will cover, just in case
KERNELTYPE=${PARSE_BRANCH}
KERNELNAME="Acrux-${KERNELRELEASE}-${PARSE_BRANCH}-${KERNELFW}-$(date +%Y%m%d-%H%M)"
sed -i "51s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/acrux_defconfig
fi
export KERNELTYPE KERNELNAME
# Workaround for long af kernel strings
git add .
git commit -m "stop adding dirty"
# Might as well export our zip
export TEMPZIPNAME="${KERNELNAME}-unsigned.zip"
export ZIPNAME="${KERNELNAME}.zip"
# Our TG channels
CI_CHANNEL="-1001420038245"
TG_GROUP="-1001435271206"
# Send to main group
tg_groupcast() {
"${TELEGRAM}" -c "${TG_GROUP}" -H \
"$(
for POST in "${@}"; do
echo "${POST}"
done
)"
}
# sendcast to channel
tg_channelcast() {
"${TELEGRAM}" -c "${CI_CHANNEL}" -H \
"$(
for POST in "${@}"; do
echo "${POST}"
done
)"
}
# Let's announce our naisu new kernel!
tg_groupcast "Acrux compilation clocked at $(date +%Y%m%d-%H%M)!"
tg_channelcast "Compiler: <code>${COMPILER_STRING}</code>" \
"Device: <b>${DEVICE}</b>" \
"Kernel: <code>Acrux, release ${KERNELRELEASE}</code>" \
"Branch: <code>${PARSE_BRANCH}</code>" \
"Commit point: <code>${COMMIT_POINT}</code>" \
"Under <code>${CIPROVIDER}, with $(nproc --all) cores</code>" \
"Clocked at: <code>$(date +%Y%m%d-%H%M)</code>" \
"Started on <code>$(whoami)</code>"
# Make is shit so I have to pass thru some toolchains
# Let's build, anyway
PATH="${KERNELDIR}/clang/bin:${PATH}"
START=$(date +"%s")
make O=out ARCH=arm64 acrux_defconfig
make -j"${JOBS}" O=out ARCH=arm64 CROSS_COMPILE="/home/$(whoami)/gcc9/bin/aarch64-elf-" CROSS_COMPILE_ARM32="/home/$(whoami)gcc932/bin/arm-eabi-"
## Check if compilation is done successfully.
if ! [ -f "${OUTDIR}"/arch/arm64/boot/Image.gz-dtb ]; then
END=$(date +"%s")
DIFF=$(( END - START ))
echo -e "Kernel compilation failed, See buildlog to fix errors"
tg_channelcast "Build for ${DEVICE} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! Check Semaphore for errors!"
tg_groupcast "Build for ${DEVICE} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! Check Semaphore for errors @nysascape! @acruxci"
cleanupfail1
exit 1
fi
# Copy our !!hopefully!! compiled kernel
cp "${OUTDIR}"/arch/arm64/boot/Image.gz-dtb "${ANYKERNEL}"/
# POST ZIP OR FAILURE
cd "${ANYKERNEL}" || exit
zip -r9 "${TEMPZIPNAME}" *
## Sign the zip before sending it to telegram
curl -sLo zipsigner-3.0.jar https://raw.githubusercontent.com/baalajimaestro/AnyKernel2/master/zipsigner-3.0.jar
java -jar zipsigner-3.0.jar ${TEMPZIPNAME} ${ZIPNAME}
"${TELEGRAM}" -f "$ZIPNAME" -c "${CI_CHANNEL}"
cd ..
rm -rf "${ANYKERNEL}"
git clone https://github.com/nysascape/Acrux-AK3 -b master anykernel3
# Build China fixes
KERNELFW=China
git fetch https://github.com/nysascape/kernel_xiaomi_acrux oem
git cherry-pick dc8e417a8d54d8c0893f19b97fb448d2a72b058d
# Do some silly defconfig replacements
if [[ "${PARSE_BRANCH}" =~ "staging"* ]]; then
# For staging branch
KERNELTYPE=nightly
KERNELNAME="Acrux-${KERNELRELEASE}-Nightly-${KERNELFW}-$(date +%Y%m%d-%H%M)"
sed -i "51s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/acrux_defconfig
elif [[ "${PARSE_BRANCH}" =~ "pie"* ]]; then
# For stable (pie) branch
KERNELTYPE=stable
KERNELNAME="Acrux-${KERNELRELEASE}-Release-${KERNELFW}-$(date +%Y%m%d-%H%M)"
sed -i "51s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/acrux_defconfig
else
# Dunno when this will happen but we will cover, just in case
KERNELTYPE=${PARSE_BRANCH}
KERNELNAME="Acrux-${KERNELRELEASE}-${PARSE_BRANCH}-${KERNELFW}-$(date +%Y%m%d-%H%M)"
sed -i "51s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/acrux_defconfig
fi
export KERNELTYPE KERNELNAME
export TEMPZIPNAME="${KERNELNAME}-unsigned.zip"
export ZIPNAME="${KERNELNAME}.zip"
make O=out ARCH=arm64 acrux_defconfig
make -j"${JOBS}" O=out ARCH=arm64 CROSS_COMPILE="/home/$(whoami)/gcc9/bin/aarch64-elf-" CROSS_COMPILE_ARM32="/home/$(whoami)/gcc932/bin/arm-eabi-"
## Check if compilation is done successfully.
if ! [ -f "${OUTDIR}"/arch/arm64/boot/Image.gz-dtb ]; then
END=$(date +"%s")
DIFF=$(( END - START ))
echo -e "Kernel compilation failed !!(FOR CHINA FW)!!, See buildlog to fix errors"
tg_channelcast "Build for ${DEVICE} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! Check Semaphore for errors!"
tg_groupcast "Build for ${DEVICE} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! Check Semaphore for errors @nysascape! @acruxci"
cleanupfail2
exit 1
fi
# Copy our !!hopefully!! compiled kernel
cp "${OUTDIR}"/arch/arm64/boot/Image.gz-dtb "${ANYKERNEL}"/
# POST ZIP OR FAILURE
cd "${ANYKERNEL}" || exit
zip -r9 "${TEMPZIPNAME}" *
## Sign the zip before sending it to telegram
curl -sLo zipsigner-3.0.jar https://raw.githubusercontent.com/baalajimaestro/AnyKernel2/master/zipsigner-3.0.jar
java -jar zipsigner-3.0.jar ${TEMPZIPNAME} ${ZIPNAME}
"${TELEGRAM}" -f "$ZIPNAME" -c "${CI_CHANNEL}"
END=$(date +"%s")
DIFF=$(( END - START ))
tg_channelcast "Build for ${DEVICE} with ${COMPILER_STRING} took $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)!"
tg_groupcast "Build for ${DEVICE} with ${COMPILER_STRING} took $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! @acruxci"
cleanupfail2