patch-kernel.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. 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. echo ${i} | cat >> ${targetdir}/.applied_patches_list
  38. ${uncomp} ${patchdir}/${i} | patch -p1 -E -d ${targetdir}
  39. if [ $? != 0 ] ; then
  40. echo "Patch failed! Please fix $i!"
  41. exit 1
  42. fi
  43. done
  44. # Check for rejects...
  45. if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
  46. echo "Aborting. Reject files found."
  47. exit 1
  48. fi
  49. # Remove backup files
  50. find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;