kpatch-build: allow building as non-root

Allowing the user to build without needing to be root.  If the needed
packages aren't installed, the error messages will tell the user what to
install.
This commit is contained in:
Josh Poimboeuf 2014-02-14 14:47:11 -06:00
parent 4c74203366
commit af17774865
2 changed files with 16 additions and 18 deletions

4
README
View File

@ -27,10 +27,10 @@ NOTE: While kpatch is designed to work with any recent Linux
kernel on any distribution, the "kpatch build" command currently
only works on Fedora.
First make a patch against the kernel tree, e.g. foo.patch.
First, use diff to make a source patch against the kernel tree, e.g. foo.patch.
Then:
sudo /usr/local/sbin/kpatch build foo.patch
kpatch build foo.patch
sudo insmod kpatch.ko kpatch-foo.ko
Voila, your kernel is patched.

View File

@ -1,21 +1,17 @@
#!/bin/bash
# kpatch build script for Fedora
# kpatch build script
# This script takes a patch based on the version of the kernel
# currently running and creates a kernel module that will
# replace modified functions in the kernel such that the
# patched code takes effect.
# This script contains Fedora specific nuances and will probably
# not work on other distributions; however, it does serve as a tutorial
# on the various steps involved and should be adaptable to other
# distributions.
# This script currently only works on Fedora and will need to be adapted to
# work on other distros.
# This script:
# - Installs the required yum/rpm tools
# - Downloads the kernel src rpm for the currently running kernel
# - Installs the build dependencies for the src rpm
# - Unpacks and prepares the src rpm for building
# - Builds the base kernel (vmlinux)
# - Builds the patched kernel and monitors changed objects
@ -40,7 +36,11 @@ cleanup() {
}
die() {
echo "ERROR: kpatch build failed. Check kpatch-build.log for more details." >&2
if [[ -z $1 ]]; then
echo "ERROR: kpatch build failed. Check kpatch-build.log for more details." >&2
else
echo "ERROR: $1" >&2
fi
exit 1
}
@ -74,7 +74,7 @@ fi
cleanup
TEMPDIR="$(mktemp -d)" || die
TEMPDIR="$(mktemp -d)" || die "mktemp failed"
if [[ -f "$KSRCDIR_CACHE" ]]; then
echo "Using cache at $KSRCDIR_CACHE"
@ -82,19 +82,17 @@ if [[ -f "$KSRCDIR_CACHE" ]]; then
tar xzf "$KSRCDIR_CACHE" -C "$KSRCDIR_DIR" >> "$LOGFILE" 2>&1 || die
cd "$KSRCDIR" || die
else
echo "Verifying required development tools"
yum install rpmdevtools yum-utils >> "$LOGFILE" 2>&1 || die
rpm -q --quiet rpmdevtools || die "rpmdevtools not installed"
rpm -q --quiet yum-utils || die "yum-utils not installed"
echo "Downloading kernel source for $ARCHVERSION"
yumdownloader --source --destdir "$TEMPDIR" "kernel-$ARCHVERSION" >> "$LOGFILE" 2>&1 || die
echo "Verifying build dependencies for kernel package"
yum-builddep "$TEMPDIR/kernel-$DISTROVERSION.src.rpm" >> "$LOGFILE" 2>&1 || die
echo "Unpacking kernel source"
rpmdev-setuptree >> "$LOGFILE" 2>&1 || die
rpm -Uvh "$TEMPDIR/kernel-$DISTROVERSION.src.rpm" >> "$LOGFILE" 2>&1 || die
rpmbuild -bp "--target=$(uname -m)" "$HOME/rpmbuild/SPECS/kernel.spec" >> "$LOGFILE" 2>&1 || die
rpm -ivh "$TEMPDIR/kernel-$DISTROVERSION.src.rpm" >> "$LOGFILE" 2>&1 || die
rpmbuild -bp "--target=$(uname -m)" "$HOME/rpmbuild/SPECS/kernel.spec" >> "$LOGFILE" 2>&1 ||
die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
rm -rf "$KSRCDIR"
mkdir -p "$KSRCDIR_DIR"
mv "$HOME"/rpmbuild/BUILD/kernel-*/linux-"$ARCHVERSION" "$KSRCDIR" >> "$LOGFILE" 2>&1 || die