Merge pull request #105 from jpoimboe/kpatch-build-srpm

kpatch-build: add option to build from source RPM
This commit is contained in:
Seth Jennings 2014-04-07 10:36:10 -05:00
commit 21586035d7
1 changed files with 40 additions and 28 deletions

View File

@ -40,13 +40,8 @@ BASE="$PWD"
LOGFILE="/tmp/kpatch-build-$(date +%s).log" LOGFILE="/tmp/kpatch-build-$(date +%s).log"
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))" SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
ARCHVERSION="$(uname -r)" ARCHVERSION="$(uname -r)"
DISTROVERSION="${ARCHVERSION%*.*}"
LOCALVERSION="-${ARCHVERSION##*-}"
CPUS="$(grep -c ^processor /proc/cpuinfo)" CPUS="$(grep -c ^processor /proc/cpuinfo)"
CACHEDIR="$HOME/.kpatch" CACHEDIR="$HOME/.kpatch"
SRCDIR="$CACHEDIR/$ARCHVERSION/src"
OBJDIR="$CACHEDIR/$ARCHVERSION/obj"
OBJDIR2="$CACHEDIR/$ARCHVERSION/obj2"
TEMPDIR= TEMPDIR=
STRIPCMD="strip -d --keep-file-symbols" STRIPCMD="strip -d --keep-file-symbols"
APPLIEDPATCHFILE="applied-patch" APPLIEDPATCHFILE="applied-patch"
@ -90,12 +85,13 @@ find_dirs() {
usage() { usage() {
echo "usage: $0 [options] <patch file>" >&2 echo "usage: $0 [options] <patch file>" >&2
echo " -h, --help Show this help message" >&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 " -s, --sourcedir Specify kernel source directory" >&2
echo " -c, --config Specify kernel config file" >&2 echo " -c, --config Specify kernel config file" >&2
echo " -d, --debug Keep scratch files in /tmp" >&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" eval set -- "$options"
@ -105,6 +101,14 @@ while [[ $# -gt 0 ]]; do
usage usage
exit 0 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) -s|--sourcedir)
USERSRCDIR=$(readlink -f "$2") USERSRCDIR=$(readlink -f "$2")
shift shift
@ -133,6 +137,10 @@ while [[ $# -gt 0 ]]; do
shift shift
done done
SRCDIR="$CACHEDIR/$ARCHVERSION/src"
OBJDIR="$CACHEDIR/$ARCHVERSION/obj"
OBJDIR2="$CACHEDIR/$ARCHVERSION/obj2"
PATCHNAME="$(basename $PATCHFILE)" PATCHNAME="$(basename $PATCHFILE)"
if [[ "$PATCHNAME" =~ \.patch ]] || [[ "$PATCHNAME" =~ \.diff ]]; then if [[ "$PATCHNAME" =~ \.patch ]] || [[ "$PATCHNAME" =~ \.diff ]]; then
PATCHNAME="${PATCHNAME%.*}" PATCHNAME="${PATCHNAME%.*}"
@ -146,7 +154,6 @@ find_dirs || die "can't find supporting tools"
[[ -e "$SYMVERSFILE" ]] || die "can't find core module Module.symvers" [[ -e "$SYMVERSFILE" ]] || die "can't find core module Module.symvers"
if [[ -d "$SRCDIR" ]] || [[ -n "$USERSRCDIR" ]]; then
if [[ -n "$USERSRCDIR" ]]; then if [[ -n "$USERSRCDIR" ]]; then
SRCDIR="$CACHEDIR/src" SRCDIR="$CACHEDIR/src"
OBJDIR="$CACHEDIR/obj" OBJDIR="$CACHEDIR/obj"
@ -164,19 +171,24 @@ if [[ -d "$SRCDIR" ]] || [[ -n "$USERSRCDIR" ]]; then
echo "Copying source to $SRCDIR" echo "Copying source to $SRCDIR"
cp -a "$USERSRCDIR" "$SRCDIR" || die "copy failed" cp -a "$USERSRCDIR" "$SRCDIR" || die "copy failed"
else
elif [[ -d "$SRCDIR" ]]; then
echo "Using cache at $SRCDIR" echo "Using cache at $SRCDIR"
fi
else else
rpm -q --quiet rpmdevtools || die "rpmdevtools not installed" rpm -q --quiet rpmdevtools || die "rpmdevtools not installed"
if [[ -z "$SRCRPM" ]]; then
rpm -q --quiet yum-utils || die "yum-utils not installed" rpm -q --quiet yum-utils || die "yum-utils not installed"
echo "Downloading kernel source for $ARCHVERSION" echo "Downloading kernel source for $ARCHVERSION"
yumdownloader --source --destdir "$TEMPDIR" "kernel-$ARCHVERSION" >> "$LOGFILE" 2>&1 || die yumdownloader --source --destdir "$TEMPDIR" "kernel-$ARCHVERSION" >> "$LOGFILE" 2>&1 || die
SRCRPM="$TEMPDIR/kernel-${ARCHVERSION%*.*}.src.rpm"
fi
echo "Unpacking kernel source" echo "Unpacking kernel source"
rpmdev-setuptree >> "$LOGFILE" 2>&1 || die 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 || 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." die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
rm -rf "$CACHEDIR" rm -rf "$CACHEDIR"
@ -184,7 +196,7 @@ else
mv "$HOME"/rpmbuild/BUILD/kernel-*/linux-"$ARCHVERSION" "$SRCDIR" >> "$LOGFILE" 2>&1 || die mv "$HOME"/rpmbuild/BUILD/kernel-*/linux-"$ARCHVERSION" "$SRCDIR" >> "$LOGFILE" 2>&1 || die
cp "$SRCDIR/.config" "$OBJDIR" || die cp "$SRCDIR/.config" "$OBJDIR" || die
echo "$LOCALVERSION" > "$SRCDIR/localversion" || die echo "-${ARCHVERSION##*-}" > "$SRCDIR/localversion" || die
fi fi
echo "Testing patch file" echo "Testing patch file"