#!/bin/sh
#
# Run a simple backup of untitled15.jpg that fails to
#  restore properly in bug #763
#
TestName="encrypt-bug-test"
JobName=Crypto-bug
. scripts/functions

scripts/cleanup
scripts/copy-crypto-confs
echo "${cwd}/encrypt-bug.jpg"   >${cwd}/tmp/file-list
echo "${cwd}/encrypt-bug.jpg"   >${cwd}/tmp/restore-list
echo "${cwd}/encrypt-bug.txt"  >>${cwd}/tmp/file-list
echo "${cwd}/encrypt-bug.txt"  >>${cwd}/tmp/restore-list
echo "${cwd}/encrypt-bug2.txt" >>${cwd}/tmp/file-list
echo "${cwd}/encrypt-bug2.txt" >>${cwd}/tmp/restore-list
files="encrypt-bug.jpg encrypt-bug.txt encrypt-bug2.txt"
mkdir -p ${cwd}/tmp/build
for i in ${files}; do
   cp -p ${cwd}/encrypt-bug*.* ${cwd}/tmp/build
done

change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File volume=TestVolume001
setdebug level=100 fd
run job=$JobName yes
wait
messages
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
setdebug level=100 fd
restore where=${cwd}/tmp/bareos-restores storage=File
5
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bareos
sleep 2
check_for_zombie_jobs storage=File
stop_bareos

#du -s build
#du -s ${cwd}/tmp/bareos-restores/

check_two_logs
diff ${cwd}/tmp/build ${cwd}/tmp/bareos-restores/${cwd} 2>&1 >/dev/null
dstat=$?
end_test
