apply_patches 637 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. if [ "$1" = "-q" ] ; then
  3. quiet=1
  4. shift
  5. fi
  6. PATCH=${PATCH:-patch}
  7. patchdir=${1:?You must supply a patches directory}
  8. sourcedir=${2?:You must supply a source directory}
  9. if [ ! -d "$patchdir" ] ; then
  10. echo "$patchdir is not a directory" >&2
  11. exit 1
  12. fi
  13. if [ ! -d "$sourcedir" ] ; then
  14. echo "$sourcedir is not a directory" >&2
  15. exit 1
  16. fi
  17. if [ ! "$(ls -A $patchdir/*.patch 2>/dev/null)" ] ; then
  18. echo "No patches in $patchdir" >&2
  19. exit 0
  20. fi
  21. for patchfile in "$patchdir"/*.patch ; do
  22. [ -z $quiet ] && echo "Applying patch $(basename $patchfile)"
  23. ${PATCH} -d "$sourcedir" -p1 -s -i "$patchfile" || exit 1
  24. done
  25. exit 0