#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# This script is used to test multiple devices grouped in
# the director configuration
#
TestName="multi-drive-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-2disk-confs
scripts/prepare-disk-changer

echo "s/signature=MD5/signature=MD5; readfifo=yes/" > $tmp/1
echo "s/FileStorage/Device = FileStorage; Device=FileStorage2; Device=FileStorage3; Device=FileStorage4/" >> $tmp/1
sed -f $tmp/1 $conf/bacula-dir.conf > $tmp/2 
$bperl -e 'add_attribute("$tmp/2", "Label Format", "Vol", "Pool", "Default")'
$bperl -e 'add_attribute("$tmp/2", "Label Format", "Vol", "Pool", "Inc")'
$bperl -e 'add_attribute("$tmp/2", "SpoolData",    "no",  "Job")'
cp $tmp/2 $conf/bacula-dir.conf

$bperl -e 'add_attribute("$conf/bacula-sd.conf", "Label Media", "yes", "Device")'
$bperl -e 'extract_resource("$conf/bacula-sd.conf", "Device", "FileStorage")' > $tmp/2
for i in 2 3 4; do
    sed "s/FileStorage/FileStorage$i/" $tmp/2 >> $conf/bacula-sd.conf
done

disable_plugins

echo "$cwd/build" >${cwd}/tmp/file-list
echo "$tmp/fifo" >>${cwd}/tmp/file-list

mkfifo $tmp/fifo
(sleep 15 > $tmp/fifo)&

change_jobname $JobName
start_test

# test with autolabel
#
#
# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@output /dev/null
messages
@$out ${cwd}/tmp/log1.out
run level=full job=backup storage=File pool=Default yes
@sleep 3
run level=full job=backup storage=File pool=Default yes
@sleep 3
run level=full job=backup storage=File pool=Inc yes
@sleep 3
messages
status storage=File
status dir
messages
wait
quit
END_OF_DATA

run_bacula

check_for_zombie_jobs storage=File
check_for_zombie_jobs storage=tape
stop_bacula

touch $tmp/log2.out
check_two_logs
#check_restore_diff

end_test
