forked from SchweGELBin/action_kernel_milk_davinci
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.sh
352 lines (288 loc) · 12 KB
/
main.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/usr/bin/env sh
# Changable Data
# ------------------------------------------------------------
# Kernel
KERNEL_NAME="Bootlegger"
KERNEL_GIT="https://github.com/silvzr/bootlegger_kernel_archive.git"
KERNEL_BRANCH=""
# KernelSU
KERNELSU_REPO="tiann/KernelSU"
KSU_ENABLED="false"
# Anykernel3
ANYKERNEL3_GIT="https://github.com/silvzr/AnyKernel3.git"
ANYKERNEL3_BRANCH="master"
# Build
DEVICE_CODE="davinci"
DEVICE_DEFCONFIG="davinci_defconfig"
COMMON_DEFCONFIG=""
DEVICE_ARCH="arch/arm64"
# Clang
CLANG_REPO="ZyCromerZ/Clang"
CLANG_VERSION="latest"
# ------------------------------------------------------------
# Input Variables
if [[ $1 == "KSU" ]]; then
KSU_ENABLED="true"
echo "Input changed KSU_ENABLED to true"
elif [[ $1 == "NonKSU" ]]; then
KSU_ENABLED="false"
echo "Input changed KSU_ENABLED to false"
fi
if [[ $2 == *.git ]]; then
KERNEL_GIT=$2
echo "Input changed KERNEL_GIT to $2"
fi
if [[ $3 ]]; then
KERNEL_BRANCH=$3
echo "Input changed KERNEL_BRANCH to $3"
fi
if [[ $4 == *.git ]]; then
ANYKERNEL3_GIT=$4
echo "Input changed KERNEL_GIT to $4"
fi
if [[ $5 ]]; then
DEVICE_CODE=$5
echo "Input changed DEVICE_CODE to $5"
fi
if [[ $6 ]]; then
DEVICE_DEFCONFIG=$6
echo "Input changed DEVICE_DEFCONFIG to $6"
fi
if [[ $7 ]]; then
COMMON_DEFCONFIG=$7
echo "Input changed COMMON_DEFCONFIG to $7"
fi
# Set variables
WORKDIR="$(pwd)"
if [[ $CLANG_VERSION == "latest" ]]; then
CLANG_DLINK="$(curl -s https://api.github.com/repos/$CLANG_REPO/releases/latest | grep -wo "https.*" | grep Clang-.*.tar.gz | sed 's/.$//')"
else
CLANG_DLINK="$(curl -s https://api.github.com/repos/$CLANG_REPO/releases/tags/$CLANG_VERSION | grep -wo "https.*" | grep Clang-.*.tar.gz | sed 's/.$//')"
fi
CLANG_DIR="$WORKDIR/Clang/bin"
KERNEL_REPO="${KERNEL_GIT::-4}/"
KERNEL_SOURCE="${KERNEL_REPO::-1}/tree/$KERNEL_BRANCH"
KERNEL_DIR="$WORKDIR/$KERNEL_NAME"
KERNELSU_SOURCE="https://github.com/$KERNELSU_REPO"
CLANG_SOURCE="https://github.com/$CLANG_REPO"
README="https://github.com/silvzr/bootlegger_kernel_archive/blob/master/README.md"
if [[ ! -z "$COMMON_DEFCONFIG" ]]; then
DEVICE_DEFCONFIG=$7
COMMON_DEFCONFIG=$6
fi
DEVICE_DEFCONFIG_FILE="$KERNEL_DIR/$DEVICE_ARCH/configs/$DEVICE_DEFCONFIG"
IMAGE="$KERNEL_DIR/out/$DEVICE_ARCH/boot/Image.gz"
DTB="$KERNEL_DIR/out/$DEVICE_ARCH/boot/dtb.img"
DTBO="$KERNEL_DIR/out/$DEVICE_ARCH/boot/dtbo.img"
export KBUILD_BUILD_USER=silvzr
export KBUILD_BUILD_HOST=GitHubCI
# Highlight
msg() {
echo
echo -e "\e[1;33m$*\e[0m"
echo
}
cd $WORKDIR
# Setup
msg "Setup"
msg "Clang"
mkdir -p Clang
aria2c -s16 -x16 -k1M $CLANG_DLINK -o Clang.tar.gz
tar -C Clang/ -zxvf Clang.tar.gz
rm -rf Clang.tar.gz
CLANG_VERSION="$($CLANG_DIR/clang --version | head -n 1 | cut -f1 -d "(" | sed 's/.$//')"
CLANG_VERSION=${CLANG_VERSION::-3} # May get removed later
LLD_VERSION="$($CLANG_DIR/ld.lld --version | head -n 1 | cut -f1 -d "(" | sed 's/.$//')"
msg "Kernel"
git clone --depth=1 $KERNEL_GIT -b $KERNEL_BRANCH $KERNEL_DIR
KERNEL_VERSION=$(cat $KERNEL_DIR/Makefile | grep -w "VERSION =" | cut -d '=' -f 2 | cut -b 2-)\
.$(cat $KERNEL_DIR/Makefile | grep -w "PATCHLEVEL =" | cut -d '=' -f 2 | cut -b 2-)\
.$(cat $KERNEL_DIR/Makefile | grep -w "SUBLEVEL =" | cut -d '=' -f 2 | cut -b 2-)
# .$(cat $KERNEL_DIR/Makefile | grep -w "EXTRAVERSION =" | cut -d '=' -f 2 | cut -b 2-)
KERNEL_VER=$(echo $KERNEL_VERSION | cut -d. -f1,2)
msg "Kernel Version: $KERNEL_VERSION"
TITLE=$KERNEL_NAME-$KERNEL_VERSION-$KERNEL_BRANCH
cd $KERNEL_DIR
KERNELSU_DIR=$(find . -mindepth 0 -maxdepth 4 \( -iname "ksu" -o -iname "kernelsu" \) -type d ! -path "*/.git/*" | cut -c3-)
KERNELSU_GITMODULE=$(grep -i "KernelSU" .gitmodules)
cd $WORKDIR
# Compare kernel versions in order to apply the correct patches
version_le() {
[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ]
}
#
if [[ $KERNEL_VER == "4.14" ]]; then
cp ./patches/strip_out_extraversion.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < strip_out_extraversion.patch
msg "4.14 detected! Removing openela tag..." && cd $WORKDIR
fi
msg "KernelSU"
if [[ $KSU_ENABLED == "true" ]] && [[ ! -z "$KERNELSU_DIR" ]]; then
if [[ ! -z "$KERNELSU_GITMODULE" ]]; then
cd $KERNEL_DIR && git submodule init && git submodule update
msg "KernelSU submodule detected! Cloning..." && cd $WORKDIR
fi
if version_le "$KERNEL_VER" "5.9"; then
cp ./patches/KernelSU/Backport/revert_backport_path_umount.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < revert_backport_path_umount.patch
msg "Fixing possible path_umount conflicts..." && cd $WORKDIR
if [[ ! -f "$WORKDIR/patches/KernelSU/SuSFS/add_susfs_in_kernel-$KERNEL_VER.patch" ]]; then
cp ./patches/KernelSU/Backport/backport_path_umount.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < backport_path_umount.patch
msg "Backporting path_umount from 5.10.9..." && cd $WORKDIR
else
cp ./patches/KernelSU/Backport/backport_path_umount_part2.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < backport_path_umount_part2.patch
msg "Partially backporting path_umount from 5.10.9..." && cd $WORKDIR
fi
fi
cp ./patches/KernelSU/Backport/safe_mode_ksu.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < safe_mode_ksu.patch
msg "Backporting KSU safe mode..."
if [[ ! -f "$KERNEL_DIR/fs/susfs.c" || ! -f "$KERNEL_DIR/include/linux/susfs.h" ]]; then
cd $WORKDIR
if [[ -d "$KERNEL_DIR/$KERNELSU_DIR/kernel" ]]; then
cp ./patches/KernelSU/SuSFS/enable_susfs_for_ksu_auto.patch $KERNEL_DIR/$KERNELSU_DIR/
cd $KERNEL_DIR/$KERNELSU_DIR && patch -p1 < enable_susfs_for_ksu_auto.patch
else
cp ./patches/KernelSU/SuSFS/enable_susfs_for_ksu_manual.patch $KERNEL_DIR/$KERNELSU_DIR/
cd $KERNEL_DIR/$KERNELSU_DIR && patch -p1 < enable_susfs_for_ksu_manual.patch
fi
msg "Importing SuSFS into KSU source..." && cd $WORKDIR
cp ./patches/KernelSU/SuSFS/add_susfs_in_kernel-$KERNEL_VER.patch $KERNEL_DIR/
cp ./patches/KernelSU/SuSFS/susfs.c $KERNEL_DIR/fs/
cp ./patches/KernelSU/SuSFS/susfs.h $KERNEL_DIR/include/linux/
cd $KERNEL_DIR && patch -p1 -F 3 < add_susfs_in_kernel-$KERNEL_VER.patch
msg "Importing SuSFS for $KERNEL_VER kernel..."
fi
echo "CONFIG_KSU=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KSU_SUSFS=y" >> $DEVICE_DEFCONFIG_FILE
if [[ ! -z "$KERNELSU_GITMODULE" ]]; then
KSU_GIT_VERSION=$(cd KernelSU && git rev-list --count HEAD)
KERNELSU_VERSION=$(($KSU_GIT_VERSION + 10200))
else
KERNELSU_VERSION=$(cat $KERNELSU_DIR/ksu.h | grep "KERNEL_SU_VERSION" | cut -c26-)
fi
msg "KernelSU Version: $KERNELSU_VERSION"
sed -i "s/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=\"-$KERNEL_BRANCH-$KERNEL_NAME-KSU\"/" $DEVICE_DEFCONFIG_FILE
elif
[[ $KSU_ENABLED == "true" ]]; then
cd $KERNEL_DIR && curl -LSs "https://raw.githubusercontent.com/$KERNELSU_REPO/main/kernel/setup.sh" | bash -s main
cd $WORKDIR
if version_le "$KERNEL_VER" "5.9"; then
if [[ ! -f "$WORKDIR/patches/KernelSU/SuSFS/add_susfs_in_kernel-$KERNEL_VER.patch" ]]; then
cp ./patches/KernelSU/Backport/backport_path_umount.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < backport_path_umount.patch
msg "Backporting path_umount from 5.10.9..." && cd $WORKDIR
else
cp ./patches/KernelSU/Backport/backport_path_umount_part2.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < backport_path_umount_part2.patch
msg "Partially backporting path_umount from 5.10.9..." && cd $WORKDIR
fi
cp ./patches/KernelSU/revert_drop_non_gki.patch $KERNEL_DIR/KernelSU/
cd $KERNEL_DIR/KernelSU && patch -p1 < revert_drop_non_gki.patch
msg "Readding support for Non GKI kernels..." && cd $WORKDIR
fi
cp ./patches/KernelSU/Backport/hook_patches_ksu-$KERNEL_VER.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < hook_patches_ksu-$KERNEL_VER.patch
msg "Importing KSU hooks for $KERNEL_VER kernel..." && cd $WORKDIR
cp ./patches/KernelSU/SuSFS/enable_susfs_for_ksu_auto.patch $KERNEL_DIR/KernelSU
cd $KERNEL_DIR/KernelSU && patch -p1 < enable_susfs_for_ksu_auto.patch
msg "Importing SuSFS into KSU source..." && cd $WORKDIR
cp ./patches/KernelSU/SuSFS/add_susfs_in_kernel-$KERNEL_VER.patch $KERNEL_DIR/
cp ./patches/KernelSU/SuSFS/susfs.c $KERNEL_DIR/fs/
cp ./patches/KernelSU/SuSFS/susfs.h $KERNEL_DIR/include/linux/
cd $KERNEL_DIR && patch -p1 < add_susfs_in_kernel-$KERNEL_VER.patch
msg "Importing SuSFS into $KERNEL_VER kernel..."
if [[ ! -f "$WORKDIR/patches/KernelSU/Backport/hook_patches_ksu-$KERNEL_VER.patch" ]]; then
echo "CONFIG_KPROBES=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_HAVE_KPROBES=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KPROBE_EVENTS=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KSU_SUSFS=y" >> $DEVICE_DEFCONFIG_FILE
msg "Hook patches not found! Using kprobes..."
else
echo "CONFIG_KSU=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KSU_SUSFS=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KPROBES=n" >> $DEVICE_DEFCONFIG_FILE # it will conflict with KSU hooks if it's on
fi
KSU_GIT_VERSION=$(cd KernelSU && git rev-list --count HEAD)
KERNELSU_VERSION=$(($KSU_GIT_VERSION + 10200))
msg "KernelSU Version: $KERNELSU_VERSION"
sed -i "s/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=\"-$KERNEL_BRANCH-$KERNEL_NAME-KSU\"/" $DEVICE_DEFCONFIG_FILE
fi
if [[ $KSU_ENABLED == "false" ]]; then
echo "KernelSU Disabled"
cd $KERNEL_DIR
echo "CONFIG_KSU=n" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KPROBES=n" >> $DEVICE_DEFCONFIG_FILE # just in case KSU is left on by default
KERNELSU_VERSION="Disabled"
sed -i "s/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=\"-$KERNEL_BRANCH-$KERNEL_NAME\"/" $DEVICE_DEFCONFIG_FILE
fi
# Build
msg "Build"
args="PATH=$CLANG_DIR:$PATH \
ARCH=arm64 \
SUBARCH=arm64 \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- \
CROSS_COMPILE_COMPAT=arm-linux-gnueabi- \
CC=clang \
LD=ld.lld \
LLVM=1 \
LLVM_IAS=1"
rm -rf out
make O=out $args $DEVICE_DEFCONFIG
if [[ ! -z "$COMMON_DEFCONFIG" ]]; then
make O=out $args $COMMON_DEFCONFIG
fi
make O=out $args kernelversion
make O=out $args -j"$(nproc --all)"
msg "Kernel version: $KERNEL_VERSION"
# Package
msg "Package"
cd $WORKDIR
git clone --depth=1 $ANYKERNEL3_GIT -b $ANYKERNEL3_BRANCH $WORKDIR/Anykernel3
cd $WORKDIR/Anykernel3
AK3_DEVICE=$(grep -m 1 "device.name.*=$DEVICE_CODE" anykernel.sh | cut -d '=' -f 2)
DEVICE_DEFCONFIG_CODE=$(basename $DEVICE_DEFCONFIG | cut -d '_' -f 1 | cut -d '-' -f 1)
COMMON_DEFCONFIG_CODE=$(basename $COMMON_DEFCONFIG | cut -d '.' -f 1 | cut -d '-' -f 1)
if [[ $AK3_DEVICE != $DEVICE_CODE ]] && [[ $DEVICE_CODE == $DEVICE_DEFCONFIG_CODE || $DEVICE_CODE == $COMMON_DEFCONFIG_CODE ]]; then
sed -i "s/device.name1=.*/device.name1=$DEVICE_CODE/" anykernel.sh
sed -i "s/device.name2=.*/device.name2=/" anykernel.sh
sed -i "s/device.name3=.*/device.name3=/" anykernel.sh
sed -i "s/device.name4=.*/device.name4=/" anykernel.sh
sed -i "s/device.name5=.*/device.name5=/" anykernel.sh
msg "Wrong AnyKernel3 repo detected! Trying to fix it..."
fi
cp $IMAGE .
cp $DTB $WORKDIR/Anykernel3/dtb
cp $DTBO .
# Archive
mkdir -p $WORKDIR/out
if [[ $KSU_ENABLED == "true" ]]; then
ZIP_NAME="$KERNEL_NAME-$KERNEL_VERSION-$KERNEL_BRANCH-KSU.zip"
else
ZIP_NAME="$KERNEL_NAME-$KERNEL_VERSION-$KERNEL_BRANCH-NonKSU.zip"
fi
TIME=$(TZ='Europe/Berlin' date +"%Y-%m-%d %H:%M:%S")
find ./ * -exec touch -m -d "$TIME" {} \;
zip -r9 $ZIP_NAME *
cp *.zip $WORKDIR/out
# Release Files
cd $WORKDIR/out
msg "Release Files"
echo "
## [$KERNEL_NAME]($README)
- **Time**: $TIME # CET
- **Codename**: $DEVICE_CODE
<br>
- **[Kernel]($KERNEL_SOURCE) Version**: $KERNEL_VERSION
- **[KernelSU]($KERNELSU_SOURCE) Version**: $KERNELSU_VERSION
<br>
- **[CLANG]($CLANG_SOURCE) Version**: $CLANG_VERSION
- **LLD Version**: $LLD_VERSION
" > bodyFile.md
echo "$TITLE" > name.txt
#echo "$KERNEL_NAME" > name.txt
# Finish
msg "Done"