4 # Copyright (C) 2002 Alex Badea <vampire@p16.pub.ro>
6 # $Id: ircd-patch,v 1.3 2002-04-02 11:24:29 isomer Exp $
8 # Experimental centralized patch system for ircu
12 # 1 - at least one live patch failed
13 # 2 - at least one simulation (dry run) failed
14 # 3 - invalid arguments (i.e. no such patch)
15 # 4 - invalid operation (i.e. tried to apply when already applied)
20 PLIST_FILE=include/patchlist.h
27 for fname in $DIFFS/*.diff ; do
28 name=`basename $fname | sed -e 's/\.diff//'`
34 for name in $PLIST ; do
35 [ -f $MARKS/$name ] && list="$list.$name"
37 echo "/* This file was automatically generated by ircd-patch */" > $PLIST_FILE
38 echo "#define PATCHLIST \"$list\"" >> $PLIST_FILE
39 echo "Updated $PLIST_FILE"
42 [ ! -d $DIFFS ] && (echo "*** Missing $DIFFS, creating it" ; mkdir -p $DIFFS)
43 [ ! -d $MARKS ] && (echo "*** Missing $MARKS, creating it" ; mkdir -p $MARKS)
46 patch -p0 -N -t --dry-run $2 >/dev/null < $1
50 echo "Available patches (* marks applied patches):"
51 for name in $PLIST ; do
52 [ -f $MARKS/$name ] && echo -n " * " || echo -n " "
59 echo "Testing patches:"
61 [ -z "$list" ] && list=$PLIST
62 for name in $list ; do
63 fname=$DIFFS/$name.diff
65 if [ ! -f $MARKS/$name ] ; then
66 if dry_run "$fname" ; then
69 echo -n " PATCH FAILED"
74 if dry_run "$fname" -R ; then
77 echo -n " REVERSE FAILED"
88 fname="$DIFFS/$name.diff"
89 if [ ! -f $fname ]; then
90 echo "Patch $name ($fname) does not exist"
95 if [ $force -lt 2 -a -f $MARKS/$name ] ; then
96 echo "Patch $name seems already applied"
101 if [ $force -lt 1 ]; then
102 echo -n "Testing $fname... "
103 if ! dry_run $fname ; then
104 echo "Failed (use -f to force)."
111 echo "Applying $fname..."
112 if patch -p0 -N -t < $fname ; then
123 fname="$DIFFS/$name.diff"
124 if [ ! -f $fname ]; then
125 echo "Patch $name ($fname) does not exist"
130 if [ $force -lt 2 -a ! -f $MARKS/$name ] ; then
131 echo "Patch $name doesn't seem to be applied"
136 if [ $force -lt 1 ]; then
137 echo -n "Testing $fname... "
138 if ! dry_run $fname -R ; then
139 echo "Failed (use -f to force)."
146 echo "Reversing $fname..."
147 if patch -p0 -R -t < $fname ; then
157 echo "Usage: $0 [-f [-f]] [args]"
158 echo "Arguments may be:"
159 echo " help Prints this help"
160 echo " list List available patches"
161 echo " test [patch list] Tests whether patches can be (un)applied correctly"
162 echo " add <patch list> Applies a patch"
163 echo " del <patch list> Reverses a patch"
164 echo " update Updates $PLIST_FILE with the currently applied patches"
165 echo "The -f option forces patching even if a dry run fails (effective on 'add'"
166 echo "and 'del' commands only). Using it twice will also skip checking whether"
167 echo "a patch is already applied."
170 while [ "$1" == "-f" ]; do