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