#!/bin/bash
#
#
# This is a simplified version of the ypbind start script that does not
# require the local machine to have a domain name set.  
#

OTHER_YPBIND_OPTS="-p 660"

# Source function library.
. /etc/init.d/functions

. /etc/sysconfig/network

start() {
	DOMAINNAME=`domainname`
	if [ "$DOMAINNAME" = "(none)" -o "$DOMAINNAME" = "" ]; then
	   if [ -z "$NISDOMAIN" ]; then
	        # if no domain set, use bogus one so ypbind will start
	        export NISDOMAIN=default.invalid
	   fi
	   action $"Setting NIS domain name $NISDOMAIN: " domainname $NISDOMAIN
	fi
	export LD_PRELOAD=/usr/spinmgmt/lib/libbindresvport.so
	echo -n $"Starting NIS services (ypbind): "

	# log anything on port 660 for debugging
	initlog --cmd='lsof -i :660'

	daemon ypbind $OTHER_YPBIND_OPTS
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
	    touch /var/lock/subsys/ypbind
	else
	    failure "starting ypbind"
	    kill $pid
	fi
	echo
	return $RETVAL
}

stop() {
	echo -n $"Shutting down NIS services (ypbind): "
	killproc ypbind
	RETVAL=$?
	if [ $RETVAL -eq 0 ] ; then
	  rm -f /var/lock/subsys/ypbind
	  # if  we used brute force (like kill -9) we don't want those around
	  if [ x$(domainname) != x ] ; then
	    rm -f /var/yp/binding/$(domainname)*
	  fi
	fi
	echo
	return $RETVAL
}

restart() {
	stop
	start
}

RETVAL=0

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status ypbind
	;;
  restart|reload)
	restart
	;;
  condrestart)
        [ -f /var/lock/subsys/ypbind ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart}"
	exit 1
esac

exit $?
