apply-patches.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. builddir=${1-.}
  9. patchdir=${2-../kernel-patches}
  10. shift 2
  11. patchpattern=${@-*}
  12. if [ ! -d "${builddir}" ] ; then
  13. echo "Aborting. '${builddir}' 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 builddir.
  23. find ${builddir}/ '(' -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. echo "${patchdir}/$i skipped"
  30. else case "$i" in
  31. *.gz)
  32. type="gzip"; uncomp="gunzip -dc"; ;;
  33. *.bz)
  34. type="bzip"; uncomp="bunzip -dc"; ;;
  35. *.bz2)
  36. type="bzip2"; uncomp="bunzip2 -dc"; ;;
  37. *.zip)
  38. type="zip"; uncomp="unzip -d"; ;;
  39. *.Z)
  40. type="compress"; uncomp="uncompress -c"; ;;
  41. *.tgz)
  42. type="tar gzip"; uncomp="gunzip -dc"; apply="tar xvf - -C"; ;;
  43. *.tar)
  44. type="tar"; uncomp="cat"; apply="tar xvf - -C"; ;;
  45. *)
  46. type="plaintext"; uncomp="cat"; ;;
  47. esac fi
  48. echo ""
  49. echo "Applying ${i} using ${type}: "
  50. echo ${i} >> ${builddir}/.applied_patches_list
  51. ${uncomp} "${patchdir}/${i}" ${uncomp_parm} | ${apply} "${builddir}"
  52. if [ $? != 0 ] ; then
  53. echo "Patch failed! Please fix $i!"
  54. exit 1
  55. fi
  56. done
  57. # Check for rejects...
  58. if [ "`find $builddir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
  59. echo "Aborting. Reject files found."
  60. exit 1
  61. fi
  62. # Remove backup files
  63. find $builddir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;