#!/bin/sh

cfgpath='/etc/ntools/borg'
function usage() {
	echo "${0##*/} <config-file-name>"
	echo
	echo "Use <config-file-name> from '$cfgpath' folder"
	echo "Available config files are:"
	ls "$cfgpath"
	exit 1
}
cfg=$1
if [[ -z $cfg ]]; then
	usage
fi
valid='0-9a-zA-Z_-'
if [[ $cfg =~ [^$valid] ]]; then
	echo "Invalid config name."
	exit 1
fi
cfgfile="$cfgpath/$cfg"
if [[ -f $cfgfile ]]; then
	. $cfgfile
else
	echo "Config file not found."
	exit 1
fi

echo 'export LANG="ru_RU.UTF-8"'

if [[ -n $HOST ]]; then
	echo "export BORG_REPO=\"$HOST:$REPOPATH\"" 
else
	echo "export BORG_REPO=\"$REPOPATH\""
fi


if [[ -n $PASSFN ]]; then
	echo "export BORG_PASSCOMMAND=\"cat $PASSFN\""
fi

if [[ $COMPRESSION != '' ]]; then
	BORGPARAMS="$BORGPARAMS --compression $COMPRESSION"
fi

