3 # IRC - Internet Relay Chat, ircd-patch
4 # Copyright (C) 2002 Alex Badea <vampire@p16.pub.ro>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 1, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # $Id: ircd-patch,v 1.5.2.1 2005/12/29 03:41:56 entrope Exp $
23 # Experimental centralized patch system for ircu
24 # Run with no arguments to get help.
28 # 1 - at least one live patch failed
29 # 2 - at least one simulation (dry run) failed
30 # 3 - invalid arguments (i.e. no such patch)
31 # 4 - invalid operation (i.e. tried to apply when already applied)
36 PLIST_FILE=include/patchlist.h
43 for fname in $DIFFS/*.diff ; do
44 name=`basename $fname | sed -e 's/\.diff//'`
50 for name in $PLIST ; do
51 test -f $MARKS/$name && list="$list.$name"
53 echo "/* This file was automatically generated by ircd-patch */" > $PLIST_FILE
54 echo "#define PATCHLIST \"$list\"" >> $PLIST_FILE
55 echo "Updated $PLIST_FILE"
58 test -d $DIFFS || (echo "*** Missing $DIFFS, creating it" ; mkdir -p $DIFFS)
59 test -d $MARKS || (echo "*** Missing $MARKS, creating it" ; mkdir -p $MARKS)
62 rejects=`patch -p0 -N -t --dry-run $2 < $1 | grep "hunk FAILED" | sed -e 's/.*to file / /;s/\.rej$//'`
67 echo "Available patches (* marks applied patches):"
68 for name in $PLIST ; do
69 test -f $MARKS/$name && echo -n " * " || echo -n " "
76 echo "Testing patches:"
78 test "z$list" = "z" && list=$PLIST
79 for name in $list ; do
80 fname=$DIFFS/$name.diff
82 if test ! -f $MARKS/$name ; then
83 if dry_run "$fname" ; then
86 echo -n " PATCH FAILED"
91 if dry_run "$fname" -R ; then
94 echo -n " REVERSE FAILED"
105 fname="$DIFFS/$name.diff"
106 if test ! -f $fname ; then
107 echo "Patch $name ($fname) does not exist"
112 if test $force -lt 2 -a -f $MARKS/$name ; then
113 echo "Patch $name seems already applied"
118 if test $force -lt 1 ; then
119 echo -n "Testing $fname... "
120 if ! dry_run $fname ; then
121 echo "Failed (use -f to force)."
122 echo "The following files failed patching:"
130 echo "Applying $fname..."
131 if patch -p0 -N -t < $fname ; then
142 fname="$DIFFS/$name.diff"
143 if test ! -f $fname ; then
144 echo "Patch $name ($fname) does not exist"
149 if test $force -lt 2 -a ! -f $MARKS/$name ; then
150 echo "Patch $name doesn't seem to be applied"
155 if test $force -lt 1 ; then
156 echo -n "Testing $fname... "
157 if ! dry_run $fname -R ; then
158 echo "Failed (use -f to force)."
159 echo "The following files failed patching:"
167 echo "Reversing $fname..."
168 if patch -p0 -R -t < $fname ; then
178 echo "Usage: $0 [-f [-f]] [args]"
179 echo "Arguments may be:"
180 echo " help Prints this help"
181 echo " list List available patches"
182 echo " test [patch list] Tests whether patches can be (un)applied correctly"
183 echo " add <patch list> Applies a patch"
184 echo " del <patch list> Reverses a patch"
185 echo " update Updates $PLIST_FILE with the currently applied patches"
186 echo "The -f option forces patching even if a dry run fails (effective on 'add'"
187 echo "and 'del' commands only). Using it twice will also skip checking whether"
188 echo "a patch is already applied."
191 while test "$1" = "-f" ; do
192 force=`expr $force + 1`