#!/bin/bash

#   BAREOS® - Backup Archiving REcovery Open Sourced
#
#   Copyright (C) 2020-2025 Bareos GmbH & Co. KG
#
#   This program is Free Software; you can redistribute it and/or
#   modify it under the terms of version three of the GNU Affero General Public
#   License as published by the Free Software Foundation and included
#   in the file LICENSE.
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#   Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
#   02110-1301, USA.

set -e
set -o pipefail
set -u

TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-s3-fd

#shellcheck source=../../environment.in
. ./environment

#shellcheck source=../../scripts/functions
. "${BAREOS_SCRIPTS_DIR}"/functions

setup_data

start_test

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out ${NULL_DEV}
messages
@$out $tmp/backup.log
setdebug level=100 storage=droplet
label volume=TestVolume001 storage=droplet pool=Full
run job=$JobName yes
status director
status client
status storage=droplet
wait
messages
quit
END_OF_DATA

run_bconsole "$@"
check_for_zombie_jobs storage=droplet

check_log "$tmp/backup.log"

# In case we want to tackle the close_wait issue
#bareos_sd_pid=$(pidof bareos_sd-${TestName})
#if [ $(lsof -p ${bareos_sd_pid} | grep -c "CLOSE_WAIT") -ne 0 ]
#then
#   echo "Error: Connection CLOSE_WAIT found"
#   estat=1
#fi

end_test
