patch-kernel.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /bin/sh
  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. case "$i" in
  22. *.gz)
  23. type="gzip"; uncomp="gunzip -dc"; ;;
  24. *.bz)
  25. type="bzip"; uncomp="bunzip -dc"; ;;
  26. *.bz2)
  27. type="bzip2"; uncomp="bunzip2 -dc"; ;;
  28. *.zip)
  29. type="zip"; uncomp="unzip -d"; ;;
  30. *.Z)
  31. type="compress"; uncomp="uncompress -c"; ;;
  32. *)
  33. type="plaintext"; uncomp="cat"; ;;
  34. esac
  35. echo ""
  36. echo "Applying ${i} using ${type}: "
  37. ${uncomp} ${patchdir}/${i} | patch -p1 -E -d ${targetdir}
  38. if [ $? != 0 ] ; then
  39. echo "Patch failed! Please fix $i!"
  40. exit 1
  41. fi
  42. done
  43. # Check for rejects...
  44. if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
  45. echo "Aborting. Reject files found."
  46. exit 1
  47. fi
  48. # Remove backup files
  49. find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;