#!/bin/bash
#
# ::do_not_edit::
# ::maintainer::
#
CMD=$(basename $0)
CMDVER="1.0"
CMDSTR="$CMV v$CMVVER (2025-10-28)"

set -e -u

# (MAIN)

repo_name="default_repo"
default_job="Backup"

veeamconfig repository list | grep -q "^$repo_name\s" && {
	echo "
ERROR

default_repo already exists, you need to remove it
before proceeding, ie running

	veeamconfig job delete --name $default_job
	veeamconfig repository delete --name $repo_name
	" >&2
	exit 1
}


smb_share=$(kusa-conf veeam-repo.smb_share)
smb_user=$(kusa-conf veeam-repo.smb_user)
smb_password=$(kusa-conf veeam-repo.smb_password)
smb_options=$(kusa-conf veeam-repo.smb_options)

opts="username=$smb_user,password=$smb_password"
[ "X$smb_options" != "X" ] && opts="$opts,$smb_options"

echo -e "\n creating repo: $repo_name\n"
veeamconfig repository create --name $repo_name --type smb \
	--location "$smb_share" \
	--options $opts

veeamconfig repository list

exit 0
