-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsync-netbsd-cvs
executable file
·355 lines (316 loc) · 8.93 KB
/
rsync-netbsd-cvs
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#! /bin/sh
#
# rsync-netbsd-cvs - rsync the CVS repo from NetBSD
#
# also updates local working directories....
#
PATH=$PATH:/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin
export PATH
LC_ALL=C
export LC_ALL
#
# local configuration
#
# location of the local repository
#
# WARNING: this pathname needs a trailing slash!
#
REPO_DIR="/vcs/master/m-NetBSD/main/"
# A list of files possibly containing locally added directories which
# need to be re-created in the REPO_DIR after rsync will have removed
# them. (since they don't exist in the remote master repository)
#
# n.b.: any whitespace or special characters in pathnames must be quoted or
# escaped in a manner compatible with xargs(1).
#
LOCALDIRS_LISTS="${LOCALDIRS_LISTS} /usr/pkgsrc/LOCALDIRS" # not normally used
LOCALDIRS_LISTS="${LOCALDIRS_LISTS} /usr/pkgsrc-current/LOCALDIRS"
LOCALDIRS_LISTS="${LOCALDIRS_LISTS} /usr/src/LOCALDIRS" # not normally used
LOCALDIRS_LISTS="${LOCALDIRS_LISTS} /usr/src-current/LOCALDIRS"
LOCALDIRS_LISTS="${LOCALDIRS_LISTS} /usr/xsrc/LOCALDIRS" # not normally used
LOCALDIRS_LISTS="${LOCALDIRS_LISTS} /usr/xsrc-current/LOCALDIRS"
# NOTE: If you probably want the following files in ${REPO_DIR}:
#
# main/CVSROOT/config:
# LockDir=/tmp
# LogHistory=
# LocalKeyword=NetBSD=CVSHeader
# KeywordExpand=iNetBSD,Name,Date,Author,Revision
# KeywordExpand=eId,CVSHeader,Header
#
# and you'll want to make them immutable: 'chflags schg'
# places to run "cvs update" after the rsync is done
#
# N.B.: You probably do not want to rely on the automatic "checkout" feature
# below, at least not for large modules like NetBSD, pkgsrc, etc., as the
# resulting email will be WAY too large.
#
WORK_DIRS=""
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/src-1.6"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/src-4"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/xsrc-4"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/src-5"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/src-7"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/src-8"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/xsrc-5"
WORK_DIRS="${WORK_DIRS} /work/NetBSD/othersrc"
WORK_DIRS="${WORK_DIRS} /work/NetBSD/src"
WORK_DIRS="${WORK_DIRS} /work/NetBSD/xsrc"
WORK_DIRS="${WORK_DIRS} /work/NetBSD/pkgsrc"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/htdocs"
#WORK_DIRS="${WORK_DIRS} /home/wwwadmin/htdocs-netbsd.robohack.ca"
# XXX sadly these are NOT in the anoncvs collection
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/CVSROOT"
#WORK_DIRS="${WORK_DIRS} /work/NetBSD/localsrc"
# places to run "cvs -n update" after the rsync is done
#
WORK_DIRS_CHECK=""
#WORK_DIRS_CHECK="${WORK_DIRS_CHECK} /work/woods/m-NetBSD-pkgsrc-2006Q4"
#WORK_DIRS_CHECK="${WORK_DIRS_CHECK} /work/woods/m-NetBSD-pkgsrc-2007Q1"
#WORK_DIRS_CHECK="${WORK_DIRS_CHECK} /work/woods/m-NetBSD-pkgsrc-2010Q1"
#
# remote configuration
#
# master NetBSD site....
#
SITE="anoncvs.netbsd.org"
METHOD="rsync://"
DIRECTORY="/cvsroot/" # aka the "module", with a trailing slash!
EXTERNAL=""
#
# The "main" sub-directory doesn't exist at anoncvs.netbsd.org, so we
# must include it in the local repo parameter to rsync
#
LOCAL_REPO=${REPO_DIR}
# old site (was another name for the same IP as ftp.netbsd.org):
#
# "Rsync service for the "anoncvs" module has moved from ftp.netbsd.org to
# anoncvs.netbsd.org.
#
# Please see http://mail-index.netbsd.org/netbsd-users/2004/03/29/0010.html
# for important details."
#
#SITE="rsync.netbsd.org"
#METHOD="rsync://"
#DIRECTORY="/anoncvs/"
#EXTERNAL=""
#
# The "main" sub-directory _does_ exist at rsync.netbsd.org...
#
#LOCAL_REPO=${REPO_DIR%%main/}
# alternate site
#
#SITE="rsync.jp.netbsd.org"
#METHOD="rsync://"
#DIRECTORY="/anoncvs/"
#
# Does the "main" sub-directory exist at rsync.jp.netbsd.org?
#
#LOCAL_REPO=${REPO_DIR}
#EXTERNAL=""
# alternate site showing use of ssh
#
#SITE=""
#METHOD="woods@whome.planix.com:"
#DIRECTORY="/u5/NetBSD-CVS/"
#LOCAL_REPO=${REPO_DIR}
#EXTERNAL="-e ssh --blocking-io"
#
# END all configuration!
#
just_make_localdirs=false
just_rsync=false
# set it to "echo" for debugging
DEBUG_ECHO=""
#
# use ${DQ} in front of and after any quoted multi-token parameters on
# command lines that are preceded by "${DEBUG_ECHO} \"
#
DQ=""
RSYNC_DEBUG=""
CVS_DEBUG=""
EX_OK=0
EX_USAGE=2
# XXX we should have "just rsync" and "just update" options too!
#
OPT_STRING=dhlr
argv0=$(basename $0)
mktable ()
{
sed \
-e '/^[ ]*#/d' \
-e 's/#.*$//' \
-e '/^[ ]*$/d' \
${1+"$@"}
}
# re-create directories in the REPO_DIR that we have local (but of
# course uncommitted) new files within...
#
# xxx hmmm....: | tr '\n' '\0' | xargs -0 install -d -m 775 --
#
make_localdirs ()
{
for local_dirs_list in ${LOCALDIRS_LISTS}; do
if [ -s ${local_dirs_list} ] ; then
mktable ${local_dirs_list} | sed -e "s|^|${REPO_DIR}|"
fi
done | sort -u | xargs \
$DEBUG_ECHO \
install -d -m 775 --
unset local_dirs_list
}
usage_error ()
{
echo "Usage: $argv0 [-${OPT_STRING}]" 1>&2
exit $EX_USAGE
}
usage_help ()
{
echo "Usage: $argv0 [-${OPT_STRING}]"
echo " -d enable debug output for testing"
echo " -h print this help message"
echo " -l just run the make_localdirs part"
echo " -r just run rsync and make_localdirs (don't update work directories)"
exit $EX_OK
}
while getopts $OPT_STRING OPT; do
case "$OPT" in
d)
# for testing
#
RSYNC_DEBUG="-vv -n"
CVS_DEBUG="-n"
DEBUG_ECHO=echo
DQ="'"
;;
h)
usage_help
;;
l)
just_make_localdirs=true
;;
r)
just_rsync=true
;;
\?)
usage_error
;;
esac
done
shift $(($OPTIND - 1))
[ $# -ne 0 ] && usage_error
if $just_make_localdirs; then
make_localdirs
exit 0
fi
# WARNING: this script could fail to interlock properly if it can be
# invoked simultaneously with more than one name! Don't do that!
#
LOCKDIR=/tmp/$(basename $0).lock
if [ -e $LOCKDIR ] ; then
echo "It appears there's already an instance of $0 running..." 1>&2
exit 1
fi
if mkdir $LOCKDIR ; then
: #got it!
else
echo "Oops, just missed grabbing $LOCKDIR!" 1>&2
exit 1
fi
cp /var/log/rsync-netbsd-cvs /var/log/rsync-netbsd-cvs.old
(
while true; do
printf "START:%s: rsync\n" "$(date '+%Y/%m/%d-%T')"
rsync ${RSYNC_DEBUG} -rlptHS --timeout=86000 -vz ${EXTERNAL} --stats --delete --delete-after --exclude '#cvs.lock' ${METHOD}${SITE}${DIRECTORY} ${LOCAL_REPO}
rc=$?
#
# Note that E#23 happens normally when rsync can't
# delete the files I've made purposefully immutable
# specifically so that it can't delete them.
#
# Also presumably if the remote server had a problem
# or there was some other filesystem error on this end
# then we should just give up and report what happened
# and wait for tomorrow to try again
#
if [ $rc -eq 0 -o $rc -eq 23 ]; then
break
else
echo ""
printf "FAILED:%s: rsync exited with code: %d\n" "$(date '+%Y/%m/%d-%T')" $rc
fi
# no newline in case someone's doing a 'tail -f'....
printf "PAUSE:%s: " "$(date '+%Y/%m/%d-%T')"
sleep 60
echo "RESTART"
done
printf "DONE:%s: rsync\n" "$(date '+%Y/%m/%d-%T')"
) > /var/log/rsync-netbsd-cvs 2>&1
# this produces the Cron report from the raw log by ignoring any line
# which ends in a '/' (presumably it's just one of the directories
# that was updated)
#
grep -v '/$' /var/log/rsync-netbsd-cvs
echo ""
make_localdirs
if $just_rsync; then
rmdir $LOCKDIR
exit 0
fi
for work_dir in $WORK_DIRS; do
echo "================================================================"
printf "\nSTART:%s: cvs update $work_dir\n\n" "$(date '+%Y/%m/%d-%T')"
if [ ! -d $work_dir ]; then
case ${work_dir} in
/work/NetBSD*)
work_dir_repo="-d /cvs/master/m-NetBSD/main"
work_dir_dir=${work_dir%/*}
work_dir_base=${work_dir##*/}
work_dir_module=${work_dir_base%-*}
# xxx this probably won't work very well
case ${work_dir_module} in
pkgsrc)
case ${work_dir_base} in
*-*)
work_dir_tag="-r ${work_dir_base}"
;;
esac
;;
xsrc|src)
case ${work_dir_base} in
*-*)
work_dir_tag="-r netbsd-${work_dir_base##*-}"
;;
esac
;;
esac
;;
esac
echo "WARNING: there is no ${work_dir} yet!"
cd ${work_dir_dir} && cvs ${work_dir_repo} ${CVS_DEBUG} -u -q checkout -P ${work_dir_tag} -d ${work_dir_base} ${work_dir_module}
else
cd $work_dir && cvs ${CVS_DEBUG} -u -q update -P -d
fi
printf "\nDONE:%s: updating $work_dir\n\n" "$(date '+%Y/%m/%d-%T')"
if [ -x /usr/pkg/bin/lintpkgsrc -a -f $work_dir/packages-to-upgrade -a $(basename $work_dir) = "pkgsrc" ] ; then
/usr/pkg/bin/lintpkgsrc -P $work_dir -i | tee $work_dir/packages-to-upgrade.new
if [ -s $work_dir/packages-to-upgrade.new ] ; then
mv -f $work_dir/packages-to-upgrade.new $work_dir/packages-to-upgrade
fi
fi
done
for work_dir in $WORK_DIRS_CHECK; do
printf "\nSTART:%s: cvs -n update $work_dir\n\n" "$(date '+%Y/%m/%d-%T')"
if [ ! -d $work_dir ]; then
echo "WARNING: there is no ${work_dir} yet!"
else
cd $work_dir && cvs -u -nq update -P -d 2>&1 | fgrep -v 'cvs update: New directory'
fi
printf "\nDONE:%s: checking $work_dir\n\n" "$(date '+%Y/%m/%d-%T')"
done
if [ ! -d $LOCKDIR ] ; then
echo "OOPS!!!! $LOCKDIR went missing!!!!" 1>&2
exit 1
fi
rmdir $LOCKDIR
exit $?