-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.sh
226 lines (178 loc) · 5.49 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
#!/usr/bin/env sh
# Changable Data
# ------------------------------------------------------------
# Kernel
KERNEL_NAME="MilkKernel"
KERNEL_GIT="https://github.com/SchweGELBin/kernel_milk_davinci.git"
KERNEL_BRANCH="vantom-14"
KERNEL_TYPE="vantom"
# KernelSU
KERNELSU_REPO="tiann/KernelSU"
KSU_ENABLED="false"
KSU_TARGET="v0.9.5"
# Anykernel3
ANYKERNEL3_GIT="https://github.com/SchweGELBin/AnyKernel3_davinci.git"
ANYKERNEL3_BRANCH="master"
# Build
DEVICE_CODE="davinci"
DEVICE_ARCH="arch/arm64"
# Clang
CLANG_REPO="ZyCromerZ/Clang"
# ------------------------------------------------------------
# Highlight
msg() {
echo
echo -e "\e[1;33m$*\e[0m"
echo
}
# Input Variables
if [[ $1 == "KSU" ]]; then
KSU_ENABLED="true"
elif [[ $1 == "NonKSU" ]]; then
KSU_ENABLED="false"
fi
if [[ $2 == *.git ]]; then
KERNEL_GIT=$2
fi
if [[ $3 ]]; then
KERNEL_BRANCH=$3
fi
if [[ $4 ]]; then
KERNEL_TYPE=$4
fi
if [[ $KERNEL_TYPE == "vantom" ]]; then
DEVICE_DEFCONFIG="davinci_defconfig"
COMMON_DEFCONFIG=""
elif [[ $KERNEL_TYPE == "perf" ]]; then
DEVICE_DEFCONFIG="vendor/davinci.config"
COMMON_DEFCONFIG="vendor/sdmsteppe-perf_defconfig"
else
DEVICE_DEFCONFIG="davinci_defconfig"
COMMON_DEFCONFIG=""
fi
msg "Variables"
echo "KSU_ENABLED: $KSU_ENABLED"
echo "KERNEL_GIT: $KERNEL_GIT"
echo "KERNEL_BRANCH: $KERNEL_BRANCH"
echo "DEVICE_DEFCONFIG: $DEVICE_DEFCONFIG"
echo "COMMON_DEFCONFIG: $COMMON_DEFCONFIG"
# Set variables
WORKDIR="$(pwd)"
CLANG_DLINK="$(curl -s https://api.github.com/repos/$CLANG_REPO/releases/latest\
| grep -wo "https.*" | grep Clang-.*.tar.gz | sed 's/.$//')"
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/SchweGELBin/kernel_milk_davinci/blob/master/README.md"
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=SchweGELBin
export KBUILD_BUILD_HOST=GitHubCI
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_VERSION: -1} = "." ] && KERNEL_VERSION=${KERNEL_VERSION::-1}
msg "Kernel Version: $KERNEL_VERSION"
TITLE=$KERNEL_NAME-$KERNEL_VERSION
cd $KERNEL_DIR
msg "KernelSU"
if [[ $KSU_ENABLED == "true" ]]; then
curl -LSs "https://raw.githubusercontent.com/$KERNELSU_REPO/main/kernel/setup.sh" | bash -s $KSU_TARGET
echo "CONFIG_KPROBES=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_HAVE_KPROBES=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KPROBE_EVENTS=y" >> $DEVICE_DEFCONFIG_FILE
KSU_GIT_VERSION=$(cd KernelSU && git rev-list --count HEAD)
KERNELSU_VERSION=$(($KSU_GIT_VERSION + 10200))
msg "KernelSU Version: $KERNELSU_VERSION"
TITLE=$TITLE-$KERNELSU_VERSION
sed -i "s/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=\"-$KERNELSU_VERSION-$KERNEL_NAME\"/" $DEVICE_DEFCONFIG_FILE
else
echo "KernelSU Disabled"
KERNELSU_VERSION="Disabled"
sed -i "s/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=\"-$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- \
CC=clang \
NM=llvm-nm \
CXX=clang++ \
AR=llvm-ar \
LD=ld.lld \
STRIP=llvm-strip \
OBJDUMP=llvm-objdump \
OBJSIZE=llvm-size \
READELF=llvm-readelf \
HOSTAR=llvm-ar \
HOSTLD=ld.lld \
HOSTCC=clang \
HOSTCXX=clang++ \
LLVM=1 \
LLVM_IAS=1"
rm -rf out
make O=out $args "$COMMON_DEFCONFIG"
make O=out $args "$DEVICE_DEFCONFIG"
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
cp $IMAGE .
cp $DTB $WORKDIR/Anykernel3/dtb
cp $DTBO .
# Archive
mkdir -p $WORKDIR/out
if [[ $KSU_ENABLED == "true" ]]; then
ZIP_NAME="$KERNEL_NAME-KSU.zip"
else
ZIP_NAME="$KERNEL_NAME-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
- **Kernel Type**: $KERNEL_TYPE
<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"