#!/bin/sh
#
# How to use this test
# --------------------
#
# * Get a working Windows OS on your network
# * Set the proper environment variables for WIN32_xx at the end
#   of your regress/config file
# * Install strawberry perl version with msi
#   http://www.bareos.org/downloads/depkgs-mingw32/strawberry-perl-5.10.1.0.msi
# * Install the latest version of Bareos FD
# * Copy or make accessible (Network share, VirtualBox share)
#     regress/scripts/regress-win32.pl
# * Execute the script on the Windows box
#     perl regress-win32.pl
#   Note, this is a server so the script just waits for Bareos
#     to run and connect to it.
# * Create c:\regress\test on the Windows machine
# * Allow ports through the Win firewall for perl 8091 and bareos-fd 9102
# * If you put bareos binaries in release32 and release64, the script will
#   update binaries
# * Run win32-fd-test regression
#
TestName="win32-fd-test"
JobName=win32
. scripts/functions

scripts/cleanup
scripts/copy-test-confs
cp scripts/win32-bareos-dir.conf bin/bareos-dir.conf

change_jobname NightlySave $JobName
start_test

URL=http://$WIN32_ADDR:8091
echo "Doing wgets ..."
wget -qO $tmp/stop.log "$URL/stop"
wget -qO $tmp/update.log "$URL/set_director_name?name=$HOST-dir;pass=$WIN32_PASSWORD"
wget -qO $tmp/start.log "$URL/start"

wget -qO $tmp/init1.log "$URL/init_attrib_test?source=$WIN32_FILE"
wget -qO $tmp/init2.log "$URL/init_weird_runscript_test?source=$WIN32_FILE"
wget -qO $tmp/clean.log "$URL/cleandir?source=$WIN32_FILE/restore"

# try to upgrade win32 binaries
update_win32

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@output
messages
@$out ${cwd}/tmp/log1.out
status client=$WIN32_CLIENT
label storage=File volume=TestVolume001
run job=$JobName storage=File yes
wait
messages
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=$WIN32_FILE/restore select all done storage=File
yes
wait
messages
@$out ${cwd}/tmp/log3.out
@#
@# make some runscript tests
@#
run job=RunScript storage=File yes
wait
messages
@$out ${cwd}/tmp/log4.out
@#
@# make some accurate tests
@#
run job=AccurateJob storage=File yes
wait
messages
@output
quit
END_OF_DATA

run_bareos
check_for_zombie_jobs storage=File
stop_bareos

check_two_logs

DST=`echo $WIN32_FILE | sed 's!:!!'`

# Compare original and restored directories
wget -qO $tmp/1.log "$URL/compare?source=$WIN32_FILE/attrib_test;dest=$WIN32_FILE/restore/$DST/attrib_test"
print_debug `cat $tmp/1.log`
rstat=0
grep OK $tmp/1.log > /dev/null
if [ $? != 0 ]; then
    rstat=1
fi

# Compare with some weird files
wget -qO $tmp/2.log "$URL/compare?source=$WIN32_FILE/weird_runscript;dest=$WIN32_FILE/restore/$DST/weird_runscript"
print_debug `cat $tmp/2.log`

grep OK $tmp/2.log > /dev/null
if [ $? != 0 ]; then
    rstat=2
fi

dstat=0
end_test
