#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

#
# Run a simple backup of the Bacula build directory
#   then restore it.
#
TestName="lib-test-root"
. scripts/functions

require_root


scripts/cleanup
scripts/copy-test-confs
echo "/lib" >${cwd}/tmp/file-list

start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File
TestVolume001
run job=NightlySave
yes
wait
messages
@# 
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bacula-restores select    
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File
stop_bacula

# more cleanup to be done below

cd /
${cwd}/bin/testls -e ${cwd}/scripts/exclude-lib-test lib >${cwd}/tmp/original
cd ${cwd}/tmp/bacula-restores
${cwd}/bin/testls -e ${cwd}/scripts/exclude-lib-test lib >${cwd}/tmp/restored
cd ${cwd}/tmp
sed s%.*lib/kbd/consolefonts$%lib/kbd/consolefonts% original >1
sort <1 >original
#
sed s%.*lib/kbd/consolefonts$%lib/kbd/consolefonts% restored >1
sort <1 >restored
rm -f 1
#
cd ${cwd}
diff ${cwd}/tmp/original ${cwd}/tmp/restored 2>&1 1>/dev/null
if [ $? != 0 ] ; then
   echo " "
   echo " "
   echo "  ===== !!!! lib-test-root failed !!!! ===== "
   echo "  ===== !!!! lib-test-root failed !!!! ===== " >>test.out
   echo " "
else
   echo "  ===== lib-test-root OK ===== "
   echo "  ===== lib-test-root OK ===== " >>test.out
   scripts/cleanup
fi
