-
Notifications
You must be signed in to change notification settings - Fork 4
/
ircd-patch
executable file
·226 lines (205 loc) · 4.81 KB
/
ircd-patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
#
# IRC - Internet Relay Chat, ircd-patch
# Copyright (C) 2002 Alex Badea <vampire@p16.pub.ro>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: ircd-patch,v 1.5.2.1 2005/12/29 03:41:56 entrope Exp $
#
#
# Experimental centralized patch system for ircu
# Run with no arguments to get help.
#
# Return codes:
# 0 - success
# 1 - at least one live patch failed
# 2 - at least one simulation (dry run) failed
# 3 - invalid arguments (i.e. no such patch)
# 4 - invalid operation (i.e. tried to apply when already applied)
#
DIFFS=patches/diffs
MARKS=patches/marks
PLIST_FILE=include/patchlist.h
retcode=0
force=0
PLIST=""
for fname in $DIFFS/*.diff ; do
name=`basename $fname | sed -e 's/\.diff//'`
PLIST="$PLIST $name"
done
update_patchlist() {
list=""
for name in $PLIST ; do
test -f $MARKS/$name && list="$list.$name"
done
echo "/* This file was automatically generated by ircd-patch */" > $PLIST_FILE
echo "#define PATCHLIST \"$list\"" >> $PLIST_FILE
echo "Updated $PLIST_FILE"
}
test -d $DIFFS || (echo "*** Missing $DIFFS, creating it" ; mkdir -p $DIFFS)
test -d $MARKS || (echo "*** Missing $MARKS, creating it" ; mkdir -p $MARKS)
dry_run() {
rejects=`patch -p0 -N -t --dry-run $2 < $1 | grep "hunk FAILED" | sed -e 's/.*to file / /;s/\.rej$//'`
test -z "$rejects"
}
patch_list() {
echo "Available patches (* marks applied patches):"
for name in $PLIST ; do
test -f $MARKS/$name && echo -n " * " || echo -n " "
echo $name
done
echo "Done."
}
patch_test() {
echo "Testing patches:"
list="$*"
test "z$list" = "z" && list=$PLIST
for name in $list ; do
fname=$DIFFS/$name.diff
echo -ne " $name\t"
if test ! -f $MARKS/$name ; then
if dry_run "$fname" ; then
echo -n " OK"
else
echo -n " PATCH FAILED"
retcode=2
fi
else
echo -n " APPLIED"
if dry_run "$fname" -R ; then
echo -n " OK"
else
echo -n " REVERSE FAILED"
retcode=2
fi
fi
echo
done
echo "Done."
}
patch_add() {
name=$1
fname="$DIFFS/$name.diff"
if test ! -f $fname ; then
echo "Patch $name ($fname) does not exist"
retcode=3
return
fi
if test $force -lt 2 -a -f $MARKS/$name ; then
echo "Patch $name seems already applied"
retcode=4
return
fi
if test $force -lt 1 ; then
echo -n "Testing $fname... "
if ! dry_run $fname ; then
echo "Failed (use -f to force)."
echo "The following files failed patching:"
echo "$rejects"
retcode=2
return
fi
echo "seems ok."
fi
echo "Applying $fname..."
if patch -p0 -N -t < $fname ; then
touch $MARKS/$name
echo "Done."
else
echo "Failed."
retcode=1
fi
}
patch_del() {
name=$1
fname="$DIFFS/$name.diff"
if test ! -f $fname ; then
echo "Patch $name ($fname) does not exist"
retcode=3
return
fi
if test $force -lt 2 -a ! -f $MARKS/$name ; then
echo "Patch $name doesn't seem to be applied"
retcode=4
return
fi
if test $force -lt 1 ; then
echo -n "Testing $fname... "
if ! dry_run $fname -R ; then
echo "Failed (use -f to force)."
echo "The following files failed patching:"
echo "$rejects"
retcode=2
return
fi
echo "seems ok."
fi
echo "Reversing $fname..."
if patch -p0 -R -t < $fname ; then
rm -f $MARKS/$name
echo "Done."
else
echo "Failed."
retcode=1
fi
}
do_help() {
echo "Usage: $0 [-f [-f]] [args]"
echo "Arguments may be:"
echo " help Prints this help"
echo " list List available patches"
echo " test [patch list] Tests whether patches can be (un)applied correctly"
echo " add <patch list> Applies a patch"
echo " del <patch list> Reverses a patch"
echo " update Updates $PLIST_FILE with the currently applied patches"
echo "The -f option forces patching even if a dry run fails (effective on 'add'"
echo "and 'del' commands only). Using it twice will also skip checking whether"
echo "a patch is already applied."
}
while test "$1" = "-f" ; do
force=`expr $force + 1`
shift
done
case "$1" in
add)
shift
for name in $* ; do
patch_add $name
done
update_patchlist
;;
del)
shift
for name in $* ; do
patch_del $name
done
update_patchlist
;;
test)
shift
patch_test $*
;;
list)
patch_list
;;
update)
update_patchlist
;;
*)
do_help
;;
esac
exit $retcode