#!/bin/sh
#
# $Id: client-build.sh,v 1.1 2004-02-25 20:53:34 dan Exp $
#
# Copyright 2003-2004 Dan Langille <dan@langille.org>
#
# Use as you wish, but keep retain this copyright notice.
# Please forward improvements.
#
# See http://www.freebsddiary.org/bacula.php for details.
#
# usage client-build.sh DIRNAME CLIENTNAME [CLIENTNAME...]
#
# Where DIRNAME is the director name which can contact this client
#       CLIENTNAME is the name of the client file daemon
#
# This script creates ./tmp and places all output there.
#
# bacula-fd.conf.in is the template it uses for creating the client scripts.
#


if [ $# -lt 2 ]
then
   echo $0 : usage $0 DIRNAME CLIENTNAME [CLIENTNAME...]
   exit 1
fi

mkdir -p ./tmp

DIRNAME=$1

shift 1

echo creating clients for Director $DIRNAME

echo "# ==== Start of run for $DIRNAME ====" >> ./tmp/bacula-dir.conf

while [ $# -gt 0 ] ; do
	CLIENT=$1
	PASSWORD=`jot -r -c 40 A z | rs -g 0`
	shift
	echo "creating config for " $CLIENT
	sed "s/@dir-name@/$DIRNAME/;s/@dir-password@/$PASSWORD/;s/@client-name@/$CLIENT/" bacula-fd.conf.in  >  ./tmp/$CLIENT-bacula-fd.conf
	sed "s/@dir-name@/$DIRNAME/;s/@dir-password@/$PASSWORD/;s/@client-name@/$CLIENT/" bacula-dir.conf.in >> ./tmp/bacula-dir.conf
done
