#!/bin/sh
#
# This is a dnscache conf wrapper script for the RPM packaging.
# For each package "A" in the dnscache package, this script runs the
# equivalent "A-conf" program, based on the filename to which this
# script is linked, with the account name set to "A" and the log account
# set to "dnslog".
#

set -e
base=`basename $0 -rhconf`
conf=/usr/bin/$base-conf

if [ $# -lt 1 ]; then
  echo "$0: usage: `basename $0` /dir [args for $base-conf]"
  exit 1
fi

$conf $base dnslog "$@"

dir=`basename "$1"`
log="/var/log/$dir"
cd "$1"
rmdir log/main
mkdir "$log"
chown dnslog.nobody "$log"
cat >log/run <<EOF
#!/bin/sh
exec setuidgid dnslog multilog t "$log"
EOF
chmod 755 log/run
svc-add -d "$1"
echo "Type 'svc-start $dir' to start this instance of $base"
