mirror of https://github.com/dynup/kpatch
Merge pull request #105 from jpoimboe/kpatch-build-srpm
kpatch-build: add option to build from source RPM
This commit is contained in:
commit
21586035d7
|
@ -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,37 +154,41 @@ 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"
|
OBJDIR2="$CACHEDIR/obj2"
|
||||||
OBJDIR2="$CACHEDIR/obj2"
|
|
||||||
|
|
||||||
rm -rf "$CACHEDIR"
|
rm -rf "$CACHEDIR"
|
||||||
mkdir -p "$CACHEDIR"
|
mkdir -p "$CACHEDIR"
|
||||||
mkdir -p "$OBJDIR" "$OBJDIR2"
|
mkdir -p "$OBJDIR" "$OBJDIR2"
|
||||||
|
|
||||||
if [[ -n "$CONFIGFILE" ]]; then
|
if [[ -n "$CONFIGFILE" ]]; then
|
||||||
cp "$CONFIGFILE" "$OBJDIR/.config" || die "config file is missing"
|
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"
|
|
||||||
else
|
else
|
||||||
echo "Using cache at $SRCDIR"
|
cp "$USERSRCDIR/.config" "$OBJDIR" || die "source dir is missing a .config file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Copying source to $SRCDIR"
|
||||||
|
cp -a "$USERSRCDIR" "$SRCDIR" || die "copy failed"
|
||||||
|
|
||||||
|
elif [[ -d "$SRCDIR" ]]; then
|
||||||
|
echo "Using cache at $SRCDIR"
|
||||||
|
|
||||||
else
|
else
|
||||||
rpm -q --quiet rpmdevtools || die "rpmdevtools not installed"
|
rpm -q --quiet rpmdevtools || die "rpmdevtools not installed"
|
||||||
rpm -q --quiet yum-utils || die "yum-utils not installed"
|
|
||||||
|
|
||||||
echo "Downloading kernel source for $ARCHVERSION"
|
if [[ -z "$SRCRPM" ]]; then
|
||||||
yumdownloader --source --destdir "$TEMPDIR" "kernel-$ARCHVERSION" >> "$LOGFILE" 2>&1 || die
|
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"
|
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"
|
||||||
|
|
Loading…
Reference in New Issue