From 6176353f8d24a79d6fbaf2d89dd7dcd946465870 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Fri, 12 Sep 2014 10:45:41 -0500 Subject: [PATCH 1/3] kpatch-build: add KVER and KREL variables Add KVER and KREL variables, and use them where appropriate. Also remove the setting of ARCHVERSION in the '-s' case, since it's not actually used anywhere in that case. --- kpatch-build/kpatch-build | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 6784572..debac52 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -238,6 +238,12 @@ done TEMPDIR="$(mktemp -d /tmp/kpatch-build-XXXXXX)" || die "mktemp failed" trap cleanup EXIT INT TERM +KVER=${ARCHVERSION%%-*} +if [[ $ARCHVERSION =~ - ]]; then + KREL=${ARCHVERSION##*-} + KREL=${KREL%.*} +fi + if [[ -n $USERSRCDIR ]]; then # save .config and vmlinux since they'll get removed with mrproper so # we can restore them later and be able to run kpatch-build multiple @@ -298,12 +304,6 @@ if [[ -n "$USERSRCDIR" ]]; then cp -f "$CONFIGFILE" "$OBJDIR/.config" - echo "Detecting kernel version" - cd "$SRCDIR" - make mrproper >> "$LOGFILE" 2>&1 || die "make mrproper failed" - make O="$OBJDIR" prepare >> "$LOGFILE" 2>&1 || die "make prepare failed" - ARCHVERSION=$(make O="$OBJDIR" kernelrelease) || die "make kernelrelease failed" - elif [[ -e "$SRCDIR" ]] && [[ -e "$VERSIONFILE" ]] && [[ $(cat "$VERSIONFILE") = $ARCHVERSION ]]; then echo "Using cache at $SRCDIR" @@ -318,7 +318,7 @@ else echo "Downloading kernel source for $ARCHVERSION" yumdownloader --source --destdir "$TEMPDIR" "kernel-$ARCHVERSION" >> "$LOGFILE" 2>&1 || die - SRCRPM="$TEMPDIR/kernel-${ARCHVERSION%*.*}.src.rpm" + SRCRPM="$TEMPDIR/kernel-$KVER-$KREL.src.rpm" fi echo "Unpacking kernel source" @@ -362,7 +362,7 @@ else # The linux-source packages are formatted like the following for: # ubuntu: linux-source-3.13.0_3.13.0-24.46_all.deb # debian: linux-source-3.14_3.14.7-1_all.deb - pkgver="${ARCHVERSION%%-*}_$(dpkg-query -W -f='${Version}' linux-image-$(uname -r))" + pkgver="$KVER_$(dpkg-query -W -f='${Version}' linux-image-$ARCHVERSION)" pkgname="linux-source-${pkgver}_all" cd $TEMPDIR @@ -373,9 +373,9 @@ else echo "Unpacking kernel source" dpkg -x ${pkgname}.deb $TEMPDIR >> "$LOGFILE" || die "dpkg: Could not extract ${pkgname}.deb" # extract and move to SRCDIR - tar $taroptions usr/src/linux-source-${ARCHVERSION%%-*}.tar.${extension} >> "$LOGFILE" || die "tar: Failed to extract kernel source package" + tar $taroptions usr/src/linux-source-$KVER.tar.${extension} >> "$LOGFILE" || die "tar: Failed to extract kernel source package" clean_cache - mv linux-source-${ARCHVERSION%%-*} "$SRCDIR" || die + mv linux-source-$KVER "$SRCDIR" || die cp "/boot/config-${ARCHVERSION}" "$OBJDIR/.config" || die if [[ "$ARCHVERSION" == *-* ]]; then echo "-${ARCHVERSION#*-}" > "$SRCDIR/localversion" || die From 74316588e8c55a0e816cbb5a7da1b3087a7fc3c6 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Fri, 12 Sep 2014 10:47:36 -0500 Subject: [PATCH 2/3] kpatch-build: download fedora src rpms from koji yumdownloader is problematic because it doesn't allow you to download anything but the latest released kernel. It can also be slow at times. Instead, for Fedora, download the RPMs from koji. --- README.md | 2 +- kpatch-build/kpatch-build | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e5249aa..b9b03e5 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ sudo yum install gcc kernel-devel elfutils elfutils-devel Install the dependencies for the "kpatch-build" command: ```bash -sudo yum install rpmdevtools pesign yum-utils openssl +sudo yum install rpmdevtools pesign yum-utils openssl wget sudo yum-builddep kernel sudo debuginfo-install kernel diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index debac52..3a29a05 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -313,13 +313,16 @@ else echo "Fedora/Red Hat distribution detected" rpm -q --quiet rpmdevtools || die "rpmdevtools not installed" + echo "Downloading kernel source for $ARCHVERSION" 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-$KVER-$KREL.src.rpm" + if [[ $DISTRO = fedora ]]; then + (cd $TEMPDIR && wget http://kojipkgs.fedoraproject.org/packages/kernel/$KVER/$KREL/src/kernel-$KVER-$KREL.src.rpm >> "$LOGFILE" 2>&1 || die) + else + rpm -q --quiet yum-utils || die "yum-utils not installed" + yumdownloader --source --destdir "$TEMPDIR" "kernel-$ARCHVERSION" >> "$LOGFILE" 2>&1 || die + fi fi + SRCRPM="$TEMPDIR/kernel-$KVER-$KREL.src.rpm" echo "Unpacking kernel source" rpmdev-setuptree >> "$LOGFILE" 2>&1 || die From d254d3d0f239f54e3b9af27b832c0435c529c00b Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Sun, 14 Sep 2014 22:23:26 -0500 Subject: [PATCH 3/3] fix review comments Use the wget -P option. --- kpatch-build/kpatch-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 3a29a05..01d44b6 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -316,7 +316,7 @@ else echo "Downloading kernel source for $ARCHVERSION" if [[ -z "$SRCRPM" ]]; then if [[ $DISTRO = fedora ]]; then - (cd $TEMPDIR && wget http://kojipkgs.fedoraproject.org/packages/kernel/$KVER/$KREL/src/kernel-$KVER-$KREL.src.rpm >> "$LOGFILE" 2>&1 || die) + wget -P $TEMPDIR http://kojipkgs.fedoraproject.org/packages/kernel/$KVER/$KREL/src/kernel-$KVER-$KREL.src.rpm >> "$LOGFILE" 2>&1 || die else rpm -q --quiet yum-utils || die "yum-utils not installed" yumdownloader --source --destdir "$TEMPDIR" "kernel-$ARCHVERSION" >> "$LOGFILE" 2>&1 || die