Skip to content

Commit

Permalink
kpatch-build: clean up rpmbuild tmp directory handling
Browse files Browse the repository at this point in the history
Setting HOME in a subshell is too hacky.  Instead just pass the rpmbuild
directory to the rpm and rpmbuild commands.
  • Loading branch information
jpoimboe committed Nov 3, 2015
1 parent b2eeb59 commit 0dec513
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions kpatch-build/kpatch-build
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CPUS="$(getconf _NPROCESSORS_ONLN)"
CACHEDIR="${CACHEDIR:-$HOME/.kpatch}"
SRCDIR="$CACHEDIR/src"
OBJDIR="$CACHEDIR/obj"
TMPSRCDIR="$CACHEDIR/tmphome"
TMPBUILDROOT="$CACHEDIR/buildroot"
VERSIONFILE="$CACHEDIR/version"
TEMPDIR="$CACHEDIR/tmp"
LOGFILE="$CACHEDIR/build.log"
Expand Down Expand Up @@ -82,7 +82,7 @@ cleanup() {
[[ -e $TEMPDIR/.config ]] && cp -f $TEMPDIR/.config $USERSRCDIR
fi
[[ "$DEBUG" -eq 0 ]] && rm -rf "$TEMPDIR"
rm -rf "$TMPSRCDIR"
rm -rf "$TMPBUILDROOT"
unset KCFLAGS
}

Expand Down Expand Up @@ -370,26 +370,15 @@ else
fi

echo "Unpacking kernel source"
(
clean_cache

# By default, rpmdev-setuptree and rpmbuild use
# ~/rpmbuild/ tree. However, this could clobber its
# existing contents, so let us use a fake home directory
# here to avoid that.
mkdir -p $TMPSRCDIR
HOME=$TMPSRCDIR

rpmdev-setuptree >> "$LOGFILE" 2>&1 || die
rpm -ivh "$SRCRPM" >> "$LOGFILE" 2>&1 || die
rpmbuild -bp "--target=$(uname -m)" "$(rpm --eval %{_specdir})"/kernel.spec >> "$LOGFILE" 2>&1 ||
die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."

RPM_BUILD_DIR=$(rpm --eval %{_builddir})
mv "$RPM_BUILD_DIR"/kernel-*/linux-"${ARCHVERSION%.*}"*"${ARCHVERSION##*.}" "$SRCDIR" >> "$LOGFILE" 2>&1 || die

rm -rf "$TMPSRCDIR"
)

clean_cache

rpm -D "_topdir $TMPBUILDROOT" -ivh "$SRCRPM" >> "$LOGFILE" 2>&1 || die
rpmbuild -D "_topdir $TMPBUILDROOT" -bp "--target=$(uname -m)" "$TMPBUILDROOT"/SPECS/kernel.spec >> "$LOGFILE" 2>&1 ||
die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."

mv "$TMPBUILDROOT"/BUILD/kernel-*/linux-"${ARCHVERSION%.*}"*"${ARCHVERSION##*.}" "$SRCDIR" >> "$LOGFILE" 2>&1 || die
rm -rf "$TMPBUILDROOT"

cp "$SRCDIR/.config" "$OBJDIR" || die
if [[ "$ARCHVERSION" == *-* ]]; then
Expand Down

0 comments on commit 0dec513

Please sign in to comment.