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