3 # Copyright (c) 2010 Advanced Computing Technologies LLC
4 # Written by: John H. Baldwin <jhb@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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
30 # Various regression tests to run for the 'resolve' command.
36 echo "Usage: tests.sh [-w workdir]"
40 # Allow the user to specify an alternate work directory.
41 while getopts "w:" option; do
57 CONFLICTS=$WORKDIR/conflicts
62 # These tests deal with conflicts to a single file. For each test, we
63 # generate a conflict in /etc/login.conf. Each resolve option is tested
65 build_login_conflict()
68 rm -rf $OLD $NEW $TEST $CONFLICTS
69 mkdir -p $OLD/etc $NEW/etc $TEST/etc
71 # Generate a conflict in /etc/login.conf.
72 cat > $OLD/etc/login.conf <<EOF
76 cat > $NEW/etc/login.conf <<EOF
79 :copyright=/etc/COPYRIGHT
81 cat > $TEST/etc/login.conf <<EOF
87 etcupdate -r -d $WORKDIR -D $TEST >/dev/null
90 # This is used to verify special handling for /etc/mail/aliases and
91 # the newaliases warning.
92 build_aliases_conflict()
95 rm -rf $OLD $NEW $TEST $CONFLICTS
96 mkdir -p $OLD/etc/mail $NEW/etc/mail $TEST/etc/mail
98 # Generate a conflict in /etc/mail/aliases
99 cat > $OLD/etc/mail/aliases <<EOF
102 # Basic system aliases -- these MUST be present
103 MAILER-DAEMON: postmaster
106 cat > $NEW/etc/mail/aliases <<EOF
109 # Basic system aliases -- these MUST be present
110 MAILER-DAEMON: postmaster
113 # General redirections for pseudo accounts
117 cat > $TEST/etc/mail/aliases <<EOF
118 root: someone@example.com
120 # Basic system aliases -- these MUST be present
121 MAILER-DAEMON: postmaster
125 etcupdate -r -d $WORKDIR -D $TEST >/dev/null
128 # $1 - relative path to file that should be missing from TEST
131 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
132 echo "File $1 should be missing"
136 # $1 - relative path to file that should be present in TEST
139 if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then
140 echo "File $1 should be present"
144 # $1 - relative path to regular file that should be present in TEST
145 # $2 - optional string that should match file contents
146 # $3 - optional MD5 of the flie contents, overrides $2 if present
151 if ! [ -f $TEST/$1 ]; then
152 echo "File $1 should be a regular file"
153 elif [ $# -eq 2 ]; then
154 contents=`cat $TEST/$1`
155 if [ "$contents" != "$2" ]; then
156 echo "File $1 has wrong contents"
158 elif [ $# -eq 3 ]; then
159 sum=`md5 -q $TEST/$1`
160 if [ "$sum" != "$3" ]; then
161 echo "File $1 has wrong contents"
166 # $1 - relative path to a regular file that should have a conflict
167 # $2 - optional MD5 of the conflict file contents
172 if ! [ -f $CONFLICTS/$1 ]; then
173 echo "File $1 missing conflict"
174 elif [ $# -gt 1 ]; then
175 sum=`md5 -q $CONFLICTS/$1`
176 if [ "$sum" != "$2" ]; then
177 echo "Conflict $1 has wrong contents"
182 # $1 - relative path to a regular file that should no longer have a conflict
185 if [ -f $CONFLICTS/$1 ]; then
186 echo "Conflict $1 should be resolved"
190 if [ `id -u` -ne 0 ]; then
194 if [ -r /etc/etcupdate.conf ]; then
195 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
198 # Test each of the following resolve options: 'p', 'mf', 'tf', 'r'.
202 # Verify that 'p' doesn't do anything.
204 echo 'p' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null
206 file /etc/login.conf "" 95de92ea3f1bb1bf4f612a8b5908cddd
207 missing /etc/login.conf.db
208 conflict /etc/login.conf
210 # Verify that 'mf' removes the conflict, but does nothing else.
211 echo "Checking 'mf':"
212 echo 'mf' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null
214 file /etc/login.conf "" 95de92ea3f1bb1bf4f612a8b5908cddd
215 missing /etc/login.conf.db
216 resolved /etc/login.conf
220 # Verify that 'tf' installs the new version of the file.
221 echo "Checking 'tf':"
222 echo 'tf' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null
224 file /etc/login.conf "" 7774a0f9a3a372c7c109c32fd31c4b6b
225 file /etc/login.conf.db
226 resolved /etc/login.conf
230 # Verify that 'r' installs the resolved version of the file. To
231 # simulate this, manually edit the merged file so that it doesn't
232 # contain conflict markers.
234 cat > $CONFLICTS/etc/login.conf <<EOF
236 :passwd_format=md5:\\
237 :copyright=/etc/COPYRIGHT\\
241 echo 'r' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null
243 file /etc/login.conf "" 966e25984b9b63da8eaac8479dcb0d4d
244 file /etc/login.conf.db
245 resolved /etc/login.conf
247 build_aliases_conflict
249 # Verify that 'p' and 'mf' do not generate the newaliases warning.
250 echo "Checking newalias warning for 'p'":
251 echo 'p' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias
252 if [ $? -eq 0 ]; then
253 echo "+ Extra warning"
255 echo "Checking newalias warning for 'mf'":
256 echo 'mf' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias
257 if [ $? -eq 0 ]; then
258 echo "+ Extra warning"
261 # Verify that 'tf' and 'r' do generate the newaliases warning.
262 build_aliases_conflict
263 echo "Checking newalias warning for 'tf'":
264 echo 'tf' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias
265 if [ $? -ne 0 ]; then
266 echo "- Missing warning"
269 build_aliases_conflict
270 cp $TEST/etc/mail/aliases $CONFLICTS/etc/mail/aliases
271 echo 'r' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias
272 if [ $? -ne 0 ]; then
273 echo "- Missing warning"