summarylogtreecommitdiffstats
path: root/build-patched-kernel
blob: 23a39e3daa3ff847e1ead009ab7b509e75a6ae28 (plain)
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
#!/bin/bash -e

CONFIG=/etc/pacman.d/patch-kernel.conf

source "${CONFIG}"

if [ "${KERNEL_PATCHES}" == "" ]; then
	# Nothing to do.
	exit 0
fi

if [ "${MAKEPKG_USER}" == "" ]; then
	echo "You need to specify a non-root user to build the patched kernel in ${CONFIG}."
	exit 1
fi

if [ "${BUILD_DIRECTORY}" == "" ]; then
	echo "You need to specify a build directory for building the patched kernel in ${CONFIG}."
	exit 1
fi

if [ "$EUID" -ne 0 ]; then
	echo "This script is expected to be run as pacman hook as root user."
fi


CONFIG="${CONFIG}" su -s /bin/bash -w CONFIG - "${MAKEPKG_USER}" -c '
set -e
source "${CONFIG}"

cd "${BUILD_DIRECTORY}"

asp update linux &> /dev/null
asp -f export core/linux &> /dev/null
cd linux

for patch in ${KERNEL_PATCHES}; do
sed -i -e "/source=(/a\\" -e "\"${patch}\"" PKGBUILD
sed -i -e "s/sha256sums=(/sha256sums=(\"SKIP\" /" PKGBUILD
done

echo "Building patched kernel. This may take a while. Logs will be written to \"${MAKEPKG_LOG:-/tmp/makepkg_linux.log}\"."
if ! PKGEXT=".pkg.tar.zst" makepkg ${MAKEPKG_OPTIONS} &> "${MAKEPKG_LOG:-/tmp/makepkg_linux.log}"; then
	echo "Failed to build patched kernel. Aborting."
	exit 1
fi

echo "Build successful. Applied patches according to makepkg log:"
grep -oP "Applying patch \K.*(?=\.\.\.)" "${MAKEPKG_LOG:-/tmp/makepkg_linux.log}"

'

echo "Overwriting pacman cache:"

source "${BUILD_DIRECTORY}"/linux/PKGBUILD
cp -v "${BUILD_DIRECTORY}"/linux/linux-${pkgver}-${pkgrel}-x86_64.pkg.tar.zst ${PACMAN_CACHE_DIR:-/var/cache/pacman/pkg/}