-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArchLinux_custom_kernel_build.sh
More file actions
executable file
·138 lines (90 loc) · 4.14 KB
/
Copy pathArchLinux_custom_kernel_build.sh
File metadata and controls
executable file
·138 lines (90 loc) · 4.14 KB
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
#!/usr/bin/env bash
get_make=$(command -v make)
get_elapsed_time="/usr/bin/time -f"
untar_it="tar -xJvf"
get_it=$(command -v secure_kernel_tarball)
NOTIFY=$(command -v notify-send)
NOCOLOR="\033[0m"
DT=$(date '+%d%m%Y')
build_dir="/home/bhaskar/custom_kernel_$(hostname)_$DT"
if test ! -d "$build_dir";then
mkdir -p "$build_dir"
fi
cd "$build_dir" || exit 1
#vim "/etc/mkinitcpio.d/linux-upstream.preset"
archlinux_kernel_build() {
which_kernel
printf "\n\n"
# Change the kernel name
sh -c "sudo sed -i '4d' /etc/mkinitcpio.d/linux-upstream.preset"
sh -c "sudo sed -i '4i ALL_kver=\"/boot/vmlinuz-linux-upstream-${kernel}-Archlinux\"' /etc/mkinitcpio.d/linux-upstream.preset"
sh -c "sudo sed -i '8d' /etc/mkinitcpio.d/linux-upstream.preset"
sh -c "sudo sed -i '8i default_image=\"/boot/initramfs-linux-upstream.img-${kernel}-Archlinux\"' /etc/mkinitcpio.d/linux-upstream.preset"
eval ${get_it} ${kernel}
#Untar it
$untar_it linux-$kernel.tar.xz
#Get into the kernel direcory
cd linux-$kernel
# Take away the debug package option for faster build
sed -i '8d' scripts/package/PKGBUILD
sed -i '8i _extrapackages=${PACMAN_EXTRAPACKAGES-headers api-headers}' scripts/package/PKGBUILD
sed -i '113,125 s/^/#/' scripts/package/PKGBUILD
# Creating a new checksum, because we have modified the PKGBUILD file
#updpkgsums scripts/package/PKGBUILD
#Clean the dir
$get_make clean && $get_make mrproper
#Copying existing/running kernel config
zcat /proc/config.gz >.config
#Disable this option to shorten the compile time
scripts/config --disable DEBUG_KERNEL
grep DEBUG_KERNEL .config
#Disable this option to shorten the compile time
scripts/config --disable DEBUG_INFO
grep DEBUG_INFO .config
# Enable USB storage module for external HDD
scripts/config --enable USB_STORAGE
# Enable crypto_lz4
scripts/config --enable CRYPTO_LZ4
# Set the local version of the operating system name
scripts/config --set-str LOCALVERSION "-Archlinux"
#Make sure the flags symbols are set correctly with an updated value
#$get_make ARCH=x86_64 olddefconfig
yes '' | make localmodconfig
# Now build it
$get_elapsed_time "\n\n\tTime Elapsed: %E\n\n" $get_make ARCH=x86_64 V=1 -j$(getconf _NPROCESSORS_ONLN) pacman-pkg
if test $? -eq 0
then
$NOTIFY --urgency=critical "Kernel building done"
printf "\nFirst take backup of the existing kernel and initramf to the backups.....\n\n"
sudo sh -c "mv -v "/boot/*-Archlinux" "/home/bhaskar/arch_linux_old_kernels/""
printf "\n Cross checking the latest movement of the kernel and initramfs in backup\n\n"
find "/home/bhaskar/arch_linux_old_kernels/" -type f -ls
printf "\n Check the latest genrated package files.....\n"
find . -maxdepth 1 -name "*.zst" -type f -ls
# printf "\n Signing the packages with my GPG key.....\n"
# sh -c "gpg2 --detach-sign --pinentry-mode loopback --passphrase --passphrase-fd 0 --output *.pkg.tar.zst.sig --sign *.pkg.tar.zst"
printf "\n Now install the generated headers,kernel and doc packages with pacman .. \n\n\n"
find . -name "linux-upstream*" -a ! -name "*.sig" -type f -exec sudo pacman -U --noconfirm {} \;
# sudo pacman -U --noconfirm linux-upstream-${kernel}_Archlinux-1-x86_64.pkg.tar.zst
# sudo pacman -U --noconfirm linux-upstream-headers-${kernel}_Archlinux-1-x86_64.pkg.tar.zst
# sudo pacman -U --noconfirm linux-upstream-api-headers-${kernel}_Archlinux-1-x86_64.pkg.tar.zst
else
echo Something went wrong, manually check.
fi
#$NOTIFY "Kernel update process done"
}
which_kernel() {
printf "\n\n Which kernel would be your base? Stable or Mainline or Longterm? [S/M/L]: %s"
read response
if [[ $response == "S" ]];then
#Get the stable kernel from kernel.org
kernel=$(curl -s https://www.kernel.org/ | grep -A1 'stable:' | grep -oP '(?<=strong>).*(?=</strong.*)' | grep 6.14)
elif [[ $response == "M" ]];then
#Get the mainline kernel from kernel.org
kernel=$(curl -s https://www.kernel.org/ | grep -A1 'mainline:' | grep -oP '(?<=strong>).*(?=</strong.*)')
elif [[ $response == "L" ]];then
#Get the longterm kernel from kernel.org
kernel=$(curl -s https://www.kernel.org/ | grep -A1 'longterm:' | grep -oP '(?<=strong>).*(?=</strong.*)')
fi
}
archlinux_kernel_build