CS-14440 : cloud-set-guest-sshkey overwriting SSH keys on reboot is fixed

This commit is contained in:
Rajesh Battala 2012-09-06 16:17:47 +05:30
parent a5241c89c7
commit 728649e672
1 changed files with 28 additions and 3 deletions

View File

@ -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