]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - packaging/utils/patcher
3 # Copyright (C) 1999, 2001 Henry Spencer.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # patcher [-v] [-c] targetdir target [ key patchfile ] ...
16 # In targetdir, patch target from patchfile unless it already contains
17 # key and it appears to have been patched with the same patch. (If the
18 # patch has changed, undo the old one and then put the new one in.) Save
19 # original as target.preipsec, and patched copy as target.wipsec, with
20 # patch md5sum stored as target.ipsecmd5. If the patch doesn't work,
21 # put the original back and save the patch attempt as target.mangled.
22 # If there are no key+patchfile pairs, undo any old patch and leave it
25 # -c means do "patching" by appending rather than by using patch(1)
27 # RCSID $Id: patcher,v 1.1 2004/03/15 20:35:27 as Exp $
29 PATH
=/bin
:/usr
/bin
:/usr
/local
/bin
:/sbin
:/usr
/sbin
:/usr
/local
/sbin
41 -*) echo "$0: unknown option \`$1'" >&2 ; exit 2 ;;
48 echo "Usage: $0 [-v] [-c] targetdir target [ key patchfile ] ..." >&2
55 echo "$0: cannot find file \`$1'" >&2
76 if test ! -s $it.ipsecmd5
78 # no records of patching...
86 if egrep -q "$key" $it
88 # patched but no record of how
89 note
"$it no longer needs patch $patchfile"
91 patches
="$patches $patchfile"
94 elif test ! -f $it.preipsec
-o ! -f $it.wipsec
96 echo "$0: $it.preipsec or .wipsec is missing!" >&2
99 # determine whether patches have changed
108 md5sum $patchfile |
awk '{print $1}' >>$tmp
110 if egrep -q "$key" $it.preipsec
112 note
"$it no longer needs patch $patchfile"
114 patches
="$patches $patchfile"
117 if cmp -s $tmp $it.ipsecmd5
119 note
"$it already fully patched"
125 # must undo old patch(es)
126 note
"$it old patches must be undone, undoing them..."
127 if ! cmp -s $it $it.wipsec
129 note
"$it has changed, cannot undo old patches!"
130 echo "$0: cannot unpatch $it, it has changed since patching" >&2
135 rm $it.wipsec
$it.ipsecmd5
138 # if no necessary patches, we're done
139 if test " $patches" = " "
141 note
"$it no longer needs patching"
145 # try to figure out patch options
146 if test " $modifier" = " patch"
148 if patch --help >/dev
/null
2>/dev
/null
150 # looks like a modern version
153 # looks like an old one
160 for patchfile
in $patches
162 note
"applying $patchfile to $it..."
164 # make local copy - this defeats hard and soft links
165 mv $it $it.preipsec ||
exit 0
167 cp -p $it.preipsec
$it
170 patch) ( cd $dir ; patch $popts ) <$patchfile ;;
171 cat) cat $patchfile >>$it ;;
174 if test $status -ne 0
176 note
"$it patch failed, restoring original"
177 echo "$0: patch on $it failed!" >&2
178 echo "$0: restoring original $it," >&2
179 echo "$0: leaving patch attempt in $it.mangled" >&2
185 rm -f $it.orig
# some patch versions leave debris
186 md5sum $patchfile |
awk '{print $1}' >>$it.ipsecmd5