#----------------------------------------------------------------------------
# /etc/rc0.d/rc400.samba - shut down samba
#
# Creation:     20.01.2003 knuffel
# Last Update:  $Id: rc400.samba 10458 2005-11-29 17:53:25Z knuffel $
#----------------------------------------------------------------------------
colechobin="/usr/local/bin/colecho"
$colechobin "shutting down samba ..." gn >/dev/console
sambanetsendbin="/bin/samba-netsend"

if [ -f /boot/rc.cfg ]
then
    . /boot/rc.cfg
fi

if [ "$LOCALE" = "de" ]
then
    message="fli4l-samba-server auf `hostname` wird nun heruntergefahren..."
else
    message="fli4l-samba-server on `hostname` is going down now..."
fi

if [ -f "$sambanetsendbin" ]
then
    $sambanetsendbin "all" "$message"
fi

if [ -n "`cat /proc/mounts | grep smbfs`" ]
then
    cd /
    for i in `cat /proc/mounts | grep smbfs | cut -d" " -f2`
    do
      echo "umounting smbfs filesystem in $i..."
      smbumount $i
      if [ "$?" = "0" ]
      then
          $colechobin "smbfs filesystem in $i umounted" gn
      else
          $colechobin "cannot umount smbfs filesystem in $i!" br x br
      fi
    done
fi

for i in smbfs nls_iso8859-1 nls_cp850 nls_iso8859-2 nls_iso8859-5 nls_iso8859-7
do
  nls="$i"
  if [ -n "`lsmod | grep $nls`" ]
  then
      rmmod $nls
      if [ "$?" = "0" ]
      then
          $colechobin "$nls unloaded" gn
      else
          $colechobin "cannot rmmod $nls!" br x
      fi
  fi
done

if [ -n "`ps ax | grep smbd | grep -v grep`" ]
then
    for i in `ps ax | grep smbd | grep -v grep | cut -c1-6`
    do
      kill -9 "$i"
      if [ "$?" = "0" ]
      then
          $colechobin "smbd with pid $i was stopped" gn
      else
          $colechobin "cannot stop smbd with pid $i!" br x br
      fi
    done
else
    $colechobin "smbd is not running!" br x br
fi

if [ -n "`ps ax | grep nmbd | grep -v grep`" ]
then
    for i in `ps ax | grep nmbd | grep -v grep | cut -c1-6`
    do
      kill -9 "$i"
      if [ "$?" = "0" ]
      then
          $colechobin "nmbd with pid $i was stopped" gn
      else
          $colechobin "cannot stop nmbd with pid $i!" br x br
      fi
    done
else
    $colechobin "nmbd is not running!" br x br
fi
