#!/usr/bin/env bash
#
# Copyright (C) 2000-2021 Kern Sibbald
# Copyright (C) 2021-2022 Bacula Systems SA
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Run a simple backup of a file with a password in the name
#
TestName="hide-password-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-confs

#
# Zap out any schedule in default conf file so that
#  it doesn't start during our test
#
outf="$tmp/sed_tmp"
echo "s%  Schedule =%# Schedule =%g" >${outf}
cp $scripts/bacula-dir.conf $tmp/1
sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf

f1="$tmp/a/test1 password=secret parameter2=a"

cat <<EOF > $tmp/s1
echo toto > '$f1'
EOF

cat <<EOF > $tmp/r1
cat '$f1'
EOF

cat <<EOF >> $conf/bacula-dir.conf
FileSet {
  Name = "HideSet"
  Include {
    Options {
      signature = MD5
      readfifo = yes
    }
    File = "$f1"
  }
}
EOF

mkdir $tmp/a

mkfifo "$f1"

change_jobname BackupClient1 $JobName
start_test

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0
run job=$JobName fileset=HideSet yes
@sleep 3
status client
@exec "sh $tmp/s1"
wait
messages
@# 
@# now do a restore
@#
@$out $tmp/log2.out  
setdebug level=4 storage=File1
restore where=/ select all done
yes
@sleep 2
status client
@exec "sh $tmp/r1"
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File1
stop_bacula

check_two_logs
end_test
