-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
243 lines (209 loc) · 7.36 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
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
#!/bin/bash
#
# Compile script for LOS kernel
# Copyright (C) 2020-2021 Adithya R & @johnmart19.
# Copyright (C) 2021-2022 Craft Rom.
SECONDS=0 # builtin bash timer
#Set Color
blue='\033[0;34m'
grn='\033[0;32m'
yellow='\033[0;33m'
red='\033[0;31m'
nocol='\033[0m'
txtbld=$(tput bold)
txtrst=$(tput sgr0)
echo -e " "
echo -e " "
echo -e "$blue░▐█▀█░▐█░▐█░▐██░▐█▀█▄▒▐█▀▀█▌▒▐█▀▀▄░▐██"
echo -e "░▐█──░▐████─░█▌░▐█▌▐█▒▐█▄▒█▌▒▐█▒▐█─░█▌"
echo -e "░▐█▄█░▐█░▐█░▐██░▐█▄█▀▒▐██▄█▌▒▐█▀▄▄░▐██$nocol"
echo -e " "
# cmdline options
clean=false
regen=false
do_not_send_to_tg=false
help=false
miui=false
# cmdline check flags
description_was_specified=false
for arg in "$@"; do
case $arg in
-c|--clean)clean=true; shift;;
-r|--regen*)regen=true; shift;;
-l|--local*)do_not_send_to_tg=true; shift;;
-h|--help*)help=true; shift;;
-d|--desc*)
shift
case $1 in
-*);;
*)
description_was_specified=true
DESC="$1"
shift
;;
esac
;;
-n|--night*)TYPE=nightly; shift;;
-s|--stab*)TYPE=stable; shift;;
-e|--exp*)TYPE=experimental; shift;;
-mi|--miui*)miui=true; shift;;
esac
done
case $TYPE in nightly|stable);; *)TYPE=experimental;; esac
# debug:
#echo "`date`: $clean $regen $help $do_not_send_to_tg $TYPE $DESC" >>build_sh.log
KERN_VER=$(echo "$(make kernelversion)")
BUILD_DATE=$(date '+%Y-%m-%d %H:%M')
DEVICE="Poco M3/Redmi 9 Power/9T/Note 9 4G"
KERNELNAME="Chidori-Kernel-$TYPE"
if $miui; then
ZIPNAME="Chidori-Kernel-MIUI-chime-$(date '+%Y%m%d%H%M')-$TYPE.zip"
else
ZIPNAME="Chidori-Kernel-chime-$(date '+%Y%m%d%H%M')-$TYPE.zip"
fi
TC_DIR="$HOME/toolchains/proton-clang"
DEFCONFIG="vendor/chime-perf_defconfig"
sed -i "22s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/$DEFCONFIG
export PATH="$TC_DIR/bin:$PATH"
export KBUILD_BUILD_USER="melles1991"
export KBUILD_BUILD_HOST=CraftRom-build
# Builder detection
[ -n "$HOSTNAME" ] && NAME=$HOSTNAME
case $NAME in
IgorK-*)BUILDER='@DfP_DEV';;
*)BUILDER='@mrshterben';;
esac
echo -e "${txtbld}Type:${txtrst} $TYPE"
echo -e "${txtbld}Config:${txtrst} $DEFCONFIG"
echo -e "${txtbld}ARCH:${txtrst} arm64"
echo -e "${txtbld}Linux:${txtrst} $KERN_VER"
echo -e "${txtbld}Username:${txtrst} $KBUILD_BUILD_USER"
echo -e "${txtbld}Builder:${txtrst} $BUILDER"
echo -e "${txtbld}BuildDate:${txtrst} $BUILD_DATE"
echo -e "${txtbld}Filename::${txtrst} $ZIPNAME"
echo -e " "
if ! [ -d "$TC_DIR" ]; then
echo -e "$grn \nProton clang not found! Cloning to $TC_DIR...\n $nocol"
if ! git clone -q --depth=1 --single-branch https://github.com/kdrag0n/proton-clang $TC_DIR; then
echo -e "$red \nCloning failed! Aborting...\n $nocol"
exit 1
fi
fi
# Help information
if $help; then
echo -e "Usage: ./build.sh [ -c | --clean, -d <args> | --desc <args>,
-h | --help, -r | --regen, -l | --local-build ]\n
These are common commands used in various situations:\n
$grn -c or --clean $nocol Remove files in out folder for clean build.
$grn -d or --description $nocol Adds a description for build;
Used with the <args> argument that contains the description.
Build's description is an important part, so if you do not specify it manually, you will be asked about entering it.
$grn -h or --help $nocol List available subcommands.
$grn -r or --regenerate $nocol Record changes to the defconfigs.
$grn -l or --local-build $nocol Build locally, do not push the archive to Telegram. \n
Build type names:
$grn -s or --stable $nocol Stable build
$grn -n or --nightly $nocol Nightly build
$grn -s or --experimental $nocol Experimental build\n"
sleep 1.5
exit 0
fi
# Clean
if $clean; then
if [ -d "./out/" ]; then
echo -e " "
rm -rf ./out/
fi
echo -e "$grn \nFull cleaning was successful succesfully!\n $nocol"
sleep 1.5
fi
# Telegram setup
push_message() {
curl -s -X POST \
https://api.telegram.org/bot5579959772:AAHJ1cvfipl05kxYhNQBvLy7b60vGmeQSRE/sendMessage \
-d chat_id="-1001695676652" \
-d text="$1" \
-d "parse_mode=html" \
-d "disable_web_page_preview=true"
}
push_document() {
curl -s -X POST \
https://api.telegram.org/bot5579959772:AAHJ1cvfipl05kxYhNQBvLy7b60vGmeQSRE/sendDocument \
-F chat_id="-1001695676652" \
-F document=@"$1" \
-F caption="$2" \
-F "parse_mode=html" \
-F "disable_web_page_preview=true"
}
# Export defconfig
echo -e "$blue \nMake DefConfig\n $nocol"
mkdir -p out
make O=out ARCH=arm64 $DEFCONFIG
if $regen; then
cp out/.config arch/arm64/configs/$DEFCONFIG
sed -i "22s/.*/CONFIG_LOCALVERSION=\"-Chidori-Kernel\"/g" arch/arm64/configs/$DEFCONFIG
git commit -am "defconfig: chime: Regenerate" --signoff
echo -e "$grn \nRegened defconfig succesfully!\n $nocol"
make mrproper
echo -e "$grn \nCleaning was successful succesfully!\n $nocol"
sleep 4
exit 0
fi
# Description check
if ! $description_was_specified; then
echo -en "\n\tYou did not specify the build's description! Do you want to set it?\n\t(Y/n): "
read ans
case $ans in n)echo -e "\tOK, the build will have no description...\n";;
*)
echo -en "\n\t\tType in the build's description: "
read DESC
echo -e "\n\tOK, saved!\n"
sleep 1.5
;;
esac
fi
# Build start
echo -e "$blue \nStarting kernel compilation...\n $nocol"
make -j$(nproc --all) O=out ARCH=arm64 CC="ccache clang" AS=llvm-as AR=llvm-ar NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump STRIP=llvm-strip CROSS_COMPILE=aarch64-linux-gnu- CROSS_COMPILE_ARM32=arm-linux-gnueabi- CLANG_TRIPLE=aarch64-linux-gnu- Image.gz-dtb dtbo.img
kernel="out/arch/arm64/boot/Image.gz-dtb"
dtbo="out/arch/arm64/boot/dtbo.img"
if [ -f "$kernel" ] && [ -f "$dtbo" ]; then
echo -e "$blue \nKernel compiled succesfully! Zipping up...\n $nocol"
if ! [ -d "AnyKernel3" ]; then
echo -e "$grn \nAnyKernel3 not found! Cloning...\n $nocol"
if ! git clone https://github.com/CraftRom/AnyKernel3 -b juice AnyKernel3; then
echo -e "$grn \nCloning failed! Aborting...\n $nocol"
fi
fi
cp $kernel $dtbo AnyKernel3
rm -f *zip
cd AnyKernel3
zip -r9 "../$ZIPNAME" * -x '*.git*' README.md *placeholder
cd ..
echo -e "$grn \n(i) Completed build$nocol $red$((SECONDS / 60))$nocol $grn minute(s) and$nocol $red$((SECONDS % 60))$nocol $grn second(s) !$nocol"
echo -e "$blue \n Flashable zip generated $yellow$ZIPNAME.\n $nocol"
rm -rf out/arch/arm64/boot
# Push kernel to telegram
if ! $do_not_send_to_tg; then
push_document "$ZIPNAME" "
<b>CHIDORI KERNEL | $DEVICE</b>
New update available!
<i>${DESC:-No description given...}</i>
<b>Maintainer:</b> <code>$KBUILD_BUILD_USER</code>
<b>Builder:</b> $BUILDER
<b>Linux:</b> <code>$KERN_VER</code>
<b>Type:</b> <code>$TYPE</code>
<b>BuildDate:</b> <code>$BUILD_DATE</code>
<b>Filename:</b> <code>$ZIPNAME</code>
<b>md5 checksum :</b> <code>$(md5sum "$ZIPNAME" | cut -d' ' -f1)</code>
#chime #juice #citrus #lime #kernel"
echo -e "$grn \n\n(i) Send to telegram succesfully!\n $nocol"
fi
# TEMP
sed -i "22s/-experimental//" arch/arm64/configs/$DEFCONFIG
else
echo -e "$red \nKernel Compilation failed! Fix the errors!\n $nocol"
# Push message if build error
push_message "$BUILDER! <b>Failed building kernel for <code>$DEVICE</code> Please fix it...!</b>"
sleep 4
fi