#! /usr/local/bin/cbsd
#v11.0.10
globalconf="${distdir}/cbsd.conf";
MYARG=""
MYOPTARG="private_key public_key renew"
MYDESC="Manage node ssh key: replace or update new pair in CBSD .ssh directory"
ADDHELP="private_key - specify full path to id_rsa to install as node private key\n\
public_key - specify full path to authorized_keys to install as node public key\n\
renew - when set to 1, remove old rsa/pub key pair and generate new\n"

.  ${subr}

.  ${cbsdinit}

.  ${system}
.  ${initenv}

### MAIN
[ -z "${private_key}" -a -z "${public_key}" -a -z "${renew}" ] && err 1 "${N1_COLOR}Use ${N2_COLOR}private_key=${N1_COLOR} or ${N2_COLOR}public_key=${N1_COLOR} or ${N2_COLOR}renew=1${N1_COLOR} to replace old files${N0_COLOR}"
[ -z "${renew}" ] && renew=0

if [ ${renew} -eq 1 ]; then
	install_sshkey -r
	err 0 "${N1_COLOR}Updated${N0_COLOR}"
fi

[ -n "${private_key}" ] && install_sshkey -p ${private_key}
[ -n "${public_key}" ] && install_sshkey -a ${public_key}
