#!/bin/sh

RW_DIR=/.rw
RSA1_KEY=/etc/ssh/ssh_host_key
RSA_KEY=/etc/ssh/ssh_host_rsa_key
DSA_KEY=/etc/ssh/ssh_host_dsa_key

case "$1" in
	start)
		for KEY in $RSA1_KEY $RSA1_KEY.pub $RSA_KEY $RSA_KEY.pub $DSA_KEY $DSA_KEY.pub; do
			if [ ! -s $KEY -a -s $RW_DIR/$KEY ]; then
				cp -af $RW_DIR/$KEY $KEY
                                chmod 0600 $KEY
			fi
		done
		;;
	stop)
		for KEY in $RSA1_KEY $RSA1_KEY.pub $RSA_KEY $RSA_KEY.pub $DSA_KEY $DSA_KEY.pub; do
			if [ -s $KEY -a ! -s $RW_DIR/$KEY ]; then
				DIR=`dirname $RW_DIR/$KEY`
				mkdir -p $DIR && cp -af $KEY $RW_DIR/$KEY
			fi
		done
		;;
	*)
		;;
esac
