#!/bin/bash blockSize=512 small=file-small smallCount=750001 large=file-large largeCount=1000000 numTests=10 printf "Enter your username: " read username printf "Enter your password: " stty -echo read password stty echo echo ((smallSize=$smallCount*$blockSize)) ((largeSize=$largeCount*$blockSize)) if [[ ! -f $small ]] || [[ $(stat -c '%s' $small) -ne $smallSize ]] then echo "Creating $small" dd if=/dev/urandom of=$small count=$smallCount fi if [[ ! -f $large ]] || [[ $(stat -c '%s' $large) -ne $largeSize ]] then echo "Creating $large" dd if=/dev/urandom of=$large count=$largeCount fi rm -f vsftpd-test compFiles() { one=$1; shift; two=$1 if [[ ! -f "$one" ]] && [[ ! -p "$one" ]] then echo "File $one does not exist."; return 1 fi if [[ ! -f "$two" ]] && [[ ! -p "$two" ]] then echo "File $two does not exist."; return 1 fi read hash2 name2 < <( nice md5sum $two ) # read second file first 'cause it might be a fifo read hash1 name1 < <( nice md5sum $one ) if [[ "$hash1" == "$hash2" ]] then printf "PASS: FILES %s and %s ARE THE SAME\n" $name1 $name2 return 0 else printf "FAIL: FILES %s and %s ARE NOT THE SAME\n" $name1 $name2 printf "MD1 %s AND MD2 %s\n" $hash1 $hash2 return 1 fi } uploadFile() { echo "S $@: `date`" nice curl -s -T $1 --user $username:$password ftp://localhost/vsftpd-test echo "E $@: `date`" } appendFile() { echo "S $@: `date`" nice curl -s -a -T $1 --user $username:$password ftp://localhost/vsftpd-test echo "E $@: `date`" } i=0 while [[ $i -lt $numTests ]] do printf "\nTEST: Same file\n" uploadFile $small ONE & sleep 2 # sometimes 2nd curl won race to write first...need 1st to win for test uploadFile $small TWO ls -l $small vsftpd-test compFiles $small vsftpd-test || exit 1 rm -f vsftpd-test printf "\nTEST: First file is smaller than the second\n" uploadFile $small ONE & sleep 2 uploadFile $large TWO ls -l $small $large vsftpd-test compFiles $large vsftpd-test || exit 1 rm -f vsftpd-test printf "\nTEST: First file is larger than the second\n" uploadFile $large ONE & sleep 2 uploadFile $small TWO ls -l $large $small vsftpd-test compFiles $small vsftpd-test || exit 1 rm -f vsftpd-test printf "\nTEST: Same file in append mode\n" appendFile $small ONE & sleep 2 appendFile $small TWO ls -l $small vsftpd-test compFiles $small <(nice dd if=vsftpd-test count=$smallCount) || exit 1 compFiles $small <(nice dd if=vsftpd-test skip=$smallCount) || exit 1 rm -f vsftpd-test printf "\nTEST: First file is smaller than the second in append mode\n" appendFile $small ONE & sleep 2 appendFile $large TWO ls -l $small $large vsftpd-test compFiles $small <(nice dd if=vsftpd-test count=$smallCount) || exit 1 compFiles $large <(nice dd if=vsftpd-test skip=$smallCount) || exit 1 rm -f vsftpd-test printf "\nTEST: First file is larger than the second in append mode\n" appendFile $large ONE & sleep 2 appendFile $small TWO ls -l $large $small vsftpd-test compFiles $large <(nice dd if=vsftpd-test count=$largeCount) || exit 1 compFiles $small <(nice dd if=vsftpd-test skip=$largeCount) || exit 1 rm -f vsftpd-test ((i++)) done echo "--------------- ALL TESTS PASSED -------------------"