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.4 2002-04-09 22:40:56 vampire 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 [ -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 [ ! -d $DIFFS ] && (echo "*** Missing $DIFFS, creating it" ; mkdir -p $DIFFS)
59 [ ! -d $MARKS ] && (echo "*** Missing $MARKS, creating it" ; mkdir -p $MARKS)
62 patch -p0 -N -t --dry-run $2 >/dev/null < $1
66 echo "Available patches (* marks applied patches):"
67 for name in $PLIST ; do
68 [ -f $MARKS/$name ] && echo -n " * " || echo -n " "
75 echo "Testing patches:"
77 [ -z "$list" ] && list=$PLIST
78 for name in $list ; do
79 fname=$DIFFS/$name.diff
81 if [ ! -f $MARKS/$name ] ; then
82 if dry_run "$fname" ; then
85 echo -n " PATCH FAILED"
90 if dry_run "$fname" -R ; then
93 echo -n " REVERSE FAILED"
104 fname="$DIFFS/$name.diff"
105 if [ ! -f $fname ]; then
106 echo "Patch $name ($fname) does not exist"
111 if [ $force -lt 2 -a -f $MARKS/$name ] ; then
112 echo "Patch $name seems already applied"
117 if [ $force -lt 1 ]; then
118 echo -n "Testing $fname... "
119 if ! dry_run $fname ; then
120 echo "Failed (use -f to force)."
127 echo "Applying $fname..."
128 if patch -p0 -N -t < $fname ; then
139 fname="$DIFFS/$name.diff"
140 if [ ! -f $fname ]; then
141 echo "Patch $name ($fname) does not exist"
146 if [ $force -lt 2 -a ! -f $MARKS/$name ] ; then
147 echo "Patch $name doesn't seem to be applied"
152 if [ $force -lt 1 ]; then
153 echo -n "Testing $fname... "
154 if ! dry_run $fname -R ; then
155 echo "Failed (use -f to force)."
162 echo "Reversing $fname..."
163 if patch -p0 -R -t < $fname ; then
173 echo "Usage: $0 [-f [-f]] [args]"
174 echo "Arguments may be:"
175 echo " help Prints this help"
176 echo " list List available patches"
177 echo " test [patch list] Tests whether patches can be (un)applied correctly"
178 echo " add <patch list> Applies a patch"
179 echo " del <patch list> Reverses a patch"
180 echo " update Updates $PLIST_FILE with the currently applied patches"
181 echo "The -f option forces patching even if a dry run fails (effective on 'add'"
182 echo "and 'del' commands only). Using it twice will also skip checking whether"
183 echo "a patch is already applied."
186 while [ "$1" == "-f" ]; do