add_patches.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. usage()
  3. {
  4. echo "Adds patches to a specfile"
  5. echo ""
  6. echo "$0 <patchdir> <specfile>"
  7. echo ""
  8. echo " patchdir - directory containing patches with"
  9. echo " .patch extension."
  10. echo " specfile - the specfile to patch."
  11. exit 1
  12. }
  13. if [ $# -ne 2 ]; then
  14. usage
  15. fi
  16. patchdir=$1
  17. specfile=$2
  18. # Validate our arguments.
  19. if [ ! -d $1 ]; then
  20. echo "Patch directory $1 does not exist or is not a directory."
  21. exit 1
  22. elif [ ! -f $2 ]; then
  23. echo "Specfile $2 does not exist or is not a file."
  24. exit 1
  25. fi
  26. # These keep track of our spec file substitutions.
  27. i=1
  28. prefix="Source0:"
  29. prepprefix="%setup"
  30. # Find all patches in the the patch directory.
  31. # to the spec file.
  32. patches=`ls ${patchdir}/*.patch 2>/dev/null`
  33. # If no patches exist, just exit.
  34. if [ -z "$patches" ]; then
  35. echo "No patches found in $patchdir."
  36. exit 0
  37. fi
  38. # Add the patches to the specfile.
  39. for p in $patches; do
  40. p=`basename $p`
  41. echo "Adding patch to spec file - $p"
  42. sed -i -e "/${prefix}/a Patch${i}: ${p}" -e "/$prepprefix/a %patch${i} -p1" $specfile
  43. prefix="Patch${i}:"
  44. prepprefix="%patch${i}"
  45. i=`expr $i + 1`
  46. done