#!/usr/bin/bash -e

# Purpose: Script used by beakerlib role to save a file to standard-test-roles artifacts
# the file is saved under test case name
#
# The script expects $STR_BKR_TEST and $STR_ARTIFACTS_DIR variables to be set
# This script should be called passing the file as parameter: str-beakerlib-submit-log <$file>
# File path could be full path or relative path to where beakerlib functions (rlFileSubmit and rlBundleLogs) are called

source /usr/share/beakerlib/beakerlib.sh

if [ -z "$STR_BKR_TEST" ] || [ -z "$STR_ARTIFACTS_DIR" ]; then
    rlLogError "STR_BKR_TEST and STR_ARTIFACTS_DIR are required by $0"
    exit 1
fi

rlLogInfo "Copying $2 to ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST}"

if [[ ! -d ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST} ]];then
    mkdir -p ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST}
fi

cp -f "${2}" ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST}/
