apply-patches.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. for i in `cd ${patchdir}; ls -d ${patchpattern} 2> /dev/null` ; do
  21. apply="patch -g0 -p1 -E -d"
  22. uncomp_parm=""
  23. if [ -d "${patchdir}/$i" ] ; then
  24. type="directory overlay"
  25. uncomp="tar cf - --exclude=.svn --no-anchored -C"
  26. uncomp_parm="."
  27. apply="tar xvf - -C"
  28. else case "$i" in
  29. *.gz)
  30. type="gzip"; uncomp="gunzip -dc"; ;;
  31. *.bz)
  32. type="bzip"; uncomp="bunzip -dc"; ;;
  33. *.bz2)
  34. type="bzip2"; uncomp="bunzip2 -dc"; ;;
  35. *.zip)
  36. type="zip"; uncomp="unzip -d"; ;;
  37. *.Z)
  38. type="compress"; uncomp="uncompress -c"; ;;
  39. *.tgz)
  40. type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;;
  41. *.tar)
  42. type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;;
  43. *)
  44. type="plaintext"; uncomp="cat"; ;;
  45. esac fi
  46. echo ""
  47. echo "Applying ${i} using ${type}: "
  48. echo ${i} | cat >> ${targetdir}/.applied_patches_list
  49. ${uncomp} ${patchdir}/${i} ${uncomp_parm} | ${apply} ${targetdir}
  50. if [ $? != 0 ] ; then
  51. echo "Patch failed! Please fix $i!"
  52. exit 1
  53. fi
  54. done
  55. # Check for rejects...
  56. if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
  57. echo "Aborting. Reject files found."
  58. exit 1
  59. fi
  60. # Remove backup files
  61. find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;