source: gpfs_3.1_ker2.6.20/lpp/mmfs/src/bin/applypatch.sh @ 69

Last change on this file since 69 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 2.3 KB
RevLine 
[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
29if [ $# != 3 ]; then
30  echo 'usage: applypatch.sh $SRC $DEST $FILENAME'
31  exit 1
32fi
33
34# Get parameter values
35PGM=${0##*/}
36SRC="$1"
37DEST="$2"
38DIFF_FILE="$3"
39
40# Construct name of the .h file to be patched and tmp file for patch output
41H_FILE=${DIFF_FILE%.diff}.h
42TMP_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
46CKSUM1=$(head -1 $DIFF_FILE)
47CKSUM2=$(cksum $SRC/$H_FILE)
48if [ "$CKSUM1" != "$CKSUM2" ]; then
49  echo "$PGM: *** Warning: source file $SRC/$H_FILE has changed"
50fi
51
52# Run the patch command; output goes into /tmp
53patch --no-backup-if-mismatch --output $TMP_FILE $SRC/$H_FILE $DIFF_FILE
54if [ $? != 0 ]; then
55  echo "$PGM: *** Error: patch command failed"
56  exit 1
57fi
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
61if [ -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
69fi
70
71# Install the patched .h file in the destination directory
72/usr/bin/install -c -m 0444 $TMP_FILE $DEST/$H_FILE
73rc=$?
74
75# Clean up and return the result of the install command
76rm $TMP_FILE
77exit $rc
Note: See TracBrowser for help on using the repository browser.