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

daemon=/usr/lpp/info/bin/infod
afs_id=infod
pwfile=/etc/security/afs_pw_infod

doit "${WRAPPER} -d ${daemon} -id ${afs_id} -p ${pwfile}"

tstamp "completed"
