#!/bin/sh
#
# description: SSH Secure Shell daemon
#
# Author: Sami Lehtinen <sjl@ssh.com>
#
# sshd2		This shell script takes care of starting and stopping
#               sshd2.
# 
# partly
#
# Copyright (C) 2000 SSH Communications Security Corp, Helsinki, Finland
#
# Most of the code taken from RedHat Linux /etc/rc.d/init.d/httpd, 
# so I guess
#
# Copyright (C) 1999 RedHat, Inc.

# Edit the below variables if needed.

ETCDIR=/etc/ssh2
SBINDIR=/usr/local/sbin


[ -f ${SBINDIR}/sshd2 ] || exit 0

PORT=

PORT=`grep Port ${ETCDIR}/sshd2_config | awk '{ x = $2 } END {print x}' -`
if [ "X$PORT" = "X" ]
then
	PORT=22
fi

# See how we were called.

case "$1" in
  start)
	# Start daemons.
	echo "Starting sshd2 on port $PORT... "
	${SBINDIR}/sshd2
	;;
  stop)
	# Stop daemons.
	
        if [ -f /var/run/sshd2_$PORT.pid ]
           
           then
  
              echo "1 Shutting down sshd2 on port ${PORT}... "
              kill `cat /var/run/sshd2_${PORT}.pid`
              rm -f /var/run/sshd2_${PORT}.pid 

           elif [ -f ${ETCDIR}/sshd2_${PORT}.pid ]
           
           then

              echo "Shutting down sshd2 on port ${PORT}... "
              kill `cat ${ETCDIR}/sshd2_${PORT}.pid`
              rm -f ${ETCDIR}/sshd2_${PORT}.pid

           else

              echo "sshd2 is not running"  

        fi

	;;

  restart)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: sshd2 {start|stop|restart}"
	exit 1
esac

exit 0

