-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-kernel.sh
executable file
·65 lines (57 loc) · 1.4 KB
/
build-kernel.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
#!/bin/bash
set -eu
LATEST=${LATEST:-$(curl -sL https://www.kernel.org/finger_banner | awk '/^The latest stable / { print $NF }')}
MAJOR_MINOR="$(echo ${LATEST} | awk -v FS=. '{ printf "%d.%d", $1, $2 }')"
BASEURL=${BASEURL:-"https://cdn.kernel.org/pub/linux/kernel/"}
WORKDIR=/usr/src
KERNEL_DIR=${WORKDIR}/linux-${LATEST}
PKG_BUILD=${PKG_BUILD:-1}
PKG_NAME=${PKG_NAME:-kvm}
PKG_ARCH=${PKG_ARCH:-amd64}
PKG_REVISION=${PKG_REVISION:-1.0}
function _get_kernel_source() {
ARCFILE=${WORKDIR}/linux-${LATEST}.tar.xz
curl "${BASEURL}/${URL_PATH}/linux-${LATEST}.tar.xz" -o "${ARCFILE}"
tar -xJf "${ARCFILE}" -C "${WORKDIR}"
}
function setup() {
_get_kernel_source
cp -v "${WORKDIR}/config-${MAJOR_MINOR}" "${KERNEL_DIR}/.config"
cd "${KERNEL_DIR}"
make olddefconfig
}
function _exec_make_kpkg() {
time make-kpkg --append-to-version "-${PKG_BUILD}-${PKG_NAME}-${PKG_ARCH}" --revision "${PKG_REVISION}" \
--initrd --rootcmd fakeroot --jobs "$(nproc)" $@
}
function build() {
setup
cd "${KERNEL_DIR}"
_exec_make_kpkg kernel_image modules_image
_exec_make_kpkg kernel_headers
}
case "${LATEST}" in
*rc*)
KERNEL_VERSION=${LATEST}
URL_PATH=v4.x/testing
;;
4.[0-9]*.[0-9]*)
KERNEL_VERSION=${LATEST}
URL_PATH=v4.x
;;
4.[0-9]*)
KERNEL_VERSION=${LATEST}.0
URL_PATH=v4.x
;;
*)
echo >&2 "${LATEST} is unsupported kernel version."
exit 4
;;
esac
case "${1}" in
build)
build
;;
*)
exit 3
esac