#!/bin/sh
#
# $FreeBSD: ports/security/ssh2/files/sshd2.sh.in,v 1.1 2006/02/19 22:56:35 marius Exp $
#

# PROVIDE: sshd2
# REQUIRE: LOGIN
#
# Available configuration variables for sshd2 are:
#
# sshd2_enable (bool):	Set to "YES" to enable sshd2. Defaults to "NO".
# sshd2_flags (flags):	Extra flags to sshd2 (see sshd2(8)). Defaults to "".
# sshd2_port (port):	Listening port of sshd2. Defaults to "22".
#
# Add at least the following line to /etc/rc.conf or /etc/rc.conf.local to
# enable sshd2:
#
# sshd2_enable="YES"
#

. /etc/rc.subr

name="sshd2"
rcvar=${name}_enable

command=/usr/local/sbin/${name}
command_args="2> /dev/null"
required_files=/usr/local/etc/ssh2/${name}_config
keygen_cmd="sshd2_keygen"
start_precmd="sshd2_precmd"
extra_commands="keygen reload"

sshd2_keygen()
{
	(
	umask 022
	if [ -f /usr/local/etc/ssh2/hostkey ]; then
		echo "You already have a host key in" \
		    "/usr/local/etc/ssh2/hostkey."
		echo "Skipping key generation."
	else
		/usr/local/bin/ssh-keygen2 -P -t dsa -c "DSA hostkey" \
		    /usr/local/etc/ssh2/hostkey
	fi
	)
}

sshd2_precmd()
{
	if [ ! -f /usr/local/etc/ssh2/hostkey ]; then
		run_rc_command keygen
	fi

	rc_flags="${rc_flags} -p ${sshd2_port}"
}

load_rc_config $name

: ${sshd2_enable="NO"}
: ${sshd2_port="22"}

pidfile=/var/run/${name}_${sshd2_port}.pid

run_rc_command "$1"
