patch-kernel.sh 1.4 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. patchpattern=${3-*}
  11. if [ ! -d "${targetdir}" ] ; then
  12. echo "Aborting. '${targetdir}' is not a directory."
  13. exit 1
  14. fi
  15. if [ ! -d "${patchdir}" ] ; then
  16. echo "Aborting. '${patchdir}' is not a directory."
  17. exit 1
  18. fi
  19. for i in ${patchdir}/${patchpattern} ; do
  20. case "$i" in
  21. *.gz)
  22. type="gzip"; uncomp="gunzip -dc"; ;;
  23. *.bz)
  24. type="bzip"; uncomp="bunzip -dc"; ;;
  25. *.bz2)
  26. type="bzip2"; uncomp="bunzip2 -dc"; ;;
  27. *.zip)
  28. type="zip"; uncomp="unzip -d"; ;;
  29. *.Z)
  30. type="compress"; uncomp="uncompress -c"; ;;
  31. *)
  32. type="plaintext"; uncomp="cat"; ;;
  33. esac
  34. [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue
  35. echo ""
  36. echo "Applying ${i} using ${type}: "
  37. ${uncomp} ${i} | ${PATCH:-patch} -f -p1 -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 {} \;