#!/bin/ksh
#
# OSSTech Samba smbd
#
# chkconfig: - 91 35
# chkconfig.solaris: 3 90 03
# chkconfig.aix: 2 390 03
# chkconfig.debian: 2345 20 19
# description: Starts and stops the Samba smbd daemons \
#	       used to provide SMB/CIFS network service.
#
### BEGIN INIT INFO
# Provides:		osstech-smb
# Required-Start:	$network $local_fs $remote_fs osstech-svscan
# Required-Stop:	$network $local_fs $remote_fs osstech-svscan
# Should-Start:		$syslog osstech-nmb osstech-winbind osstech-ldap slapd
# Should-Stop:		$syslog osstech-nmb osstech-winbind osstech-ldap slapd
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
### END INIT INFO

. /etc/init.d/svinit || exit $?

sv_name="smbd"

if [[ -x /opt/osstech/bin/samba-tool && -e /opt/osstech/etc/samba/smb.conf ]]; then
  server_role=$(/opt/osstech/bin/samba-tool testparm --parameter-name="server role" 2>/dev/null |tail -n1)
  if [[ "$server_role" == "active directory domain controller" ]]; then
    echo "If server role is 'active directory domain controller'," 1>&2
    echo "we DO NOT start '$sv_name' service." 1>&2
    if [[ "$1" == restart ]]; then
      shift
      set -- stop "$@"
    elif [[ "$1" == start ]]; then
      exit 0
    fi
  fi
fi

function sv_reload {
  sv_hangup "$1" "Reloading"
}

sv_init "$sv_name" ${1+"$@"}
