#!/bin/bash

# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

set -e

SSH_DIR=/etc/ssh
mkdir -p ${SSH_DIR}

# ssh-keygen doesn't ensure that host keys are valid, merely that they exist.
# Remove zero-length keys, which can be a result of an unclean filesystem
# shutdown.
find ${SSH_DIR} -name 'ssh_host_*_key' -size 0 -delete

ssh-keygen -A -v

# Provide key fingerprints via issue
mkdir -p /run/issue.d
for KEY_FILE in $(find ${SSH_DIR} -name 'ssh_host_*_key') ; do
  ssh-keygen -l -f ${KEY_FILE}
done | awk '{print "SSH host key: " $2 " " $4}' > /run/issue.d/00_ssh_host_keys
