1238423Sjhb#!/bin/sh 2238423Sjhb# 3238423Sjhb# Copyright (c) 2010 Advanced Computing Technologies LLC 4238423Sjhb# Written by: John H. Baldwin <jhb@FreeBSD.org> 5238423Sjhb# All rights reserved. 6238423Sjhb# 7238423Sjhb# Redistribution and use in source and binary forms, with or without 8238423Sjhb# modification, are permitted provided that the following conditions 9238423Sjhb# are met: 10238423Sjhb# 1. Redistributions of source code must retain the above copyright 11238423Sjhb# notice, this list of conditions and the following disclaimer. 12238423Sjhb# 2. Redistributions in binary form must reproduce the above copyright 13238423Sjhb# notice, this list of conditions and the following disclaimer in the 14238423Sjhb# documentation and/or other materials provided with the distribution. 15238423Sjhb# 16238423Sjhb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17238423Sjhb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18238423Sjhb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19238423Sjhb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20238423Sjhb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21238423Sjhb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22238423Sjhb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23238423Sjhb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24238423Sjhb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25238423Sjhb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26238423Sjhb# SUCH DAMAGE. 27238423Sjhb# 28238423Sjhb# $FreeBSD$ 29238423Sjhb 30238423Sjhb# Various regression tests to test the -I flag to the 'update' command. 31238423Sjhb 32238423SjhbWORKDIR=work 33238423Sjhb 34238423Sjhbusage() 35238423Sjhb{ 36238423Sjhb echo "Usage: ignore.sh [-w workdir]" 37238423Sjhb exit 1 38238423Sjhb} 39238423Sjhb 40238423Sjhb# Allow the user to specify an alternate work directory. 41238423Sjhbwhile getopts "w:" option; do 42238423Sjhb case $option in 43238423Sjhb w) 44238423Sjhb WORKDIR=$OPTARG 45238423Sjhb ;; 46238423Sjhb *) 47238423Sjhb echo 48238423Sjhb usage 49238423Sjhb ;; 50238423Sjhb esac 51238423Sjhbdone 52238423Sjhbshift $((OPTIND - 1)) 53238423Sjhbif [ $# -ne 0 ]; then 54238423Sjhb usage 55238423Sjhbfi 56238423Sjhb 57238423SjhbCONFLICTS=$WORKDIR/conflicts 58238423SjhbOLD=$WORKDIR/old 59238423SjhbNEW=$WORKDIR/current 60238423SjhbTEST=$WORKDIR/test 61238423Sjhb 62238423Sjhb# These tests deal with ignoring certain patterns of files. We run the 63238423Sjhb# test multiple times ignoring different patterns. 64238423Sjhbbuild_trees() 65238423Sjhb{ 66238423Sjhb local i 67238423Sjhb 68238423Sjhb rm -rf $OLD $NEW $TEST $CONFLICTS 69238423Sjhb mkdir -p $OLD $NEW $TEST 70238423Sjhb 71238423Sjhb for i in $OLD $NEW $TEST; do 72238423Sjhb mkdir -p $i/tree 73238423Sjhb done 74238423Sjhb 75238423Sjhb # tree: Test three different cases (add, modify, remove) that all 76238423Sjhb # match the tree/* glob. 77238423Sjhb echo "foo" > $NEW/tree/add 78238423Sjhb for i in $OLD $TEST; do 79238423Sjhb echo "old" > $i/tree/modify 80238423Sjhb done 81238423Sjhb echo "new" > $NEW/tree/modify 82238423Sjhb for i in $OLD $TEST; do 83238423Sjhb echo "old" > $i/tree/remove 84238423Sjhb done 85238423Sjhb 86238423Sjhb # rmdir: Remove a whole tree. 87238423Sjhb for i in $OLD $TEST; do 88238423Sjhb mkdir $i/rmdir 89238423Sjhb echo "foo" > $i/rmdir/file 90238423Sjhb done 91238423Sjhb} 92238423Sjhb 93238423Sjhb# $1 - relative path to file that should be missing from TEST 94238423Sjhbmissing() 95238423Sjhb{ 96238423Sjhb if [ -e $TEST/$1 -o -L $TEST/$1 ]; then 97238423Sjhb echo "File $1 should be missing" 98238423Sjhb fi 99238423Sjhb} 100238423Sjhb 101238423Sjhb# $1 - relative path to file that should be present in TEST 102238423Sjhbpresent() 103238423Sjhb{ 104238423Sjhb if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then 105238423Sjhb echo "File $1 should be present" 106238423Sjhb fi 107238423Sjhb} 108238423Sjhb 109238423Sjhb# $1 - relative path to file that should be a directory in TEST 110238423Sjhbdir() 111238423Sjhb{ 112238423Sjhb if ! [ -d $TEST/$1 ]; then 113238423Sjhb echo "File $1 should be a directory" 114238423Sjhb fi 115238423Sjhb} 116238423Sjhb 117238423Sjhb# $1 - relative path to regular file that should be present in TEST 118238423Sjhb# $2 - optional string that should match file contents 119238423Sjhb# $3 - optional MD5 of the flie contents, overrides $2 if present 120238423Sjhbfile() 121238423Sjhb{ 122238423Sjhb local contents sum 123238423Sjhb 124238423Sjhb if ! [ -f $TEST/$1 ]; then 125238423Sjhb echo "File $1 should be a regular file" 126238423Sjhb elif [ $# -eq 2 ]; then 127238423Sjhb contents=`cat $TEST/$1` 128238423Sjhb if [ "$contents" != "$2" ]; then 129238423Sjhb echo "File $1 has wrong contents" 130238423Sjhb fi 131238423Sjhb elif [ $# -eq 3 ]; then 132238423Sjhb sum=`md5 -q $TEST/$1` 133238423Sjhb if [ "$sum" != "$3" ]; then 134238423Sjhb echo "File $1 has wrong contents" 135238423Sjhb fi 136238423Sjhb fi 137238423Sjhb} 138238423Sjhb 139238423Sjhb# $1 - relative path to a regular file that should have a conflict 140238423Sjhb# $2 - optional MD5 of the conflict file contents 141238423Sjhbconflict() 142238423Sjhb{ 143238423Sjhb local sum 144238423Sjhb 145238423Sjhb if ! [ -f $CONFLICTS/$1 ]; then 146238423Sjhb echo "File $1 missing conflict" 147238423Sjhb elif [ $# -gt 1 ]; then 148238423Sjhb sum=`md5 -q $CONFLICTS/$1` 149238423Sjhb if [ "$sum" != "$2" ]; then 150238423Sjhb echo "Conflict $1 has wrong contents" 151238423Sjhb fi 152238423Sjhb fi 153238423Sjhb} 154238423Sjhb 155238423Sjhb# $1 - relative path to a regular file that should not have a conflict 156238423Sjhbnoconflict() 157238423Sjhb{ 158238423Sjhb if [ -f $CONFLICTS/$1 ]; then 159238423Sjhb echo "File $1 should not have a conflict" 160238423Sjhb fi 161238423Sjhb} 162238423Sjhb 163238423Sjhbif [ `id -u` -ne 0 ]; then 164238423Sjhb echo "must be root" 165238423Sjhbfi 166238423Sjhb 167238423Sjhbif [ -r /etc/etcupdate.conf ]; then 168238423Sjhb echo "WARNING: /etc/etcupdate.conf settings may break some tests." 169238423Sjhbfi 170238423Sjhb 171238423Sjhb# First run the test ignoring no patterns. 172238423Sjhb 173238423Sjhbbuild_trees 174238423Sjhb 175238423Sjhbetcupdate -r -d $WORKDIR -D $TEST > $WORKDIR/test.out 176238423Sjhb 177238423Sjhbcat > $WORKDIR/correct.out <<EOF 178238423Sjhb D /rmdir/file 179238423Sjhb D /tree/remove 180238423Sjhb D /rmdir 181238423Sjhb U /tree/modify 182238423Sjhb A /tree/add 183238423SjhbEOF 184238423Sjhb 185238423Sjhbecho "Differences for regular:" 186238423Sjhbdiff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out 187238423Sjhb 188238423Sjhbmissing /tree/remove 189238423Sjhbfile /tree/modify "new" 190238423Sjhbfile /tree/add "foo" 191238423Sjhbmissing /rmdir/file 192238423Sjhbmissing /rmdir 193238423Sjhb 194238423Sjhb# Now test with -I '/tree/*'. This should preserve the /tree files. 195238423Sjhb 196238423Sjhbbuild_trees 197238423Sjhb 198238423Sjhbetcupdate -r -I '/tree/*' -d $WORKDIR -D $TEST > $WORKDIR/test1.out 199238423Sjhb 200238423Sjhbcat > $WORKDIR/correct1.out <<EOF 201238423Sjhb D /rmdir/file 202238423Sjhb D /rmdir 203238423SjhbEOF 204238423Sjhb 205238423Sjhbecho "Differences for -I '/tree/*':" 206238423Sjhbdiff -u -L "correct" $WORKDIR/correct1.out -L "test" $WORKDIR/test1.out 207238423Sjhb 208238423Sjhbfile /tree/remove "old" 209238423Sjhbfile /tree/modify "old" 210238423Sjhbmissing /tree/add 211238423Sjhbmissing /rmdir/file 212238423Sjhbmissing /rmdir 213238423Sjhb 214238423Sjhb# Now test with two patterns. This should preserve everything. 215238423Sjhb 216238423Sjhbbuild_trees 217238423Sjhb 218238423Sjhbetcupdate -r -I '/tree/*' -I '/rmdir*' -d $WORKDIR -D $TEST > \ 219238423Sjhb $WORKDIR/test2.out 220238423Sjhb 221238423Sjhbcat > $WORKDIR/correct2.out <<EOF 222238423SjhbEOF 223238423Sjhb 224238423Sjhbecho "Differences for -I '/tree/*' -I '/rmdir*':" 225238423Sjhb 226238423Sjhbdiff -u -L "correct" $WORKDIR/correct2.out -L "test" $WORKDIR/test2.out 227238423Sjhb 228238423Sjhbfile /tree/remove "old" 229238423Sjhbfile /tree/modify "old" 230238423Sjhbmissing /tree/add 231238423Sjhbfile /rmdir/file "foo" 232238423Sjhb 233238423Sjhb# Now test with a pattern that should cause a warning on /rmdir by 234238423Sjhb# only ignoring the files under that directory. Note that this also 235238423Sjhb# tests putting two patterns into a single -I argument. 236238423Sjhb 237238423Sjhbbuild_trees 238238423Sjhb 239238423Sjhbetcupdate -r -I '/tree/* /rmdir/*' -d $WORKDIR -D $TEST > \ 240238423Sjhb $WORKDIR/test3.out 241238423Sjhb 242238423Sjhbcat > $WORKDIR/correct3.out <<EOF 243238423SjhbWarnings: 244238423Sjhb Non-empty directory remains: /rmdir 245238423SjhbEOF 246238423Sjhb 247238423Sjhbecho "Differences for -I '/tree/* /rmdir/*':" 248238423Sjhb 249238423Sjhbdiff -u -L "correct" $WORKDIR/correct3.out -L "test" $WORKDIR/test3.out 250238423Sjhb 251238423Sjhbfile /tree/remove "old" 252238423Sjhbfile /tree/modify "old" 253238423Sjhbmissing /tree/add 254238423Sjhbfile /rmdir/file "foo" 255238423Sjhbdir /rmdir 256