forked from freedomofpress/kernel-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-kernel.sh
executable file
·70 lines (58 loc) · 1.94 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
66
67
68
69
70
#!/bin/bash
set -e
set -u
set -o pipefail
# Patching with grsecurity is disabled by default.
# Can be renabled vai env var or cli flag.
GRSECURITY="${GRSECURITY:-}"
if [[ $# > 0 ]]; then
x="$1"
shift
if [[ "$x" = "--grsecurity" ]]; then
GRSECURITY=1
else
echo "Usage: $0 [--grsecurity]"
exit 1
fi
fi
if [[ -n "$GRSECURITY" ]]; then
LINUX_VERSION="$(/usr/local/bin/grsecurity-urls.py --print-version)"
echo "Will include grsecurity patch for kernel $LINUX_VERSION"
/usr/local/bin/grsecurity-urls.py > /patches/grsec
else
echo "Skipping grsecurity patch set"
fi
LINUX_VERSION="${LINUX_VERSION:-}"
if [[ -z "$LINUX_VERSION" ]]; then
LINUX_VERSION="$(curl -s https://www.kernel.org/ | grep -m1 -F stable: -A1 | tail -n1 | grep -oP '[\d\.]+')"
fi
LINUX_MAJOR_VERSION="$(cut -d. -f1 <<< "$LINUX_VERSION")"
# If there's no output directory, then deb packages will be
# lost in the ephemeral container.
if [[ ! -d /output ]]; then
echo "WARNING: Output directory /output not found" >&2
echo "WARNING: to save packages, you must mount /output as a volume" >&2
exit 1
fi
echo "Fetching Linux kernel source $LINUX_VERSION"
wget https://cdn.kernel.org/pub/linux/kernel/v${LINUX_MAJOR_VERSION}.x/linux-${LINUX_VERSION}.tar.xz
echo "Extracting Linux kernel source $LINUX_VERSION"
xz -d -v linux-${LINUX_VERSION}.tar.xz
tar -xf linux-${LINUX_VERSION}.tar
cd linux-${LINUX_VERSION}
if [[ -e /config ]]; then
echo "Copying custom config for kernel source $LINUX_VERSION"
cp /config .config
fi
if [[ -d /patches ]]; then
echo "Applying custom patches for kernel source $LINUX_VERSION"
find /patches -maxdepth 1 -type f -exec patch -p 1 -i {} \;
fi
echo "Building Linux kernel source $LINUX_VERSION"
make olddefconfig
VCPUS="$(nproc)"
make -j $VCPUS deb-pkg
echo "Storing build artifacts for $LINUX_VERSION"
if [[ -d /output ]]; then
rsync -a --info=progress2 ../*.deb ../*.tar.gz /output/
fi