#! /bin/sh
#
# $Id: makedat.in,v 1.2 1999/10/11 01:22:13 mrsam Exp $
#
# Generic wrapper for makedat.
#
# Usage: makedat.sh -src=src -file=file -tmp=tmpfile -hup=hupfile
#
# Create [file] from [src].  [src] can be either a plain text file, or a
# directory. [tmpfile] is used.  if [hupfile] is specified and it exists,
# this file contains a PID, which is SIGHUPed.

prefix="/usr";
exec_prefix="/usr";

srcfile=""
dstfile=""
tmpfile=""
hupfile=""

usage() {
	echo "Usage: $0 -src=src -file=file -tmp=tmpfile -hup=hupfile" >&2
	exit 1
}

while test $# -gt 0
do
	case $1 in
	-src=*)
		srcfile=`echo "$1" | sed 's/-src=//'`;
		shift
		;;
	-tmp=*)
		tmpfile=`echo "$1" | sed 's/-tmp=//'`;
		shift
		;;
	-file=*)
		dstfile=`echo "$1" | sed 's/-file=//'`;
		shift
		;;
	-hup=*)
		hupfile=`echo "$1" | sed 's/-hup=//'`;
		shift
		;;
	*)
		usage
		;;
	esac
done

if test "$dstfile" = ""
then
	usage
fi

if test "$srcfile" = ""
then
	usage
fi

if test "$tmpfile" = ""
then
	usage
fi


get_access() {

	if test -d "$srcfile"
	then
		for f in "$srcfile"/*
		do
			cat "$f" || return
		done
	else
		cat "$srcfile" || return
	fi
	echo "."
}

get_access | /usr/bin/makedat -dot - "$tmpfile" "$dstfile" || exit 1

if test "$hupfile" != ""
then
	if test -f $hupfile
	then
		kill -HUP `cat "$hupfile"`
	fi
fi
