#! /bin/sh

#  /etc/init.d/amd: start and stop the 4.4BSD automouter.
#  Copyright (C) 1996 by Dominik Kubla, <kubla@Uni-Mainz.DE
#
#  $Id$

CONFIGDIR=/etc/amd

# If the package is removed, skip it.
test -x /usr/sbin/amd || exit 0

# If the package is not configured, skip it.
test -f $CONFIGDIR/config || exit 0

# Read the configuration data.
. $CONFIGDIR/config

case "$1" in
  start)
	# If the hostname is not a FQHN, add the -d command line switch,
	# so that hostnames in the maps are stripped correctly.
	case `hostname` in
	*.*)	dnsdomain=""
		;;
	*)	dnsdomain="-d `dnsdomainname`"
		;;
	esac
	# Rotate logfile on startup, if SYSLOG is not used.
	case "$LOGFILE" in
	*/*)	savelog -g adm -m 644 -u root -c 4 "$LOGFILE" >/dev/null
		cp /dev/null "$LOGFILE" 
		;;
	syslog)	# Do nothing
		;;
	esac

	if [ -n "$NISMAP" ]
	then 
	  if [ -n "$NISKEY" ]
	  then
	    AMDARGS=`ypmatch $NISKEY $NISMAP 2>/dev/null`
	  else
	    AMDARGS=`ypcat $NISMAP 2>/dev/null`
	  fi
	else
	  AMDARGS=`cat $CONFIGDIR/amd.master 2>/dev/null`
	fi

	# If we got no master map, abort ...
	if [ -z "$AMDARGS" ]
	then
	  echo "$0: WARNING: Couldn't find master map..."
	  exit 0
	fi

	eval start-stop-daemon --start --verbose --exec /usr/sbin/amd \
	  -- -l $LOGFILE $AMDARGS
	;;

  stop)
	start-stop-daemon --stop --verbose --exec /usr/sbin/amd
	;;

  *)
	echo "Usage: /etc/init.d/amd {start|stop}"
	exit 1
esac

exit 0
