[16] | 1 | #!/bin/ksh |
---|
| 2 | # |
---|
| 3 | # $Id: applypatch.sh,v 1.1 2001/01/31 17:18:07 gjertsen Exp $ |
---|
| 4 | # $Log: applypatch.sh,v $ |
---|
| 5 | # Revision 1.1 2001/01/31 17:18:07 gjertsen |
---|
| 6 | # Move patch scripts to tools directory. |
---|
| 7 | # |
---|
| 8 | # Revision 1.3 2000/06/29 23:08:50 schmuck |
---|
| 9 | # Fix problem where script got confused when patch command created a |
---|
| 10 | # backup copy of its input file, because it did not exactly match the |
---|
| 11 | # input from which the diff was produced. |
---|
| 12 | # Avoid file name collisions by using a tmp file for patch output. |
---|
| 13 | # |
---|
| 14 | # Revision 1.2 2000/06/23 22:07:31 eshel |
---|
| 15 | # minor changes to messages |
---|
| 16 | # |
---|
| 17 | # Revision 1.1 2000/06/22 23:02:03 eshel |
---|
| 18 | # add createpatch.sh and applypatch.sh to patch linux source .h files |
---|
| 19 | # |
---|
| 20 | # |
---|
| 21 | ## ###################################################################### ## |
---|
| 22 | ## Copyright IBM 2000 ## |
---|
| 23 | ## ###################################################################### ## |
---|
| 24 | |
---|
| 25 | #set nonomatch |
---|
| 26 | #set -x; |
---|
| 27 | |
---|
| 28 | # Verify correct number of parameters |
---|
| 29 | if [ $# != 3 ]; then |
---|
| 30 | echo 'usage: applypatch.sh $SRC $DEST $FILENAME' |
---|
| 31 | exit 1 |
---|
| 32 | fi |
---|
| 33 | |
---|
| 34 | # Get parameter values |
---|
| 35 | PGM=${0##*/} |
---|
| 36 | SRC="$1" |
---|
| 37 | DEST="$2" |
---|
| 38 | DIFF_FILE="$3" |
---|
| 39 | |
---|
| 40 | # Construct name of the .h file to be patched and tmp file for patch output |
---|
| 41 | H_FILE=${DIFF_FILE%.diff}.h |
---|
| 42 | TMP_FILE=/tmp/$$.$H_FILE |
---|
| 43 | |
---|
| 44 | # Compare checksums to verify that the source file to be patched matches |
---|
| 45 | # the file that was used to produce the .diff file |
---|
| 46 | CKSUM1=$(head -1 $DIFF_FILE) |
---|
| 47 | CKSUM2=$(cksum $SRC/$H_FILE) |
---|
| 48 | if [ "$CKSUM1" != "$CKSUM2" ]; then |
---|
| 49 | echo "$PGM: *** Warning: source file $SRC/$H_FILE has changed" |
---|
| 50 | fi |
---|
| 51 | |
---|
| 52 | # Run the patch command; output goes into /tmp |
---|
| 53 | patch --no-backup-if-mismatch --output $TMP_FILE $SRC/$H_FILE $DIFF_FILE |
---|
| 54 | if [ $? != 0 ]; then |
---|
| 55 | echo "$PGM: *** Error: patch command failed" |
---|
| 56 | exit 1 |
---|
| 57 | fi |
---|
| 58 | |
---|
| 59 | # If a file with the same name as the source file exists in the current |
---|
| 60 | # directory, verify that its content matches the result of applying the patch |
---|
| 61 | if [ -f $H_FILE ]; then |
---|
| 62 | diff -q $H_FILE $TMP_FILE > /dev/null |
---|
| 63 | if [ $? != 0 ]; then |
---|
| 64 | echo "$PGM: *** Error: result of applying $DIFF_FILE does not match ./$H_FILE" |
---|
| 65 | echo "$PGM: run createpatch.sh before running applypatch.sh again" |
---|
| 66 | rm $TMP_FILE |
---|
| 67 | exit 1 |
---|
| 68 | fi |
---|
| 69 | fi |
---|
| 70 | |
---|
| 71 | # Install the patched .h file in the destination directory |
---|
| 72 | /usr/bin/install -c -m 0444 $TMP_FILE $DEST/$H_FILE |
---|
| 73 | rc=$? |
---|
| 74 | |
---|
| 75 | # Clean up and return the result of the install command |
---|
| 76 | rm $TMP_FILE |
---|
| 77 | exit $rc |
---|