forked from Mizumo-prjkt/A12s-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
361 lines (330 loc) · 9.63 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
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
353
354
355
356
357
358
359
360
361
#! /usr/bin/env bash
# Rissu Project (C) 2024
# Script for CI and partial for Local Build.
# Contributor: Rissu <farisjihadih@outlook.com>
export RSUPATH="$(pwd)/Rissu"
make_a_config() {
RAND="$RSUPATH/bin/random6"
chmod +x $RAND
mk_config() {
page_one() {
clear
echo " 1"
echo "## Assign a name for your Kernel: (example: MyKernel)"
echo "Rules: No space (example: My Kernel <- Wrong)!"
echo "Default: MyKernel"
read -p "> " TMP_LOCAL_ENV_KERN_STRINGS
if [ -z $TMP_LOCAL_ENV_KERN_STRINGS ]; then
export KERNEL_STRINGS="MyKernel";
else
export KERNEL_STRINGS=$TMP_LOCAL_ENV_KERN_STRINGS
fi
}
page_one;
page_two() {
clear
echo " 2"
echo "## Include KernelSU? ##"
echo "Info: KernelSU is a kernel-based root for Android. an alternative to Magisk rooting."
echo "Options: true, false"
echo "Default: false"
read -p "> " TMP_LOCAL_ENV_KSU_SUPPORT
if [[ $TMP_LOCAL_ENV_KSU_SUPPORT = 'true' ]]; then
export KSU_STATE="true"
elif [[ $TMP_LOCAL_ENV_KSU_SUPPORT = 'false' ]] || [ -z $TMP_LOCAL_ENV_KSU_SUPPORT ]; then
export KSU_STATE="false"
elif [[ $TMP_LOCAL_ENV_KSU_SUPPORT != 'false' ]] || [[ $TMP_LOCAL_ENV_KSU_SUPPORT != 'true' ]]; then
page_two;
fi
}
page_two;
if [[ $KSU_STATE = 'true' ]]; then
page_three() {
clear
echo " 3"
echo "## KernelSU branch ##"
echo "Select KernelSU branch: dev, stable"
echo "Default: stable"
read -p "> " TMP_LOCAL_ENV_KSU_BRANCH
if [[ $TMP_LOCAL_ENV_KSU_BRANCH = 'stable' ]] || [ -z $TMP_LOCAL_ENV_KSU_BRANCH ]; then
export KSU_BRANCH="stable"
elif [[ $TMP_LOCAL_ENV_KSU_BRANCH = 'dev' ]]; then
export KSU_BRANCH="dev"
elif [[ $TMP_LOCAL_ENV_KSU_BRANCH != 'dev' ]] || [[ $TMP_LOCAL_ENV_KSU_BRANCH != 'stable' ]]; then
page_three;
fi
}
page_three;
fi
page_four() {
clear
echo " 4"
echo "## SELinux state ##"
echo "Select SELinux state: permissive, enforcing"
echo "Default: enforcing"
read -p "> " TMP_LOCAL_ENV_SELINUX_STATE
if [[ $TMP_LOCAL_ENV_SELINUX_STATE = 'enforcing' ]] || [ -z $TMP_LOCAL_ENV_SELINUX_STATE ]; then
export SELINUX_STATE="false"
elif [[ $TMP_LOCAL_ENV_SELINUX_STATE = 'permissive' ]]; then
export SELINUX_STATE="true"
elif [[ $TMP_LOCAL_ENV_SELINUX_STATE != 'permissive' ]] || [[ $TMP_LOCAL_ENV_SELINUX_STATE != 'enforcing' ]]; then
page_four;
fi
}
page_four;
page_five() {
clear
echo " 5"
echo "## Assign a revision for your Kernel: (example: 4)"
echo "- [i] You can skip this"
read -p "> " TMP_LOCAL_ENV_REVISION
if [ ! -z $TMP_LOCAL_ENV_REVISION ]; then
export REV="`echo r$TMP_LOCAL_ENV_REVISION`"
else
export REV=$($RAND)
fi
}
page_five;
}
summary() {
clear
echo "";
echo " ##########################################"
echo " # Name: $KERNEL_STRINGS"
echo " # Revision: $REV"
if [[ $KSU_STATE = 'true' ]]; then
echo " # KSU: $KSU_STATE"
echo " # KSU Branch: $KSU_BRANCH"
fi
echo " # SELinux Permissive: $SELINUX_STATE"
echo " ##########################################"
}
mk_config;
summary;
echo "";
read -p "- Is this configuration right to you? (y/n): " GO_BUILD
if [[ $GO_BUILD = 'y' ]] || [[ $GO_BUILD = 'Y' ]]; then
pre_build_stage;
elif [[ $GO_BUILD = 'N' ]] || [[ $GO_BUILD = 'n' ]]; then
mk_config;
else
echo "Illegal options! abort."
exit 1;
fi
}
DATE=$(date +'%Y%m%d%H%M%S')
pre_build_stage() {
if [[ $ENV_IS_CI = 'true' ]]; then
export KERNEL_STRINGS="$CI_ENV_LOCALVERSION"
PRE_REV="${CI_ENV_REVISION//[^0-9]/}"
if [ ! -z $CI_ENV_REVISION ]; then
export REV="r`echo $PRE_REV`"
else
export REV="`echo $DATE`"
fi
fi
## SELINUX
if [[ $SELINUX_STATE = "true" ]]; then
export REAL_STATE="Permissive"
export PERM_FLAGS="y"
export ENF_FLAGS="n"
else
export REAL_STATE="Enforcing"
export PERM_FLAGS="n"
export ENF_FLAGS="y"
fi
## KSU
if [[ $KSU_STATE = "true" ]]; then
if [ ! -d $(pwd)/KernelSU ]; then
if [[ $KSU_BRANCH = "dev" ]]; then
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s main
else
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -
fi
fi
export KSU_VERSION_TAGS=$(cd KernelSU && git describe --tags)
export KSU_COMMIT_COUNT=$(cd KernelSU && git rev-list --count HEAD)
export KSU_VERSION_NUMBER=$(expr 10200 + $KSU_COMMIT_COUNT)
FMT="`echo $KERNEL_STRINGS`-`echo $REV`-`echo $REAL_STATE`-ksu-`echo $KSU_VERSION_NUMBER`_`echo $KSU_VERSION_TAGS`"
BUILD_FLAGS="CONFIG_KSU=y"
else
FMT="`echo $KERNEL_STRINGS`-`echo $REV`_`echo $REAL_STATE`-`echo $DATE`"
fi
# fixup! Fix ci upload filename
TAR_FMT="$FMT.tar"
BOOT_FMT="$FMT.img"
ANYKERNEL3_FMT="`echo $FMT`_AnyKernel3.zip"
if [[ $ENV_IS_CI = 'true' ]]; then
CI_ANYKERNEL3_FMT="`echo $FMT`_AnyKernel3"
echo $CI_ANYKERNEL3_FMT > zipfile_format.txt
echo $FMT > file_format.txt
fi
if [[ $KSU_STATE = 'false' ]]; then
if [ -d $(pwd)/KernelSU ]; then
rm -rR $(pwd)/KernelSU -f
fi
export KSU_HARDCODE_STRINGS="unsupported"
else
export KSU_HARDCODE_STRINGS="`echo $KSU_VERSION_TAGS`/`echo $KSU_VERSION_NUMBER`"
fi
}
# global variable
export DEFCONFIG="rsuntk_defconfig"
export ARCH=arm64
export ANDROID_MAJOR_VERSION=t
export PLATFORM_VERSION=13
# TOOLCHAINS
if [ ! -d /rsuntk ]; then
if [[ $ENV_IS_CI = 'true' ]]; then
# CI default toolchain path
export ANDROID_CC_PATH="$(pwd)/toolchains/google/bin"
export LLVM_PATH="$(pwd)/toolchains/clang/bin"
export GCC_PATH="$(pwd)/toolchains/gnu/bin"
else
# Your own path.
export ANDROID_CC_PATH=
export LLVM_PATH=
export GCC_PATH=
fi
else
# Rissu use a custom mount point.
export ANDROID_CC_PATH="/rsuntk/env/google/bin"
export LLVM_PATH="/rsuntk/env/clang-11/bin"
export GCC_PATH="/rsuntk/env/gnu/bin"
fi
# FMT
export MGSKBOOT="$RSUPATH/bin/magiskboot"
export GEN_RANDOM="$RSUPATH/bin/random"
export OEMBOOT="$RSUPATH/data/stockboot.tar.xz"
# local variable
OUTDIR="$(pwd)/out"
MIN_CORES="2"
CORES=$(nproc --all)
MAKE_SH="$(pwd)/make_cmd.sh"
ANYKERNEL3="$RSUPATH/AnyKernel3"
if [ $CORES -gt $MIN_CORES ]; then
THREADCOUNT="-j`echo $CORES`"
elif [ $CORES -lt $MIN_CORES ]; then
THREADCOUNT="-j1"
else
THREADCOUNT="-j`echo $MIN_CORES`"
fi
chmod +x $MGSKBOOT
chmod +x $GEN_RANDOM
if [[ $ENV_IS_CI = 'true' ]]; then
summary() {
pre_build_stage;
clear
echo "";
echo " ##########################################"
echo " # Name: $KERNEL_STRINGS"
echo " # Revision: $REV"
if [[ $KSU_STATE = 'true' ]]; then
echo " # KSU: $KSU_STATE"
echo " # KSU Branch: $KSU_BRANCH"
fi
echo " # SELinux Permissive: $SELINUX_STATE"
echo " # Upload Gz: $GIT_UPLOAD_GZ"
echo " # Upload img: $GIT_UPLOAD_UNCOMPRESSED_BOOT_IMG"
echo " #########################################"
echo "";
echo "- Build started at `date`"
}
summary;
else
make_a_config;
fi
printf "#! /usr/bin/env bash
# Temporary make commands!
make -C $(pwd) O=$(pwd)/out CONFIG_LOCALVERSION=\"-`echo $KERNEL_STRINGS`\" `echo $BUILD_FLAGS` `echo $DEFCONFIG`
make -C $(pwd) O=$(pwd)/out CONFIG_LOCALVERSION=\"-`echo $KERNEL_STRINGS`\" `echo $BUILD_FLAGS` `echo $THREADCOUNT`" > make_cmd.sh
## Rissu Kernel Project things.
make_boot() {
cd $RSUPATH
cat $RSUPATH/art.txt
tar -xf $OEMBOOT -C $RSUPATH
echo "";
## << Unpack boot with magiskboot
echo "- Unpacking boot"
$MGSKBOOT unpack $RSUPATH/boot.img 2>/dev/null
## << Remove stock samsung kernel
rm $RSUPATH/kernel
## << Copy new kernel to current path
cp $OUTDIR/arch/$ARCH/boot/Image $RSUPATH/kernel
## << Create flashable AnyKernel3
echo "- Creating AnyKernel3"
bash $RSUPATH/mk_version
cp $OUTDIR/arch/$ARCH/boot/Image $ANYKERNEL3
cd $ANYKERNEL3
zip -0 -r $RSUPATH/$ANYKERNEL3_FMT *
cd $RSUPATH
## << Repacking boot
echo "- Repacking boot"
$MGSKBOOT repack $RSUPATH/boot.img 2>/dev/null
rm $RSUPATH/boot.img
mv $RSUPATH/new-boot.img $RSUPATH/boot.img
## << Compress it, to avoid long download time
echo "- Compressing with lz4"
lz4 -B6 --content-size boot.img boot.img.lz4 2>/dev/null
## << Make it ODIN flashable
echo "- Creating tarball file"
tar -cf $TAR_FMT boot.img.lz4
rm $RSUPATH/boot.img.lz4
## << Pack boot.img to tar.xz with Level 9 Extreme flags
echo "- Creating boot file"
echo "- Done!"
echo "- Cleaning files"
mv $RSUPATH/boot.img $RSUPATH/$BOOT_FMT
rm $RSUPATH/kernel && rm $RSUPATH/dtb
if [ -f $RSUPATH/ramdisk.cpio ]; then
rm $RSUPATH/ramdisk.cpio
fi
cd ..
}
purify_anykernel3_folder() {
rm $ANYKERNEL3/Image
rm $ANYKERNEL3/version
}
cleanups() {
rm $OUTDIR/vmlinux
rm $OUTDIR/vmlinux.o
rm $OUTDIR/System.map
rm $OUTDIR/.tmp_kallsyms1.o
rm $OUTDIR/.tmp_kallsyms1.S
rm $OUTDIR/.tmp_kallsyms2.o
rm $OUTDIR/.tmp_kallsyms2.S
rm $OUTDIR/.tmp_System.map
rm $OUTDIR/.tmp_vmlinux1
rm $OUTDIR/.tmp_vmlinux2
}
if [ -f $MAKE_SH ]; then
bash $MAKE_SH ## Execute make commands
rm $MAKE_SH ## Remove it after it done.
# We use vmlinux, Image, and Image.gz file as an build status indicator.
# Because when build is completed, Image and vmlinux file will exist.
if [ -f $OUTDIR/arch/$ARCH/boot/Image ] && [ -f $OUTDIR/vmlinux ]; then
cleanups;
BUILD_STATE=0
else
BUILD_STATE=1
fi
# Have some known issue in here. This indicator cannot detect
# kernel module building. If something failed, well, it keep
# detecting as successful.
echo "- Build state: $BUILD_STATE"
if [[ $BUILD_STATE = '0' ]]; then
if [[ $GIT_UPLOAD_GZ = "true" ]]; then
mv $OUTDIR/arch/arm64/boot/Image.gz $RSUPATH/Image.gz
fi
echo "- Build ended at `date`. Creating boot.img"
make_boot;
if [[ $ENV_IS_CI != 'true' ]]; then
purify_anykernel3_folder;
fi
else
echo "- Build ended at `date`. with status: $BUILD_STATE."
fi
else
echo "- Fatal, $MAKE_SH not found!"
exit 1;
fi