1#!/bin/bash 2 3cd / 4 5DEVICE=0,0,0 6MNTDEV=/dev/scd0 7 8BKDIR=/tmp/cdbkup-test-suite 9 10prefix=/usr 11exec_prefix=${prefix} 12sbindir=${exec_prefix}/sbin 13cdbkup=$sbindir/cdbkup 14cdrstr=$sbindir/cdrstr 15gnutar=/bin/tar 16 17function checksum () { 18 md5sum * */* */*/* */*/*/* 2>/dev/null | sort | md5sum 19} 20 21function setup_input () { 22 rm -rf $BKDIR 23 mkdir $BKDIR 24 pushd $BKDIR 25 26 mkdir input 27 mkdir input/subdir 28 mkdir input/s 29 mkdir input/s/s 30 echo Test File > input/s/s/file1 31 perl -e 'print $i while(++$i)' | 32 dd bs=1024 count=1024 >input/bigfile 2>/dev/null 33 echo Another test file > input/subdir/file2 34 echo Another subdir-test file > input/subdir/file-to-delete 35 echo Yet another test file > input/file3 36 chmod u+x input/file3 37 ln -s bigfile input/link-bigfile 38 ln -s non-file input/broken-link 39 40 cd input 41 PREMOD_CKSUM=`checksum` 42 43 popd 44} 45 46function modify_input () { 47 pushd $BKDIR 48 49 perl -e 'print $i while(++$i)' | dd bs=1024 count=2048 \ 50 > "input/subdir/big file with spaces in its name" 2>/dev/null 51 touch input/subdir/file2 52 rm input/subdir/file-to-delete 53 54 cd input 55 POSTMOD_CKSUM=`checksum` 56 57 popd 58} 59 60function warn () { 61 echo "Please insert a CD-RW into device $MNTDEV. All of its" 1>&2 62 echo "current contents will be erased. Press Enter to continue." 1>&2 63 read 64} 65 66function clean_up () { 67 rm -rf $BKDIR 68} 69 70if [ "$1" ]; then echo "*** Test Phase: $1" 1>&2; fi 71 72case $1 in 73 74'') 75 $0 nocd 76 $0 exclude 77 $0 lengths 78 $0 create-cdrw && # verify-cdrw depends on create-cdrw succeeding. 79 $0 verify-cdrw 80 ;; 81 82nocd) 83 setup_input 84 85 pushd $BKDIR 86 87 $cdbkup 0 -t --label=cdbkup-test-suite $DEVICE $BKDIR/input 2>&1 88 result=cdbkup-test-suite-`/bin/date +%Y-%m-%d`-0.tar.gz 89 90 if [ ! -f $result ]; then 91 echo Backup File Not Created 1>&2 92 exit 1; 93 fi 94 95 mkdir output 96 cd output 97 $gnutar xfz ../$result 2>&1 98 99 if [ `checksum` != $PREMOD_CKSUM ]; then 100 echo Incorrect fileset when using tar 1>&2 101 exit 1; 102 fi 103 104 cd .. 105 rm -rf output 106 107 modify_input 108 109 $cdbkup 3 --no-iso --test -l cdbkup-test-suite \ 110 -S 696320 $DEVICE $BKDIR/input 2>&1 111 112 mkdir output 113 114 (echo;echo 1) | $cdrstr -t output 2>&1 115 116 cd output 117 118 if [ `checksum` != $PREMOD_CKSUM ]; then 119 echo Incorrect fileset when using cdrstr 1>&2 120 exit 1; 121 fi 122 123 cd .. 124 125 (echo;echo 2;echo;echo q) | $cdrstr -t output 2>&1 126 127 cd output 128 if [ `checksum` != $POSTMOD_CKSUM ]; then 129 echo Final backup has incorrect checksum 1>&2 130 exit 1; 131 fi 132 133 cd .. 134 rm -rf output 135 136 $cdbkup 3 --test -l cdbkup-test-suite \ 137 -S 14899199 $DEVICE $BKDIR/input 2>&1 138 139 mkdir output 140 141 (echo;echo 1) | $cdrstr -t output 2>&1 142 143 mkdir mnt1 144 mkdir mnt2 145 if ! mount -o loop cdbkup-test-suite-*-3.tar.gz.1.iso mnt1; then 146 echo "Can't mount ISO images for testing." 1>&2 147 exit 1; 148 fi 149 mount -o loop cdbkup-test-suite-*-3.tar.gz.2.iso mnt2 150 151 cd output 152 153 cat ../mnt1/* ../mnt2/* | $gnutar -f - -xz --incremental 2>&1 154 155 umount ../mnt1 156 umount ../mnt2 157 158 if [ `checksum` != $POSTMOD_CKSUM ]; then 159 echo Incorrect fileset based on ISO images 1>&2 160 exit 1; 161 fi 162 163 popd 164 165 clean_up 166 167 ;; 168 169exclude) 170 setup_input 171 172 pushd $BKDIR 173 174 $cdbkup 0 -t -e $BKDIR/input/subdir --exclude=$BKDIR/input/file3 \ 175 --label=cdbkup-test-suite $DEVICE $BKDIR/input 2>&1 176 177 cd input 178 rm -rf subdir file3 179 EXCLUDE_CKSUM=`checksum` 180 cd .. 181 182 mkdir output 183 184 (echo;echo 1) | $cdrstr -t output 2>&1 185 186 if [ -e output/subdir ]; then 187 echo Exclusion of subdirectory failed. 1>&2 188 exit 1; 189 fi 190 191 if [ -e output/file3 ]; then 192 echo Exclusion of file failed. 1>&2 193 exit 1; 194 fi 195 196 cd output 197 if [ `checksum` != $EXCLUDE_CKSUM ]; then 198 echo Exclusion broke something else. 1>&2 199 exit 1; 200 fi 201 202 popd 203 204 clean_up 205 206 ;; 207 208create-cdrw) 209 warn 210 211 setup_input 212 213 pushd $BKDIR 214 215 yes '' | $cdbkup 0 -c bz2 -b --label=cdbkup-test-suite \ 216 $DEVICE $BKDIR/input 2>&1 217 218 if [ -x /usr/bin/eject ]; then eject $MNTDEV; fi 219 220 modify_input 221 222 yes '' | $cdbkup 3 -l cdbkup-test-suite $DEVICE $BKDIR/input 2>&1 223 224 if [ -x /usr/bin/eject ]; then eject $MNTDEV; fi 225 226 popd 227 228 ;; 229 230verify-cdrw) 231 232 # Make sure we know the proper checksums 233 if [ "$POSTMOD_CKSUM" == '' ]; then 234 setup_input 235 modify_input 236 fi 237 238 pushd $BKDIR 239 240 mkdir output 241 (echo;echo 1) | cdrstr -c bz2 -d $MNTDEV output 2>&1 242 243 cd output 244 if [ `checksum` != $PREMOD_CKSUM ]; then 245 echo Burn of level 0 to CD-ROM produced incorrect checksum 1>&2 246 exit 1; 247 fi 248 cd .. 249 250 (echo;echo 2) | cdrstr -c gz -d $MNTDEV output 2>&1 251 252 cd output 253 if [ `checksum` != $POSTMOD_CKSUM ]; then 254 echo Burn of level 3 to CD-ROM produced incorrect checksum 1>&2 255 exit 1; 256 fi 257 cd .. 258 259 popd 260 261 clean_up 262 263 ;; 264 265lengths) 266 267 setup_input 268 269 pushd $BKDIR 270 271 filesize=152007 272 273 $cdbkup 0 -c none -t -S $filesize --no-iso --label=cdbkup-test-suite \ 274 $DEVICE $BKDIR/input 2>&1 275 276 if [ `wc -c < *.1` != $filesize ]; then 277 echo Incorrect file size 1>&2 278 exit 1; 279 fi 280 281 mkdir output 282 cd output 283 cat ../cdbkup-test-suite-* | $gnutar xf - 284 285 if [ `checksum` != $PREMOD_CKSUM ]; then 286 echo -t,-S,-I produced incorrect checksum 1>&2 287 exit 1; 288 fi 289 cd .. 290 291 rm -rf output 292 293 $cdbkup 0 -c none -t -S 14815233 --label=cdbkup-test-suite $DEVICE $BKDIR/input 2>&1 294 295 mkdir mnt 296 if ! mount -o loop cdbkup-test-suite-*.tar.1.iso mnt; then 297 echo "Can't mount ISO images for testing." 1>&2 298 exit 1; 299 fi 300 301 if [ `wc -c < mnt/*` != 614400 ]; then 302 umount mnt 303 echo Incorrect file size 1>&2 304 exit 1; 305 fi 306 307 umount mnt 308 309 clean_up 310 311 ;; 312 313esac 314 315if [ "$1" ]; then echo "*** Success!" 1>&2; fi 316