apply-patches.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #! /bin/bash
  2. # A little script I whipped up to make it easy to
  3. # patch source trees and have sane error handling
  4. # -Erik
  5. #
  6. # (c) 2002 Erik Andersen <andersen@codepoet.org>
  7. # Set directories from arguments, or use defaults.
  8. targetdir=${1-.}
  9. patchdir=${2-../kernel-patches}
  10. shift 2
  11. patchpattern=${@-*}
  12. if [ ! -d "${targetdir}" ] ; then
  13. echo "Aborting. '${targetdir}' is not a directory."
  14. exit 1
  15. fi
  16. if [ ! -d "${patchdir}" ] ; then
  17. echo "Aborting. '${patchdir}' is not a directory."
  18. exit 1
  19. fi
  20. # Remove any rejects present BEFORE patching - Because if there are
  21. # any, even if patches are well applied, at the end it will complain
  22. # about rejects in targetdir.
  23. find ${targetdir}/ '(' -name '*.rej' -o -name '.*.rej' ')' -print0 | \
  24. xargs -0 -r rm -f
  25. for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do
  26. apply="patch -g0 -p1 -E -d"
  27. uncomp_parm=""
  28. if [ -d "${patchdir}/$i" ] ; then
  29. type="directory overlay"
  30. uncomp="tar cf - --exclude=.svn --no-anchored -C"
  31. uncomp_parm="."
  32. apply="tar xvf - -C"
  33. else case "$i" in
  34. *.gz)
  35. type="gzip"; uncomp="gunzip -dc"; ;;
  36. *.bz)
  37. type="bzip"; uncomp="bunzip -dc"; ;;
  38. *.bz2)
  39. type="bzip2"; uncomp="bunzip2 -dc"; ;;
  40. *.zip)
  41. type="zip"; uncomp="unzip -d"; ;;
  42. *.Z)
  43. type="compress"; uncomp="uncompress -c"; ;;
  44. *.tgz)
  45. type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;;
  46. *.tar)
  47. type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;;
  48. *)
  49. type="plaintext"; uncomp="cat"; ;;
  50. esac fi
  51. echo ""
  52. echo "Applying ${i} using ${type}: "
  53. echo ${i} | cat >> ${targetdir}/.applied_patches_list
  54. ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir}
  55. if [ $? != 0 ] ; then
  56. echo "Patch failed! Please fix $i!"
  57. exit 1
  58. fi
  59. done
  60. # Check for rejects...
  61. if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
  62. echo "Aborting. Reject files found."
  63. exit 1
  64. fi
  65. # Remove backup files
  66. find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;