-
Notifications
You must be signed in to change notification settings - Fork 56
/
setup.sh
executable file
·82 lines (71 loc) · 2.67 KB
/
setup.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
#!/bin/bash
usage()
{
echo "Usage : $0 [ OPTIONS ]"
echo "Options : "
echo " -l : Setup Localy "
echo " -v x86/arm : Setup corresponding virtual images"
}
if [ $# -eq 0 ]
then
usage
exit
fi
while getopts ":lv:" opt ;do
case "${opt}" in
l)
echo -e "\n---- Installing Kernel Headers -----\n\n"
sudo apt update && sudo apt install -y linux-headers-$(uname -r)
;;
v)
if [ ${OPTARG} != "x86" -a ${OPTARG} != "arm" ]; then
echo -e "Invalid Architecture Specified \n\n"
usage
exit
fi
# Install qemu for running the kernel Images
echo -e "\n---- Installing QEMU -----\n\n"
sudo apt update && sudo apt-get install -y qemu qemu-user qemu-user-static
echo -e "\n---- Installing Kernel Sources -----\n\n"
mkdir kernel_source
cd kernel_source
wget -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.18.16.tar.xz
tar -xvf linux-4.18.16.tar.xz
cd ../
if [ ${OPTARG} = "arm" ] ;then
# GDB multiarch for Debugging
sudo apt-get install -y gdb-multiarch
# Cross Compiler for arm
sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libelf-dev gcc-aarch64-linux-gnu
echo -e "\n---- Unpacking Kernel Image ----\n\n"
tar -xvzf ./images/arm64/arm64-Image.tar.gz -C ./images/arm64/
echo -e "\n---- Preparing Kernel for Module Compilation ----\n\n"
cd ./kernel_source/linux-4.18.16/
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make modules_prepare
cd ../../
fi
if [ ${OPTARG} = "x86" ]; then
sudo apt-get install -y libssl-dev
echo -e "Downloading Virtual image\n"
cd ./images
wget -c http://www.akulpillai.com/how2kernel/x86_64.tar.gz
tar xvf x86_64.tar.gz
cd ../
echo "Building for x86"
echo -e "\n---- Preparing Kernel for Module Compilation ----\n\n"
sudo apt install bison
sudo apt install flex
sudo apt install libelf-dev
cd ./kernel_source/linux-4.18.16/
make x86_64_defconfig
make modules_prepare
cd ../../
fi
;;
*)
echo "Invalid Option "
usage
;;
esac
done