#!/bin/bash

#
# /etc/rc.d/init.d/S15inet - Start/Stop the inetd daemon(s).
#

# Comment out the following exit line to enable this script.
# exit 0

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

DAEMON="/usr/sbin/sshd"

case "$1" in

    start)
	if [ ! -f /etc/ssh/ssh_host_rsa_key ] ; then
	    echo "Generating RSA key for SSH v2"
	    /usr/bin/ssh-keygen -N ""  -t rsa -f /etc/ssh/ssh_host_rsa_key
	fi

	if [ ! -f /etc/ssh/ssh_host_dsa_key ] ; then
	    echo "Generating DSA key for SSH v2"
	    /usr/bin/ssh-keygen -N ""  -t dsa -f /etc/ssh/ssh_host_dsa_key
	fi

	test -f /etc/ssh/sshd_not_to_be_run && exit 0
	msg -n "Starting sshd:"
	daemon --survive=5 $DAEMON
	msg
	;;

    stop)
	msg -n "Stopping sshd:"
	killproc $DAEMON
	msg
	;;

    restart)
	test -f /etc/ssh/sshd_not_to_be_run && exit 0
	$0 stop
	sleep 1
	$0 start
	;;

    *)
	echo "Usage: $0 (start|stop|restart)"
	exit 1
	;;

esac

exit 0

