#!/bin/bash

. ${TOOLKIT}-functions.sh


# (MAIN)

# this is missing from veeam packages
#
enable_service veeamservice

# FIRST RUN?
#
# - install our custom cfg file
# - create default repository
# - create default job
#
file="ku-veeam.cfg"

# instead of automatically install our config file (from 'install' file)
# we install it manually, so we can use his existence to know if it is
# a fresh veeam installation
#
if [ -f /etc/veeam/$file ]
then
	# exists, but we install it anyway (needs to keep updated)
	installfile $file /etc/veeam/ root:root 660
else
	# do not exists, is a fresh veeam installation
	installfile $file /etc/veeam/ root:root 660

	echo -e "\n\tYOU NEED TO ACCEPT VEEAM LICENCE BEFORE PROCEED\n"
	confirm
	veeam
fi

# create / update default_repo and job
#
repo_name=$(jtconf veeam-repo.repo_name)
veeamconfig repository list | grep -q "^$repo_name\s" || {
	echo -e "\nmissing default repo '$repo_name', creating ...\n"

	veeam_create_default_repo
	veeam_create_default_job
}


# cleanup
#
uninstallfiles --remove \
	/usr/sbin/veeam_add_default_job \
	/usr/sbin/veeam_run_default_job


$SOMETHING_CHANGED && {
	restart_service veeamservice veeamservice
}

exit 0
