#!/bin/sh -e


umask 022


create_key() {
	local msg="$1"
	shift
	local file="$1"
	shift

	if [ ! -f "$file" ] ; then
		echo -n $msg
		ssh-keygen -f "$file" -N '' "$@" > /dev/null
		echo
	fi
}


create_keys() {
	RET=true

	if [ "$RET" = "false" ] ; then
		create_key "Creating SSH1 key" /etc/ssh/ssh_host_key -t rsa1
	fi

	create_key "Creating SSH2 RSA key" /etc/ssh/ssh_host_rsa_key -t rsa
	create_key "Creating SSH2 DSA key" /etc/ssh/ssh_host_dsa_key -t dsa
}


setup_init() {
	if [ -e /etc/init.d/ssh ]; then
		/etc/init.d/ssh restart
	fi
}

create_keys
setup_init

exit 0

