b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 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 | |
| 8 | # Set directories from arguments, or use defaults. |
| 9 | targetdir=${1-.} |
| 10 | patchdir=${2-../kernel-patches} |
| 11 | patchpattern=${3-*} |
| 12 | |
| 13 | if [ ! -d "${targetdir}" ] ; then |
| 14 | echo "Aborting. '${targetdir}' is not a directory." |
| 15 | exit 1 |
| 16 | fi |
| 17 | if [ ! -d "${patchdir}" ] ; then |
| 18 | echo "Aborting. '${patchdir}' is not a directory." |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | for i in ${patchdir}/${patchpattern} ; do |
| 23 | case "$i" in |
| 24 | *.gz) |
| 25 | type="gzip"; uncomp="gunzip -dc"; ;; |
| 26 | *.bz) |
| 27 | type="bzip"; uncomp="bunzip -dc"; ;; |
| 28 | *.bz2) |
| 29 | type="bzip2"; uncomp="bunzip2 -dc"; ;; |
| 30 | *.zip) |
| 31 | type="zip"; uncomp="unzip -d"; ;; |
| 32 | *.Z) |
| 33 | type="compress"; uncomp="uncompress -c"; ;; |
| 34 | *) |
| 35 | type="plaintext"; uncomp="cat"; ;; |
| 36 | esac |
| 37 | [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue |
| 38 | echo "" |
| 39 | echo "Applying ${i} using ${type}: " |
| 40 | ${uncomp} ${i} | ${PATCH:-patch} -f -p1 -d ${targetdir} |
| 41 | if [ $? != 0 ] ; then |
| 42 | echo "Patch failed! Please fix $i!" |
| 43 | exit 1 |
| 44 | fi |
| 45 | done |
| 46 | |
| 47 | # Check for rejects... |
| 48 | if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then |
| 49 | echo "Aborting. Reject files found." |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
| 53 | # Remove backup files |
| 54 | find $targetdir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \; |