# -*- sh -*-
# $Id: 08sshkeygen,v 1.5 2004/02/07 18:01:39 lioka Exp $

# We're prefer to do this here instead of every time at start
# used do_keygen() from sshd initscript

WITHOUT_RC_COMPAT=1
. /etc/init.d/functions

KEYGEN=/usr/bin/ssh-keygen
SSH1_RSA_KEY=/etc/openssh/ssh_host_key
SSH2_RSA_KEY=/etc/openssh/ssh_host_rsa_key
SSH2_DSA_KEY=/etc/openssh/ssh_host_dsa_key

do_keygen()
{
local kfile ktype kname
    kfile="$1"
    shift
    ktype="$1"
    shift
    kname="$1"
    shift

    if [ ! -s "$kfile" ]; then
        printf $"Generating %s host key: " "$kname"
        if $KEYGEN -q -t "$ktype" -f "$kfile" -C '' -N '' >/dev/null 2>&1; then
            echo_success "$kname key generation"
            echo
        else
            echo_failure "$kname key generation"
            echo
            exit 1
        fi
    fi
}

if [ -x $KEYGEN ]; then
    do_keygen "$SSH1_RSA_KEY" rsa1 "SSH1 RSA"
    do_keygen "$SSH2_RSA_KEY" rsa  "SSH2 RSA"
    do_keygen "$SSH2_DSA_KEY" dsa  "SSH2 DSA"
fi
