#!/bin/sh

prefix=/usr
exec_prefix=/usr
serverdatadir=/usr/share/jnbackup/server
serverconfdir=/etc/jnbackup/server
servervardir=/var/lib/jnbackup/server
bindir=/usr/bin
SSH=/usr/bin/ssh
SSHFLAGS="-T -1"
TIME=/usr/bin/time
VERSION=0.5
client_user=backupc
server_user=backups

. ${serverdatadir}/functions

if [ "`id -nu`" != ${server_user} ] ; then
	exec su - backups -c "${bindir}/backups $*"
	exit 1
fi

echo "Jajcus' Net Backup Server ${VERSION}" >&2

if [ -z "$1" -o -z "$2" ] ; then
	usage
	exit 1
fi

if [ "$1" != "test" -a "$1" != backup ] ; then
	usage
	exit 1
fi

ACTION=$1
PROFILE=$2

if [ ! -f "${serverconfdir}/profiles/$PROFILE" ] ; then
	echo "No such backup profile: $PROFILE" >&2
fi

gen_backupid

cat "${serverconfdir}/profiles/$PROFILE" | grep -v "^#" | \
while read CLIENT BACKUP BACKUPLEVEL; do
	if [ -n "$CLIENT" ] ; then
		case $ACTION in 
			backup|test)
				do_backup
				;;
		esac
	fi
done 

exit 0
