#!/bin/sh -
#
# @(#)mk-afs-wrap-qdaemon	1.3 (hursley) 11/1/96
# /afs/hursley.ibm.com/common/src/afs/@cell/rs_aix32/usr/local/sbin/mk-afs-wrap-qdaemon/SCCS/s.mk-afs-wrap-qdaemon
#
# NAME		mk-afs-wrap-qdaemon
# AUTHOR	Paul Blackburn <mpb@acm.org>
# PURPOSE	Wrapper to get AFS authentication and then start qdaemon.
#
# USAGE		After mk-afs-odmfix-qdaemon has changed the qdaemon invocation
#		for srcmstr (in the AIX ODM),  normal srcmstr commands
#               to be used to stop and start the AFS authenticated qdaemon
#		daemon via mk-afs-wrap-qdaemon
#
#		    stopsrc -s qdaemon
#		    startsrc -s qdaemon
#
# CAUTION	Do not attempt to use the mk-afs-wrap-qdaemon wrapper program
#		unless you have:
#		a) a working reauth installed (eg: /usr/etc/mk-afs-reauth)
#		b) configured mk-afs-wrap-qdaemon to authenticate as an AFS ID
#		   (eg qdaemon) authorised to read files in $HOMEs
#		c) Set an ACL on $HOMEs to allow read access
#		   (eg: fs sa $HOME qdaemon rl)
#
#		See: ftp://grand.central.org:/pub/afs-contrib/tools/reauth

CMD=`basename ${0}`
LOGDIR=/var/log
LOG=${LOGDIR}/${CMD}

# functions

tstamp() {
	echo "`date '+''%H''%M'':%S'` ${CMD}: ${1}"
}

warning() {
	echo "${CMD} warning: ${1}" >&2
}

error() {
        echo "${CMD} error: ${1}" >&2
}

fatal() {
        echo "${CMD} fatal: ${1}" >&2
	exit 1
}

doit() {
	tstamp "${1}"
	eval ${1}

	retcode=$?
	if [ ${retcode} != 0 ]; then
		error "\$?=${retcode}"
	fi
}

mkdir -p ${LOGDIR} 2>/dev/null          # make sure we have a LOGDIR

echo "stdout and stderr now being written to ${LOG}"
exec 4>&2
exec 3>&1
exec 1>>${LOG}
exec 2>&1

tstamp "version 1.3 commenced on `date '+%a %d %h %y'`"

WRAPPER=${afs_install_base}/usr/local/sbin/mk-afs-wrapper

if [ ! -x "${WRAPPER}" ]; then
	fatal "unable to execute ${WRAPPER}"
fi

doit "${WRAPPER} -d /etc/qdaemon -id qdaemon -p /etc/security/afs_pw_qdaemon"

tstamp "completed"
