Deleted Added
sdiff udiff text old ( 258063 ) new ( 263221 )
full compact
1#!/bin/sh
2#
3# Copyright (c) 2010 Advanced Computing Technologies LLC
4# Written by: John H. Baldwin <jhb@FreeBSD.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# $FreeBSD: head/tools/regression/usr.sbin/etcupdate/always.sh 258063 2013-11-12 19:15:06Z jhb $
29
30# Various regression tests to test the -A flag to the 'update' command.
31
32WORKDIR=work
33
34usage()
35{
36 echo "Usage: always.sh [-s script] [-w workdir]"
37 exit 1
38}
39
40# Allow the user to specify an alternate work directory or script.
41COMMAND=etcupdate
42while getopts "s:w:" option; do
43 case $option in
44 s)
45 COMMAND="sh $OPTARG"
46 ;;
47 w)
48 WORKDIR=$OPTARG
49 ;;
50 *)
51 echo
52 usage
53 ;;
54 esac
55done
56shift $((OPTIND - 1))
57if [ $# -ne 0 ]; then
58 usage
59fi
60
61CONFLICTS=$WORKDIR/conflicts
62OLD=$WORKDIR/old
63NEW=$WORKDIR/current
64TEST=$WORKDIR/test
65
66# The various states of the comparison of a file between two trees.
67states="equal first second difftype difflinks difffiles"
68
69# These tests deal with ignoring certain patterns of files. We run
70# the test multiple times forcing the install of different patterns.
71build_trees()
72{
73 local i
74
75 rm -rf $OLD $NEW $TEST $CONFLICTS
76
77 for i in $states; do
78 for j in $states; do
79 for k in $states; do
80 mkdir -p $OLD/$i/$j/$k $NEW/$i/$j/$k \
81 $TEST/$i/$j/$k
82 done
83 done
84 done
85
86 # What follows are the various warning/conflict cases from the
87 # larger regression tests. These results of many of these
88 # tests should be changed when installation is forced. The
89 # cases when these updates should still fail even when forced
90 # are: 1) it should not force the removal of a modified file
91 # and 2) it should not remove a subdirectory that contains a
92 # modified or added file.
93
94 # /first/difftype/second: File with different local type
95 # removed. Should generate a warning.
96 mkfifo $OLD/first/difftype/second/fifo
97 mkdir $TEST/first/difftype/second/fifo
98
99 # /first/difflinks/second: Modified link removed. Should
100 # generate a warning.
101 ln -s "old link" $OLD/first/difflinks/second/link
102 ln -s "test link" $TEST/first/difflinks/second/link
103
104 # /first/difffiles/second: Modified file removed. Should
105 # generate a warning.
106 echo "foo" > $OLD/first/difffiles/second/file
107 echo "bar" > $TEST/first/difffiles/second/file
108
109 # /second/second/difftype: Newly added file conflicts with
110 # existing file in test tree of a different type. Should
111 # generate a warning.
112 mkdir $NEW/second/second/difftype/dir
113 mkfifo $TEST/second/second/difftype/dir
114
115 # /second/second/difflinks: Newly added link conflicts with
116 # existing link in test tree. Should generate a warning.
117 ln -s "new link" $NEW/second/second/difflinks/link
118 ln -s "test link" $TEST/second/second/difflinks/link
119
120 # /second/second/difffiles: Newly added file conflicts with
121 # existing file in test tree. Should generate a warning.
122 echo "new" > $NEW/second/second/difffiles/file
123 echo "test" > $TEST/second/second/difffiles/file
124
125 # /difftype/first/first: A removed file has changed type.
126 # This should generate a warning.
127 mkfifo $OLD/difftype/first/first/fifo
128 mkdir $NEW/difftype/first/first/fifo
129
130 # /difftype/difftype/difftype: All three files (old, new, and
131 # test) are different types from each other. This should
132 # generate a warning.
133 mkfifo $OLD/difftype/difftype/difftype/one
134 mkdir $NEW/difftype/difftype/difftype/one
135 echo "foo" > $TEST/difftype/difftype/difftype/one
136 mkdir $OLD/difftype/difftype/difftype/two
137 echo "baz" > $NEW/difftype/difftype/difftype/two
138 ln -s "bar" $TEST/difftype/difftype/difftype/two
139
140 # /difftype/difftype/difflinks: A file has changed from a
141 # non-link to a link in both the new and test trees, but the
142 # target of the new and test links differ. This should
143 # generate a new link conflict.
144 mkfifo $OLD/difftype/difftype/difflinks/link
145 ln -s "new" $NEW/difftype/difftype/difflinks/link
146 ln -s "test" $TEST/difftype/difftype/difflinks/link
147
148 # /difftype/difftype/difffile: A file has changed from a
149 # non-regular file to a regular file in both the new and test
150 # trees, but the contents in the new and test files differ.
151 # This should generate a new file conflict.
152 ln -s "old" $OLD/difftype/difftype/difffiles/file
153 echo "foo" > $NEW/difftype/difftype/difffiles/file
154 echo "bar" > $TEST/difftype/difftype/difffiles/file
155
156 # /difflinks/first/first: A modified link is missing in the
157 # test tree. This should generate a warning.
158 ln -s "old" $OLD/difflinks/first/first/link
159 ln -s "new" $NEW/difflinks/first/first/link
160
161 # /difflinks/difftype/difftype: An updated link has been
162 # changed to a different file type in the test tree. This
163 # should generate a warning.
164 ln -s "old" $OLD/difflinks/difftype/difftype/link
165 ln -s "new" $NEW/difflinks/difftype/difftype/link
166 echo "test" > $TEST/difflinks/difftype/difftype/link
167
168 # /difflinks/difflinks/difflinks: An updated link has been
169 # modified in the test tree and doesn't match either the old
170 # or new links. This should generate a warning.
171 ln -s "old" $OLD/difflinks/difflinks/difflinks/link
172 ln -s "new" $NEW/difflinks/difflinks/difflinks/link
173 ln -s "test" $TEST/difflinks/difflinks/difflinks/link
174
175 # /difffiles/first/first: A removed file has been changed in
176 # the new tree. This should generate a warning.
177 echo "foo" > $OLD/difffiles/first/first/file
178 echo "bar" > $NEW/difffiles/first/first/file
179
180 # /difffiles/difftype/difftype: An updated regular file has
181 # been changed to a different file type in the test tree.
182 # This should generate a warning.
183 echo "old" > $OLD/difffiles/difftype/difftype/file
184 echo "new" > $NEW/difffiles/difftype/difftype/file
185 mkfifo $TEST/difffiles/difftype/difftype/file
186
187 # /difffiles/difffiles/difffiles: A modified regular file was
188 # updated in the new tree. The changes should be merged into
189 # to the new file if possible. If the merge fails, a conflict
190 # should be generated. For this test we just include the
191 # conflict case.
192 cat > $OLD/difffiles/difffiles/difffiles/conflict <<EOF
193this is an old file
194EOF
195 cat > $NEW/difffiles/difffiles/difffiles/conflict <<EOF
196this is a new file
197EOF
198 cat > $TEST/difffiles/difffiles/difffiles/conflict <<EOF
199this is a test file
200EOF
201
202 ## Tests for adding directories
203 mkdir -p $OLD/adddir $NEW/adddir $TEST/adddir
204
205 # /adddir/conflict: Add a new file in a directory that already
206 # exists as a file. This should generate two warnings.
207 mkdir $NEW/adddir/conflict
208 touch $NEW/adddir/conflict/newfile
209 touch $TEST/adddir/conflict
210
211 ## Tests for removing directories
212 mkdir -p $OLD/rmdir $NEW/rmdir $TEST/rmdir
213
214 # /rmdir/extra: Do not remove a directory with an extra local file.
215 # This should generate a warning.
216 for i in $OLD $TEST; do
217 mkdir $i/rmdir/extra
218 done
219 echo "foo" > $TEST/rmdir/extra/localfile.txt
220
221 # /rmdir/conflict: Do not remove a directory with a conflicted
222 # remove file. This should generate a warning.
223 for i in $OLD $TEST; do
224 mkdir $i/rmdir/conflict
225 done
226 mkfifo $OLD/rmdir/conflict/difftype
227 mkdir $TEST/rmdir/conflict/difftype
228
229 ## Tests for converting files to directories and vice versa
230 for i in $OLD $NEW $TEST; do
231 for j in already old fromdir todir; do
232 mkdir -p $i/dirchange/$j
233 done
234 done
235
236 # /dirchange/fromdir/extradir: Convert a directory tree to a
237 # file. The test tree includes an extra file in the directory
238 # that is not present in the old tree. This should generate a
239 # warning.
240 for i in $OLD $TEST; do
241 mkdir $i/dirchange/fromdir/extradir
242 echo "foo" > $i/dirchange/fromdir/extradir/file
243 done
244 mkfifo $TEST/dirchange/fromdir/extradir/fifo
245 ln -s "bar" $NEW/dirchange/fromdir/extradir
246
247 # /dirchange/fromdir/conflict: Convert a directory tree to a
248 # file. The test tree includes a local change that generates
249 # a warning and prevents the removal of the directory.
250 for i in $OLD $TEST; do
251 mkdir $i/dirchange/fromdir/conflict
252 done
253 echo "foo" > $OLD/dirchange/fromdir/conflict/somefile
254 echo "bar" > $TEST/dirchange/fromdir/conflict/somefile
255 mkfifo $NEW/dirchange/fromdir/conflict
256
257 # /dirchange/todir/difffile: Convert a file to a directory
258 # tree. The test tree has a locally modified version of the
259 # file so that the conversion fails with a warning.
260 echo "foo" > $OLD/dirchange/todir/difffile
261 mkdir $NEW/dirchange/todir/difffile
262 echo "baz" > $NEW/dirchange/todir/difffile/file
263 echo "bar" > $TEST/dirchange/todir/difffile
264
265 # /dirchange/todir/difftype: Similar to the previous test, but
266 # the conflict is due to a change in the file type.
267 echo "foo" > $OLD/dirchange/todir/difftype
268 mkdir $NEW/dirchange/todir/difftype
269 echo "baz" > $NEW/dirchange/todir/difftype/file
270 mkfifo $TEST/dirchange/todir/difftype
271}
272
273# $1 - relative path to file that should be missing from TEST
274missing()
275{
276 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
277 echo "File $1 should be missing"
278 fi
279}
280
281# $1 - relative path to file that should be present in TEST
282present()
283{
284 if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then
285 echo "File $1 should be present"
286 fi
287}
288
289# $1 - relative path to file that should be a fifo in TEST
290fifo()
291{
292 if ! [ -p $TEST/$1 ]; then
293 echo "File $1 should be a FIFO"
294 fi
295}
296
297# $1 - relative path to file that should be a directory in TEST
298dir()
299{
300 if ! [ -d $TEST/$1 ]; then
301 echo "File $1 should be a directory"
302 fi
303}
304
305# $1 - relative path to file that should be a symlink in TEST
306# $2 - optional value of the link
307link()
308{
309 local val
310
311 if ! [ -L $TEST/$1 ]; then
312 echo "File $1 should be a link"
313 elif [ $# -gt 1 ]; then
314 val=`readlink $TEST/$1`
315 if [ "$val" != "$2" ]; then
316 echo "Link $1 should link to \"$2\""
317 fi
318 fi
319}
320
321# $1 - relative path to regular file that should be present in TEST
322# $2 - optional string that should match file contents
323# $3 - optional MD5 of the flie contents, overrides $2 if present
324file()
325{
326 local contents sum
327
328 if ! [ -f $TEST/$1 ]; then
329 echo "File $1 should be a regular file"
330 elif [ $# -eq 2 ]; then
331 contents=`cat $TEST/$1`
332 if [ "$contents" != "$2" ]; then
333 echo "File $1 has wrong contents"
334 fi
335 elif [ $# -eq 3 ]; then
336 sum=`md5 -q $TEST/$1`
337 if [ "$sum" != "$3" ]; then
338 echo "File $1 has wrong contents"
339 fi
340 fi
341}
342
343# $1 - relative path to a regular file that should have a conflict
344# $2 - optional MD5 of the conflict file contents
345conflict()
346{
347 local sum
348
349 if ! [ -f $CONFLICTS/$1 ]; then
350 echo "File $1 missing conflict"
351 elif [ $# -gt 1 ]; then
352 sum=`md5 -q $CONFLICTS/$1`
353 if [ "$sum" != "$2" ]; then
354 echo "Conflict $1 has wrong contents"
355 fi
356 fi
357}
358
359# $1 - relative path to a regular file that should not have a conflict
360noconflict()
361{
362 if [ -f $CONFLICTS/$1 ]; then
363 echo "File $1 should not have a conflict"
364 fi
365}
366
367if [ `id -u` -ne 0 ]; then
368 echo "must be root"
369fi
370
371if [ -r /etc/etcupdate.conf ]; then
372 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
373fi
374
375# First run the test ignoring no patterns.
376
377build_trees
378
379$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
380
381cat > $WORKDIR/correct.out <<EOF
382 D /dirchange/fromdir/extradir/file
383 C /difffiles/difffiles/difffiles/conflict
384 C /difftype/difftype/difffiles/file
385 C /second/second/difffiles/file
386Warnings:
387 Modified regular file remains: /dirchange/fromdir/conflict/somefile
388 Modified regular file remains: /first/difffiles/second/file
389 Modified symbolic link remains: /first/difflinks/second/link
390 Modified directory remains: /first/difftype/second/fifo
391 Modified directory remains: /rmdir/conflict/difftype
392 Non-empty directory remains: /rmdir/extra
393 Non-empty directory remains: /rmdir/conflict
394 Modified mismatch: /difffiles/difftype/difftype/file (regular file vs fifo file)
395 Removed file changed: /difffiles/first/first/file
396 Modified link changed: /difflinks/difflinks/difflinks/link ("old" became "new")
397 Modified mismatch: /difflinks/difftype/difftype/link (symbolic link vs regular file)
398 Removed link changed: /difflinks/first/first/link ("old" became "new")
399 New link conflict: /difftype/difftype/difflinks/link ("new" vs "test")
400 Modified regular file changed: /difftype/difftype/difftype/one (fifo file became directory)
401 Modified symbolic link changed: /difftype/difftype/difftype/two (directory became regular file)
402 Remove mismatch: /difftype/first/first/fifo (fifo file became directory)
403 Modified directory changed: /dirchange/fromdir/conflict (directory became fifo file)
404 Modified directory changed: /dirchange/fromdir/extradir (directory became symbolic link)
405 Modified regular file changed: /dirchange/todir/difffile (regular file became directory)
406 Modified fifo file changed: /dirchange/todir/difftype (regular file became directory)
407 New file mismatch: /adddir/conflict (directory vs regular file)
408 Directory mismatch: $TEST/adddir/conflict (regular file)
409 Directory mismatch: $TEST/dirchange/todir/difffile (regular file)
410 Directory mismatch: $TEST/dirchange/todir/difftype (fifo file)
411 New link conflict: /second/second/difflinks/link ("new link" vs "test link")
412 New file mismatch: /second/second/difftype/dir (directory vs fifo file)
413EOF
414
415echo "Differences for regular:"
416diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out
417
418## /first/difftype/second:
419present /first/difftype/second/fifo
420
421## /first/difflinks/second:
422link /first/difflinks/second/link "test link"
423
424## /first/difffiles/second:
425file /first/difffiles/second/file "bar"
426
427## /second/second/difftype:
428fifo /second/second/difftype/dir
429
430## /second/second/difflinks:
431link /second/second/difflinks/link "test link"
432
433## /second/second/difffiles:
434file /second/second/difffiles/file "test"
435conflict /second/second/difffiles/file 4f2ee8620a251fd53f06bb6112eb6ffa
436
437## /difftype/first/first:
438missing /difftype/first/first/fifo
439
440## /difftype/difftype/difftype:
441file /difftype/difftype/difftype/one "foo"
442link /difftype/difftype/difftype/two "bar"
443
444## /difftype/difftype/difflinks:
445link /difftype/difftype/difflinks/link "test"
446
447## /difftype/difftype/difffile:
448conflict /difftype/difftype/difffiles/file 117f2bcd1f6491f6044e79e5a57a9229
449
450## /difflinks/first/first:
451missing /difflinks/first/first/link
452
453## /difflinks/difftype/difftype:
454file /difflinks/difftype/difftype/link "test"
455
456## /difflinks/difflinks/difflinks:
457link /difflinks/difflinks/difflinks/link "test"
458
459## /difffiles/first/first:
460missing /difffiles/first/first/file
461
462## /difffiles/difftype/difftype:
463fifo /difffiles/difftype/difftype/file
464
465## /difffiles/difffiles/difffiles:
466file /difffiles/difffiles/difffiles/conflict "this is a test file"
467conflict /difffiles/difffiles/difffiles/conflict \
468 8261cfdd89280c4a6c26e4ac86541fe9
469
470## /adddir/conflict:
471file /adddir/conflict
472
473## /rmdir/extra:
474dir /rmdir/extra
475file /rmdir/extra/localfile.txt "foo"
476
477## /rmdir/conflict:
478dir /rmdir/conflict/difftype
479present /rmdir/conflict
480
481## /dirchange/fromdir/extradir:
482missing /dirchange/fromdir/extradir/file
483fifo /dirchange/fromdir/extradir/fifo
484
485## /dirchange/fromdir/conflict:
486file /dirchange/fromdir/conflict/somefile "bar"
487
488## /dirchange/todir/difffile:
489file /dirchange/todir/difffile "bar"
490
491## /dirchange/todir/difftype:
492fifo /dirchange/todir/difftype
493
494# Now test with -A '/first*' -A '/second* /*di*'. This should remove
495# most of the warnings and conflicts.
496
497build_trees
498
499$COMMAND -r -A '/first*' -A '/second* /*di*' -d $WORKDIR -D $TEST > \
500 $WORKDIR/test1.out
501
502cat > $WORKDIR/correct1.out <<EOF
503 D /dirchange/fromdir/extradir/file
504 U /difffiles/difffiles/difffiles/conflict
505 U /difffiles/difftype/difftype/file
506 A /difffiles/first/first/file
507 U /difflinks/difflinks/difflinks/link
508 U /difflinks/difftype/difftype/link
509 A /difflinks/first/first/link
510 U /difftype/difftype/difffiles/file
511 U /difftype/difftype/difflinks/link
512 D /difftype/difftype/difftype/one
513 U /difftype/difftype/difftype/two
514 U /dirchange/todir/difffile
515 U /dirchange/todir/difftype
516 U /adddir/conflict
517 A /adddir/conflict/newfile
518 A /dirchange/todir/difffile/file
519 A /dirchange/todir/difftype/file
520 U /second/second/difffiles/file
521 U /second/second/difflinks/link
522 D /second/second/difftype/dir
523Warnings:
524 Modified regular file remains: /dirchange/fromdir/conflict/somefile
525 Modified regular file remains: /first/difffiles/second/file
526 Modified symbolic link remains: /first/difflinks/second/link
527 Modified directory remains: /first/difftype/second/fifo
528 Modified directory remains: /rmdir/conflict/difftype
529 Non-empty directory remains: /rmdir/extra
530 Non-empty directory remains: /rmdir/conflict
531 Modified directory changed: /dirchange/fromdir/conflict (directory became fifo file)
532 Modified directory changed: /dirchange/fromdir/extradir (directory became symbolic link)
533EOF
534
535echo "Differences for -A '/first*' -A '/second* /*di*':"
536diff -u -L "correct" $WORKDIR/correct1.out -L "test" $WORKDIR/test1.out
537
538## /first/difftype/second:
539present /first/difftype/second/fifo
540
541## /first/difflinks/second:
542link /first/difflinks/second/link "test link"
543
544## /first/difffiles/second:
545file /first/difffiles/second/file "bar"
546
547## /second/second/difftype:
548missing /second/second/difftype/dir
549
550## /second/second/difflinks:
551link /second/second/difflinks/link "new link"
552
553## /second/second/difffiles:
554file /second/second/difffiles/file "new"
555noconflict /second/second/difffiles/file
556
557## /difftype/first/first:
558missing /difftype/first/first/fifo
559
560## /difftype/difftype/difftype:
561missing /difftype/difftype/difftype/one
562file /difftype/difftype/difftype/two "baz"
563
564## /difftype/difftype/difflinks:
565link /difftype/difftype/difflinks/link "new"
566
567## /difftype/difftype/difffile:
568noconflict /difftype/difftype/difffiles/file
569file /difftype/difftype/difffiles/file "foo"
570
571## /difflinks/first/first:
572link /difflinks/first/first/link "new"
573
574## /difflinks/difftype/difftype:
575link /difflinks/difftype/difftype/link "new"
576
577## /difflinks/difflinks/difflinks:
578link /difflinks/difflinks/difflinks/link "new"
579
580## /difffiles/first/first:
581file /difffiles/first/first/file "bar"
582
583## /difffiles/difftype/difftype:
584file /difffiles/difftype/difftype/file "new"
585
586## /difffiles/difffiles/difffiles:
587noconflict /difffiles/difffiles/difffiles/conflict
588file /difffiles/difffiles/difffiles/conflict "this is a new file"
589
590## /adddir/conflict:
591file /adddir/conflict/newfile
592
593## /rmdir/extra:
594dir /rmdir/extra
595file /rmdir/extra/localfile.txt "foo"
596
597## /rmdir/conflict:
598dir /rmdir/conflict/difftype
599present /rmdir/conflict
600
601## /dirchange/fromdir/extradir:
602missing /dirchange/fromdir/extradir/file
603fifo /dirchange/fromdir/extradir/fifo
604
605## /dirchange/fromdir/conflict:
606file /dirchange/fromdir/conflict/somefile "bar"
607
608## /dirchange/todir/difffile:
609file /dirchange/todir/difffile/file "baz"
610
611## /dirchange/todir/difftype:
612file /dirchange/todir/difftype/file "baz"