#!/bin/sh
# description: Secure Shell daemon
#
# (c) 2004, Eko M. Budi, for Vector Linux
# Released under GNU GPL
#
# Include the functions declared in the /etc/rc.d/functions file
source /etc/rc.d/functions

# path to binary
ROOT="/usr/sbin"
# name of binary to run
APP="sshd"
#runtime options
OPT=""
#server name & description
SERVER="Secure Shell daemon"

check_config() {
  # Create host keys if needed.
  if [ ! -r /etc/ssh/ssh_host_key ]; then
    /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N '' 
  fi
  if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
    /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
  fi
  if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
    /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
  fi
  if [ ! -f /etc/ssh/ssh_host_ecdsa_key ]; then
    /usr/bin/ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
  fi

}

case "$1" in
    start)
	check_config
	echon "Starting $SERVER ..."
	loadproc $ROOT/$APP
	;;
    stop)
	echon "Stopping $SERVER ..."
        killproc $ROOT/$APP
        ;;
    reload)
        echon "Reloading $SERVER..........."
        reloadproc $ROOT/$APP
        ;;
    restart)
        $0 stop
	sleep 1
	$0 start
        ;;
    status)
        statusproc $ROOT/$APP
        ;;
    *)
        echo "Usage: $0 {start|stop|reload|restart|status}"        
    ;;
esac

# End /etc/init.d/
