From 728649e6723c82af2ff29ac523dfada2aa5fff44 Mon Sep 17 00:00:00 2001 From: Rajesh Battala Date: Thu, 6 Sep 2012 16:17:47 +0530 Subject: [PATCH] CS-14440 : cloud-set-guest-sshkey overwriting SSH keys on reboot is fixed --- setup/bindir/cloud-set-guest-sshkey.in | 31 +++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/setup/bindir/cloud-set-guest-sshkey.in b/setup/bindir/cloud-set-guest-sshkey.in index 2f19f1feee0..1be6307069f 100755 --- a/setup/bindir/cloud-set-guest-sshkey.in +++ b/setup/bindir/cloud-set-guest-sshkey.in @@ -12,6 +12,17 @@ user=root # Add your DHCP lease folders here DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/*" + +if [ -f /etc/debian_version ]; then + # Ubuntu + DHCP_FOLDERS="/var/lib/dhcpcd/dhcpcd-eth0.*" +elif [ -f /etc/redhat-release ]; then + # Redhat / CentOS / Scientific Linux + DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/*" +else + # Others + DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/*" +fi keys_received=0 file_count=0 @@ -21,6 +32,16 @@ do then file_count=$((file_count+1)) SSHKEY_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;') + if [ -f /etc/debian_version ]; then + # Ubuntu + SSHKEY_SERVER_IP=$(grep DHCPSID $DHCP_FILE | tail -1 | egrep -o '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' ) + elif [ -f /etc/redhat-release ]; then + # Redhat / CentOS / Scientific Linux + SSHKEY_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;') + else + # Others + SSHKEY_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;') + fi if [ -n $SSHKEY_SERVER_IP ] then @@ -65,9 +86,13 @@ then touch $authorized fi -cat $authorized|grep -v "$publickey" > $authorized -echo "$publickey" >> $authorized - +#cat $authorized|grep -v "$publickey" > $authorized +#echo "$publickey" >> $authorized +#To support user copied ssh keys +if [ `grep -c "$publickey" $authorized` == 0 ] +then + echo "$publickey" >> $authorized +fi exit 0