#!/bin/sh
# Copyright 2010 Novell, Inc.
# Author: Peter Bowen <pzb@novell.com> as a work made for hire
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
# /etc/init.d/amazon-late
#
#   and it's symbolic link
#
# /usr/sbin/rcamazon-late
#
# chkconfig: 345 90 10
# description: Prints the SSH host keys to the system log
#
### BEGIN INIT INFO
# Provides:       amazon-late
# Required-Start: amazon sshd $all 
# Should-Start:  
# Required-Stop:  $null
# Should-Stop:
# Default-Start:  3 5
# Default-Stop: 
# Description:    print SSH host keys
# Short-Description: print SSH keys 
# X-UnitedLinux-Default-Enabled: yes
### END INIT INFO

. /etc/rc.status

# First reset status of this service
rc_reset

##function: printSSHkey
function printSSHkey {
    echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----" |logger -s -t "ec2"
    ssh-keygen -l -f /etc/ssh/ssh_host_key.pub |logger -s -t "ec2"
    ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub |logger -s -t "ec2"
    ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub |logger -s -t "ec2"
    echo "-----END SSH HOST KEY FINGERPRINTS-----"   |logger -s -t "ec2"
}

case "$1" in
    start)
        printSSHkey
        rc_status -v
        ;;
    stop)
        true
        rc_status -v
        ;;
    try-restart)
        $0 status >/dev/null &&  $0 restart
        rc_status
        ;;
    reload)
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    *)
        echo "Usage: $0 {start|stop|try-restart|restart}"
        exit 1
        ;;
esac
rc_exit

