diff options
author | Daniel Kirchner | 2020-02-16 00:49:43 +0100 |
---|---|---|
committer | Daniel Kirchner | 2020-02-16 00:49:43 +0100 |
commit | eaced730fda1d8c79457cfa2d4bf8af9f3af94ae (patch) | |
tree | 855c86f52da44665206ab701cfb9e3a06fc7d8a9 | |
download | aur-eaced730fda1d8c79457cfa2d4bf8af9f3af94ae.tar.gz |
Initial commit
-rw-r--r-- | .SRCINFO | 18 | ||||
-rw-r--r-- | PKGBUILD | 26 | ||||
-rwxr-xr-x | build-patched-kernel | 56 | ||||
-rw-r--r-- | build-patched-kernel.hook | 10 | ||||
-rw-r--r-- | patch-kernel-pacman-hook.install | 8 | ||||
-rw-r--r-- | patch-kernel.conf | 14 |
6 files changed, 132 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..d7d7dd97b46b --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,18 @@ +pkgbase = patch-kernel-pacman-hook + pkgdesc = Pacman hook to automatically build the linux package from ABS with additional patches upon updates. + pkgver = 1 + pkgrel = 1 + install = patch-kernel-pacman-hook.install + arch = any + license = MIT + depends = asp + backup = etc/pacman.d/patch-kernel.conf + source = build-patched-kernel + source = build-patched-kernel.hook + source = patch-kernel.conf + sha512sums = e2164f6511c179847aa9fda2372f38c59035ed333c5f0b589bb353756a6dd4abbf951e4b96e0d7d43948c0d323ca2daea968de8f2574a127d29ff6d84a0939a1 + sha512sums = 134eb0cfdaedb4d677a3cc92e5d9fd2f5a63a657ffefd5c217fa662d06b1ba6cb47e29915c2763e34afcefbfeba7e61aa932b7f6258c639ac1ff4b9fd9b17df5 + sha512sums = a8debf2dfac793689eb411cf31833eea9d8f20bd5af493f312f15d02082d77a2f025fa1cef047091cb95aae00f09a999ce4524c8696de10fcdb73678a8379025 + +pkgname = patch-kernel-pacman-hook + diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..418fd26ac543 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,26 @@ +# Maintainer: Daniel Kirchner <daniel@ekpyron.org> + +pkgname=patch-kernel-pacman-hook +pkgver=1 +pkgrel=1 +pkgdesc="Pacman hook to automatically build the linux package from ABS with additional patches upon updates." +arch=("any") +depends=('asp') +license=('MIT') +backup=('etc/pacman.d/patch-kernel.conf') +install="patch-kernel-pacman-hook.install" +source=('build-patched-kernel' + 'build-patched-kernel.hook' + 'patch-kernel.conf') +sha512sums=('e2164f6511c179847aa9fda2372f38c59035ed333c5f0b589bb353756a6dd4abbf951e4b96e0d7d43948c0d323ca2daea968de8f2574a127d29ff6d84a0939a1' + '134eb0cfdaedb4d677a3cc92e5d9fd2f5a63a657ffefd5c217fa662d06b1ba6cb47e29915c2763e34afcefbfeba7e61aa932b7f6258c639ac1ff4b9fd9b17df5' + 'a8debf2dfac793689eb411cf31833eea9d8f20bd5af493f312f15d02082d77a2f025fa1cef047091cb95aae00f09a999ce4524c8696de10fcdb73678a8379025') + +package() { + install -m755 -d "${pkgdir}/usr/share/libalpm/scripts" + install -m755 -d "${pkgdir}/usr/share/libalpm/hooks" + install -m755 -d "${pkgdir}/etc/pacman.d" + install -m755 "${srcdir}/build-patched-kernel" "${pkgdir}/usr/share/libalpm/scripts/build-patched-kernel" + install -m644 "${srcdir}/build-patched-kernel.hook" "${pkgdir}/usr/share/libalpm/hooks/build-patched-kernel.hook" + install -m644 "${srcdir}/patch-kernel.conf" "${pkgdir}/etc/pacman.d/patch-kernel.conf" +} diff --git a/build-patched-kernel b/build-patched-kernel new file mode 100755 index 000000000000..23a39e3daa3f --- /dev/null +++ b/build-patched-kernel @@ -0,0 +1,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/} diff --git a/build-patched-kernel.hook b/build-patched-kernel.hook new file mode 100644 index 000000000000..b09bead70bfe --- /dev/null +++ b/build-patched-kernel.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Install +Operation = Upgrade +Type = Package +Target = linux +[Action] +Description = Patch linux kernel +When = PreTransaction +Exec = /usr/share/libalpm/scripts/build-patched-kernel +AbortOnFail diff --git a/patch-kernel-pacman-hook.install b/patch-kernel-pacman-hook.install new file mode 100644 index 000000000000..97d0105e29eb --- /dev/null +++ b/patch-kernel-pacman-hook.install @@ -0,0 +1,8 @@ +post_install() { + if [ -f "/etc/pacman.d/patch-kernel.conf.pacsave" ]; then + mv -v "/etc/pacman.d/patch-kernel.conf.pacsave" "/etc/pacman.d/patch-kernel.conf" + else + echo "To enable automatic kernel patching you have to customize /etc/pacman.d/patch-kernel.conf." + echo -e "\033[0;33mpatch-kernel-pacman-hook is highly experimental, use at your own risk.\033[0m" + fi +} diff --git a/patch-kernel.conf b/patch-kernel.conf new file mode 100644 index 000000000000..7739c973846e --- /dev/null +++ b/patch-kernel.conf @@ -0,0 +1,14 @@ +# Specify a non-root user used to build the patched kernel. +MAKEPKG_USER="" + +# Specify a directory for building. The hook will use asp to create subdirectory called "linux" for the patched build. +BUILD_DIRECTORY="" + +# A list of paths to kernel patches to apply to the kernel. +KERNEL_PATCHES="" + +# An optional list of arguments to be passed to makepkg. +# MAKEPKG_OPTIONS="--clean --skippgpcheck" + +# The pacman cache dir used to store the created package. Modify this, if you don't use the default. +# PACMAN_CACHE_DIR=/var/cache/pacman/pkg |