forked from Alone0316/ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
219 lines (183 loc) · 7.6 KB
/
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
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
#!/bin/bash
#
# Copyright (C) 2020 Fox kernel project
#
# 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.
#
# Setup colour for the script
yellow='\033[0;33m'
white='\033[0m'
red='\033[0;31m'
green='\e[0;32m'
# Deleting out "kernel complied" and zip "anykernel" from an old compilation
echo -e "$green << cleanup >> \n $white"
rm -rf out
rm -rf zip
rm -rf error.log
echo -e "$green << setup dirs >> \n $white"
# With that setup , the script will set dirs and few important thinks
MY_DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$MY_DIR" ]]; then MY_DIR="$PWD"; fi
# Now u can chose which things need to be modified
# CHATID = chatid of a telegram group/channel
# API_BOT = api bot of a telegram bot
#
# DEVICE = your device codename
# KERNEL_NAME = the name of ur kranul
#
# DEFCONFIG = defconfig that will be used to compile the kernel
#
# AnyKernel = the url of your modified anykernel script
# AnyKernelbranch = the branch of your modified anykernel script
#
# HOSST = build host
# USEER = build user
#
# TOOLCHAIN = the toolchain u want to use "gcc/clang"
CHATID="-1001283860476"
API_BOT="2049436092:AAFV-TxprsH_aC3_XBl-6uhgc9MToKhqUCQ"
DEVICE="Redmi Note 4/4X"
CODENAME="mido"
KERNEL_NAME="FussionKernel"
DEFCONFIG="mido_defconfig"
AnyKernel="https://github.com/Hunter-commits/anykernel.git"
AnyKernelbranch="master"
HOSST="Alone's Buildbot"
USEER="Alone0316"
TOOLCHAIN="clang"
# setup telegram env
export BOT_MSG_URL="https://api.telegram.org/bot$API_BOT/sendMessage"
export BOT_BUILD_URL="https://api.telegram.org/bot$API_BOT/sendDocument"
tg_post_msg() {
curl -s -X POST "$BOT_MSG_URL" -d chat_id="$2" \
-d "parse_mode=html" \
-d text="$1"
}
tg_post_build() {
#Post MD5Checksum alongwith for easeness
MD5CHECK=$(md5sum "$1" | cut -d' ' -f1)
#Show the Checksum alongwith caption
curl --progress-bar -F document=@"$1" "$BOT_BUILD_URL" \
-F chat_id="$2" \
-F "disable_web_page_preview=true" \
-F "parse_mode=html" \
-F caption="$3 build finished in $(($Diff / 60)) minutes and $(($Diff % 60)) seconds | <b>MD5 Checksum : </b><code>$MD5CHECK</code>"
}
tg_error() {
curl --progress-bar -F document=@"$1" "$BOT_BUILD_URL" \
-F chat_id="$2" \
-F "disable_web_page_preview=true" \
-F "parse_mode=html" \
-F caption="$3Failed to build , check <code>error.log</code>"
}
# Now let's clone gcc/clang on HOME dir
# And after that , the script start the compilation of the kernel it self
# For regen the defconfig . use the regen.sh script
if [ "$TOOLCHAIN" == gcc ]; then
if [ ! -d "$HOME/gcc64" ] && [ ! -d "$HOME/gcc32" ]
then
echo -e "$green << cloning gcc from arter >> \n $white"
git clone --depth=1 https://github.com/mvaisakh/gcc-arm64 "$HOME"/gcc64
git clone --depth=1 https://github.com/mvaisakh/gcc-arm "$HOME"/gcc32
fi
export PATH="$HOME/gcc64/bin:$HOME/gcc32/bin:$PATH"
export STRIP="$HOME/gcc64/aarch64-elf/bin/strip"
export KBUILD_COMPILER_STRING=$("$HOME"/gcc64/bin/aarch64-elf-gcc --version | head -n 1)
elif [ "$TOOLCHAIN" == clang ]; then
if [ ! -d "$HOME/proton_clang" ]
then
echo -e "$green << cloning proton clang >> \n $white"
git clone --depth=1 https://github.com/kdrag0n/proton-clang.git "$HOME"/proton_clang
fi
export PATH="$HOME/proton_clang/bin:$PATH"
export STRIP="$HOME/proton_clang/aarch64-linux-gnu/bin/strip"
export KBUILD_COMPILER_STRING=$("$HOME"/proton_clang/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
fi
# Setup build process
build_kernel() {
Start=$(date +"%s")
if [ "$TOOLCHAIN" == clang ]; then
echo clang
make -j$(nproc --all) O=out \
ARCH=arm64 \
CC="ccache clang" \
AR=llvm-ar \
NM=llvm-nm \
STRIP=llvm-strip \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
OBJSIZE=llvm-size \
READELF=llvm-readelf \
HOSTCC=clang \
HOSTCXX=clang++ \
HOSTAR=llvm-ar \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- \
CONFIG_DEBUG_SECTION_MISMATCH=y \
CONFIG_NO_ERROR_ON_MISMATCH=y 2>&1 | tee error.log
elif [ "$TOOLCHAIN" == gcc ]; then
echo gcc
make -j$(nproc --all) O=out \
ARCH=arm64 \
CROSS_COMPILE=aarch64-elf- \
CROSS_COMPILE_ARM32=arm-eabi- 2>&1 | tee error.log
fi
End=$(date +"%s")
Diff=$(($End - $Start))
}
export IMG="$MY_DIR"/out/arch/arm64/boot/Image.gz-dtb
# Let's start
echo -e "$green << doing pre-compilation process >> \n $white"
export ARCH=arm64
export SUBARCH=arm64
export HEADER_ARCH=arm64
export KBUILD_BUILD_HOST="$HOSST"
export KBUILD_BUILD_USER="$USEER"
mkdir -p out
make O=out clean && make O=out mrproper
make "$DEFCONFIG" O=out
echo -e "$yellow << compiling the kernel >> \n $white"
tg_post_msg "<code>Building Image.gz-dtb</code>" "$CHATID"
build_kernel || error=true
DATE=$(date +"%Y%m%d-%H%M%S")
KERVER=$(make kernelversion)
if [ -f "$IMG" ]; then
echo -e "$green << Build completed in $(($Diff / 60)) minutes and $(($Diff % 60)) seconds >> \n $white"
else
echo -e "$red << Failed to compile the kernel , Check up to find the error >>$white"
tg_error "error.log" "$CHATID"
rm -rf out
rm -rf testing.log
rm -rf error.log
exit 1
fi
if [ -f "$IMG" ]; then
echo -e "$green << cloning AnyKernel from your repo >> \n $white"
git clone "$AnyKernel" --single-branch -b "$AnyKernelbranch" zip
echo -e "$yellow << making kernel zip >> \n $white"
cp -r "$IMG" zip/
cd zip
mv Image.gz-dtb zImage
export ZIP="$KERNEL_NAME"-"$CODENAME"-"$DATE"
zip -r "$ZIP" *
curl -sLo zipsigner-3.0.jar https://raw.githubusercontent.com/Hunter-commits/AnyKernel/master/zipsigner-3.0.jar
java -jar zipsigner-3.0.jar "$ZIP".zip "$ZIP"-signed.zip
tg_post_msg "<b>=============================</b> %0A <b>× FussionKernel For Redmi note 4/4x ×</b> %0A <b>=============================</b> %0A%0A <b>Date : </b> <code>$(TZ=India/Kolkata date)</code> %0A%0A <b>Device Code Name:</b> <code>$CODENAME</code> %0A%0A <b>Kernel Version :</b> <code>$KERVER</code> %0A%0A <b>Developer:</b> @Alone0316 %0A%0A <b>Support group:</b> t.me/fussionkernelmido %0A%0A <b>Channel:</b> t.me/fkupdates %0A%0A <b>Changelog:</b> %0A https://github.com/Alone0316/kernel_mido/commits/normal %0A%0A <b>Download Normal version:</b> %0A https://t.me/fkupdates/ %0A%0A <b>Download Overclock version:</b> %0A https://t.me/fkupdates/ #fussionkernel #mido" "$CHATID"
tg_post_build "$ZIP"-signed.zip "$CHATID"
cd ..
rm -rf error.log
rm -rf out
rm -rf zip
rm -rf testing.log
exit
fi