a7e38b
#!/bin/bash -
a7e38b
a7e38b
set -e
a7e38b
a7e38b
# Maintainer script to copy patches from the git repo to the current
a7e38b
# directory.  It's normally only used downstream (ie. in RHEL).  Use
a7e38b
# it like this:
a7e38b
#   ./copy-patches.sh
a7e38b
a7e38b
project=libguestfs
a7e38b
rhel_version=9.0.0
a7e38b
a7e38b
# Check we're in the right directory.
a7e38b
if [ ! -f $project.spec ]; then
a7e38b
    echo "$0: run this from the directory containing '$project.spec'"
a7e38b
    exit 1
a7e38b
fi
a7e38b
a7e38b
case `id -un` in
a7e38b
    rjones) git_checkout=$HOME/d/$project-rhel-$rhel_version ;;
a7e38b
    lacos)  git_checkout=$HOME/src/v2v/$project ;;
a7e38b
    *)      git_checkout=$HOME/d/$project-rhel-$rhel_version ;;
a7e38b
esac
a7e38b
if [ ! -d $git_checkout ]; then
a7e38b
    echo "$0: $git_checkout does not exist"
a7e38b
    echo "This script is only for use by the maintainer when preparing a"
a7e38b
    echo "$project release on RHEL."
a7e38b
    exit 1
a7e38b
fi
a7e38b
a7e38b
# Get the base version of the project.
a7e38b
version=`grep '^Version:' $project.spec | awk '{print $2}'`
a7e38b
tag="v$version"
a7e38b
a7e38b
# Remove any existing patches.
a7e38b
git rm -f [0-9]*.patch ||:
a7e38b
rm -f [0-9]*.patch
a7e38b
a7e38b
# Get the patches.
a7e38b
(cd $git_checkout; rm -f [0-9]*.patch; git -c core.abbrev=9 format-patch -O/dev/null -N --submodule=diff $tag)
a7e38b
mv $git_checkout/[0-9]*.patch .
a7e38b
a7e38b
# Remove any not to be applied.
a7e38b
rm -f *NOT-FOR-RPM*.patch
a7e38b
a7e38b
# Add the patches.
a7e38b
git add [0-9]*.patch
a7e38b
a7e38b
# Print out the patch lines.
a7e38b
echo
a7e38b
echo "--- Copy the following text into $project.spec file"
a7e38b
echo
a7e38b
a7e38b
echo "# Patches."
a7e38b
for f in [0-9]*.patch; do
a7e38b
    n=`echo $f | awk -F- '{print $1}'`
a7e38b
    echo "Patch$n:     $f"
a7e38b
done
a7e38b
a7e38b
echo
a7e38b
echo "--- End of text"