#!/usr/bin/bash

# Copyright (c) 2020 Fedora CoreOS Authors. All rights reserved.
# 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.
# Modified from the CoreOS repository: https://github.com/coreos/init/blob/master/scripts/sshd_keygen

set -e

. /usr/lib/console-login-helper-messages/libutil.sh
. /usr/lib/console-login-helper-messages/issue.defs

# Provide key fingerprints via issue.
SSH_DIR=/etc/ssh
# Ensure `${SSH_DIR}` is created and can be searched without error.
mkdir -p "${SSH_DIR}"
SSH_KEY_OUTDIR="${RUN_SNIPPETS}"
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}' \
    | write_via_tempfile "${SSH_KEY_OUTDIR}/21_${CLHM_FILE_MARKER}_ssh_host_keys.issue"
