From 0cb8025eff87228746b138ef6771e1f061634ab5 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Tue, 1 Apr 2014 10:12:59 -0500 Subject: [PATCH 1/2] kpatch-build: add option to build from source RPM --- kpatch-build/kpatch-build | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 33faa63..421233b 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -40,13 +40,8 @@ BASE="$PWD" LOGFILE="/tmp/kpatch-build-$(date +%s).log" SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))" ARCHVERSION="$(uname -r)" -DISTROVERSION="${ARCHVERSION%*.*}" -LOCALVERSION="-${ARCHVERSION##*-}" CPUS="$(grep -c ^processor /proc/cpuinfo)" CACHEDIR="$HOME/.kpatch" -SRCDIR="$CACHEDIR/$ARCHVERSION/src" -OBJDIR="$CACHEDIR/$ARCHVERSION/obj" -OBJDIR2="$CACHEDIR/$ARCHVERSION/obj2" TEMPDIR= STRIPCMD="strip -d --keep-file-symbols" APPLIEDPATCHFILE="applied-patch" @@ -90,12 +85,13 @@ find_dirs() { usage() { echo "usage: $0 [options] " >&2 echo " -h, --help Show this help message" >&2 + echo " -r, --sourcerpm Specify kernel source RPM" >&2 echo " -s, --sourcedir Specify kernel source directory" >&2 echo " -c, --config Specify kernel config file" >&2 echo " -d, --debug Keep scratch files in /tmp" >&2 } -options=$(getopt -o hs:c:d -l "help,sourcedir:,config:,debug" -- "$@") || die "getopt failed" +options=$(getopt -o hr:s:c:d -l "help,sourcerpm:,sourcedir:,config:,debug" -- "$@") || die "getopt failed" eval set -- "$options" @@ -105,6 +101,14 @@ while [[ $# -gt 0 ]]; do usage exit 0 ;; + -r|--sourcerpm) + SRCRPM=$(readlink -f "$2") + shift + [[ ! -f "$SRCRPM" ]] && die "source rpm $SRCRPM not found" + rpmname=$(basename "$SRCRPM") + ARCHVERSION=${rpmname%.src.rpm}.$(uname -m) + ARCHVERSION=${ARCHVERSION#kernel-} + ;; -s|--sourcedir) USERSRCDIR=$(readlink -f "$2") shift @@ -133,6 +137,10 @@ while [[ $# -gt 0 ]]; do shift done +SRCDIR="$CACHEDIR/$ARCHVERSION/src" +OBJDIR="$CACHEDIR/$ARCHVERSION/obj" +OBJDIR2="$CACHEDIR/$ARCHVERSION/obj2" + PATCHNAME="$(basename $PATCHFILE)" if [[ "$PATCHNAME" =~ \.patch ]] || [[ "$PATCHNAME" =~ \.diff ]]; then PATCHNAME="${PATCHNAME%.*}" @@ -169,14 +177,18 @@ if [[ -d "$SRCDIR" ]] || [[ -n "$USERSRCDIR" ]]; then fi else 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 + if [[ -z "$SRCRPM" ]]; then + 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 + SRCRPM="$TEMPDIR/kernel-${ARCHVERSION%*.*}.src.rpm" + fi echo "Unpacking kernel source" rpmdev-setuptree >> "$LOGFILE" 2>&1 || die - rpm -ivh "$TEMPDIR/kernel-$DISTROVERSION.src.rpm" >> "$LOGFILE" 2>&1 || die + rpm -ivh "$SRCRPM" >> "$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 "$CACHEDIR" @@ -184,7 +196,7 @@ else mv "$HOME"/rpmbuild/BUILD/kernel-*/linux-"$ARCHVERSION" "$SRCDIR" >> "$LOGFILE" 2>&1 || die cp "$SRCDIR/.config" "$OBJDIR" || die - echo "$LOCALVERSION" > "$SRCDIR/localversion" || die + echo "-${ARCHVERSION##*-}" > "$SRCDIR/localversion" || die fi echo "Testing patch file" From 9bbea5c60475db3428e9c26f18cb37dae45290e1 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Tue, 1 Apr 2014 11:07:08 -0500 Subject: [PATCH 2/2] kpatch-build: small refactor Split up the USERSRCDIR and SRCDIR code paths for better readability. --- kpatch-build/kpatch-build | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 421233b..9485fb7 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -154,27 +154,27 @@ find_dirs || die "can't find supporting tools" [[ -e "$SYMVERSFILE" ]] || die "can't find core module Module.symvers" -if [[ -d "$SRCDIR" ]] || [[ -n "$USERSRCDIR" ]]; then - if [[ -n "$USERSRCDIR" ]]; then - SRCDIR="$CACHEDIR/src" - OBJDIR="$CACHEDIR/obj" - OBJDIR2="$CACHEDIR/obj2" +if [[ -n "$USERSRCDIR" ]]; then + SRCDIR="$CACHEDIR/src" + OBJDIR="$CACHEDIR/obj" + OBJDIR2="$CACHEDIR/obj2" - rm -rf "$CACHEDIR" - mkdir -p "$CACHEDIR" - mkdir -p "$OBJDIR" "$OBJDIR2" + rm -rf "$CACHEDIR" + mkdir -p "$CACHEDIR" + mkdir -p "$OBJDIR" "$OBJDIR2" - if [[ -n "$CONFIGFILE" ]]; then - cp "$CONFIGFILE" "$OBJDIR/.config" || die "config file is missing" - else - cp "$USERSRCDIR/.config" "$OBJDIR" || die "source dir is missing a .config file" - fi - - echo "Copying source to $SRCDIR" - cp -a "$USERSRCDIR" "$SRCDIR" || die "copy failed" + if [[ -n "$CONFIGFILE" ]]; then + cp "$CONFIGFILE" "$OBJDIR/.config" || die "config file is missing" else - echo "Using cache at $SRCDIR" + cp "$USERSRCDIR/.config" "$OBJDIR" || die "source dir is missing a .config file" fi + + echo "Copying source to $SRCDIR" + cp -a "$USERSRCDIR" "$SRCDIR" || die "copy failed" + +elif [[ -d "$SRCDIR" ]]; then + echo "Using cache at $SRCDIR" + else rpm -q --quiet rpmdevtools || die "rpmdevtools not installed"