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