-
Notifications
You must be signed in to change notification settings - Fork 0
/
nethunter-build-server.sh
116 lines (102 loc) · 3.8 KB
/
nethunter-build-server.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
#!/bin/bash
# DEFINE COLORS
NC='\033[0m'
RED='\033[0;31m'
LRD='\033[1;31m'
LGR='\033[1;32m'
CYAN='\033[1;36m'
YELLOW='\033[1;33m'
rm -rf out
make clean && make mrproper
KERNEL_DIR="${PWD}"
CCACHE=$(command -v ccache)
OBJDIR="${KERNEL_DIR}/out"
Anykernel_DIR=$KERNEL_DIR/Anykernel3
BUILDDIR="${KERNEL_DIR}/build"
ZIMAGE=$KERNEL_DIR/out/arch/arm64/boot/Image.gz-dtb
KERNEL_NAME="samurai-4.14.355"
DATE=$(date +"[%d%m%Y-%H%M]")
TIME=$(date +"%H.%M.%S")
ZIP_NAME="$KERNEL_NAME-$DATE-KSU.zip"
TC_CLONE_FILE=${KERNEL_DIR}/toolchain_clone.sh
export CONFIG_FILE="nethunter_defconfig"
export ARCH="arm64"
export KBUILD_BUILD_HOST=kali
export KBUILD_BUILD_USER=zahid
export LOCALVERSION=-NetHunter+KSU
# DEFINE VARIABLES & CLANG TOOLCHAIN
TC_DIR=$KERNEL_DIR/toolchain
CLANG_DIR=$TC_DIR/clang-r522817
##Check if CLANG_DIR exists........
if ! [ -d "$TC_DIR" ]; then
echo -e "${LRD}Toolchain not found! Cloning to $TC_DIR...${NC}"
if ! bash $TC_CLONE_FILE; then
echo -e "${RED}Cloning failed! Aborting...${NC}"
exit 1
fi
fi
echo -e "${YELLOW}Using clang directory: $CLANG_DIR${NC}"
export PATH="$CLANG_DIR/bin:$PATH"
##SYNC SUBMODULE
git submodule init && git submodule update
##Installing necessary components
! sudo apt-get install bc git gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig libssl-dev ccache cpio axel bc build-essential ccache curl device-tree-compiler pandoc libncurses5-dev lynx lz4 fakeroot xz-utils bc build-essential ccache curl device-tree-compiler pandoc lynx lz4 fakeroot xz-utils
##BUILD STARTED.....!!!
make_defconfig()
{
BUILD_START=$(date +"%s")
echo -e ${LGR} "*********************************************${NC}"
echo -e ${LGR} "########### Generating Defconfig ############${NC}"
make -s ARCH=${ARCH} O=${OBJDIR} ${CONFIG_FILE} -j$(nproc --all)
# make -s ARCH=${ARCH} O=${OBJDIR} menuconfig
}
compile()
{
cd ${KERNEL_DIR}
echo -e "${CYAN}*********************************************${NC}"
echo -e "${CYAN} COMPILING KERNEL ${NC}"
echo -e "${CYAN}*********************************************${NC}"
make -j$(nproc --all) \
O=out \
ARCH=${ARCH}\
CC="ccache clang" \
CLANG_TRIPLE="aarch64-linux-gnu-" \
CROSS_COMPILE="aarch64-linux-gnu-" \
CROSS_COMPILE_ARM32="arm-linux-gnueabi-" \
LLVM=1 \
LLVM_IAS=1
}
completion()
{
cd ${OBJDIR}
COMPILED_IMAGE=arch/arm64/boot/Image.gz-dtb
COMPILED_DTBO=arch/arm64/boot/dtbo.img
COMPILED_DTC=arch/arm64/boot/dts/qcom/sm8150-v2.dtb
if [[ -f ${COMPILED_IMAGE} && ${COMPILED_DTBO} && ${COMPILED_DTC} ]]; then
git clone https://github.com/zahid5656/AnyKernel3.git -b nethunter $Anykernel_DIR
mv -f $ZIMAGE ${COMPILED_DTBO} ${COMPILED_DTC} $Anykernel_DIR
cd $Anykernel_DIR
find . -name "*.zip" -type f
find . -name "*.zip" -type f -delete
zip -r AnyKernel.zip *
mv AnyKernel.zip $ZIP_NAME
mv $Anykernel_DIR/$ZIP_NAME $KERNEL_DIR/$ZIP_NAME
rm -rf $Anykernel_DIR
echo -e ${LGR} "###################################################"
echo -e ${LGR} "###### KERNEL COMPILED SUCCESSFULLY!!! :) ######"
echo -e ${LGR} "###################################################${NC}"
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
echo -e "${LGR}BUILD COMPLETED in $(($DIFF / 60)) minute(s) & $(($DIFF % 60)) seconds.${NC}"
exit 0
else
echo -e ${LRD} "############################################"
echo -e ${LRD} "### ERROR!!! Unsccessfull :'( ###"
echo -e ${LRD} "############################################${NC}"
exit 1
fi
}
make_defconfig
compile
completion
cd ${KERNEL_DIR}