#!/usr/bin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

supervisor=supervise-daemon
command=/usr/bin/dropbear
command_args="-F ${DROPBEAR_OPTS}"

depend() {
	use logger dns
	need net
}

start_pre() {
	mkdir -p /etc/dropbear

	local t k
	for t in dss rsa ecdsa; do
		k="/etc/dropbear/dropbear_${t}_host_key"
		if [ ! -e ${k} ] ; then
			# See if support is enabled for this key type.
			if dropbearkey -h 2>&1 | grep -q "	${t}$" ; then
				einfo "Generating ${k} ..."
				dropbearkey -t ${t} -f ${k} >/dev/null
			fi
		fi &
	done
	wait
}
