diff --git a/cloud.spec b/cloud.spec index aa5b6436a8a..42accedf9b4 100644 --- a/cloud.spec +++ b/cloud.spec @@ -520,6 +520,7 @@ fi %attr(0755,root,root) %{_bindir}/%{name}-setup-databases %attr(0755,root,root) %{_bindir}/%{name}-migrate-databases %attr(0755,root,root) %{_bindir}/%{name}-set-guest-password +%attr(0755,root,root) %{_bindir}/%{name}-set-guest-sshkey %dir %{_datadir}/%{name}/setup %{_datadir}/%{name}/setup/*.sql %{_datadir}/%{name}/setup/*.sh diff --git a/debian/cloud-setup.install b/debian/cloud-setup.install index f790bb3ecc2..8665e5d5587 100644 --- a/debian/cloud-setup.install +++ b/debian/cloud-setup.install @@ -1,6 +1,7 @@ /usr/bin/cloud-setup-databases /usr/bin/cloud-migrate-databases /usr/bin/cloud-set-guest-password +/usr/bin/cloud-set-guest-sshkey /usr/share/cloud/setup/*.sql /usr/share/cloud/setup/*.sh /usr/share/cloud/setup/server-setup.xml diff --git a/setup/bindir/cloud-set-guest-sshkey.in b/setup/bindir/cloud-set-guest-sshkey.in new file mode 100755 index 00000000000..cf02bbdd661 --- /dev/null +++ b/setup/bindir/cloud-set-guest-sshkey.in @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Init file for SSH Public Keys Download Client +# +# chkconfig: 345 98 02 +# description: SSH Public Keys Download Client + +# Modify this line to specify the user (default is root) +user=ubuntu + + +# Get DomR Ip +DOMR_IP=$(ip route | grep default | cut -d' ' -f3) + +if [ ! -n "$DOMR_IP" ] +then + echo "DomR IP address not found. Exiting." + exit 1 +fi + +# Get ssh public key +homedir=$(grep ^$user /etc/passwd|awk -F ":" '{print $6}') +sshdir=$homedir/.ssh +authorized=$sshdir/authorized_keys +publickey=$(wget -t 3 -T 20 -O - http://$DOMR_IP/latest/public-keys 2>/dev/null) + +if [ $? -ne 0 ] +then + echo "Error receiving SSH public key. Exiting." + exit 1 +fi + + +if [ ! -e $sshdir ] +then + mkdir $sshdir +fi + +if [ ! -e $authorized ] +then + touch $authorized +fi + +cat $authorized|grep -v "$publickey" > $authorized +echo "$publickey" >> $authorized + + +exit 0 +