022f11
#!/bin/bash -
022f11
022f11
set -e
022f11
022f11
# Maintainer script to copy patches from the git repo to the current
022f11
# directory.  Use it like this:
022f11
#   ./copy-patches.sh
022f11
022f11
# Check we're in the right directory.
022f11
if [ ! -f libguestfs.spec ]; then
022f11
    echo "$0: run this from the directory containing 'libguestfs.spec'"
022f11
    exit 1
022f11
fi
022f11
022f11
git_checkout=$HOME/d/libguestfs-rhel-7.0
022f11
if [ ! -d $git_checkout ]; then
022f11
    echo "$0: $git_checkout does not exist"
022f11
    echo "This script is only for use by the maintainer when preparing a"
022f11
    echo "libguestfs release on RHEL."
022f11
    exit 1
022f11
fi
022f11
022f11
# Get the base version of libguestfs.
022f11
version=`grep '^Version:' libguestfs.spec | awk '{print $2}'`
022f11
022f11
# Remove any existing patches.
022f11
git rm -f [0-9]*.patch ||:
022f11
rm -f [0-9]*.patch
022f11
022f11
# Get the patches.
022f11
(cd $git_checkout; rm -f [0-9]*.patch; git format-patch -N $version)
022f11
mv $git_checkout/[0-9]*.patch .
022f11
022f11
# Remove any not to be applied.
022f11
rm -f *NOT-FOR-RPM*.patch
022f11
022f11
# Add the patches.
022f11
git add [0-9]*.patch
022f11
022f11
# Print out the patch lines.
022f11
echo
022f11
echo "--- Copy the following text into libguestfs.spec file"
022f11
echo
022f11
022f11
rhel_7_flag=no
022f11
echo "# Feature and backport patches."
022f11
for f in [0-9]*.patch; do
022f11
    n=`echo $f | awk -F- '{print $1}'`
022f11
    is_rhel_7=no
022f11
    if [ "$(echo $f | awk -F- '{print $2 $3}')" = "RHEL7" ]; then
022f11
	is_rhel_7=yes
022f11
    fi
022f11
    if [ "$rhel_7_flag" = "no" -a "$is_rhel_7" = "yes" ]; then
022f11
	echo
022f11
	echo "# RHEL 7 specific patches."
022f11
	rhel_7_flag=yes
022f11
    elif [ "$rhel_7_flag" = "yes" -a "$is_rhel_7" = "no" ]; then
022f11
	echo "$0: error: patch out of order near $f"
022f11
	exit 1
022f11
    fi
022f11
    echo "Patch$n:     $f"
022f11
done
022f11
022f11
echo
022f11
echo "--- End of text"