From eedd8a26dbd8fb2a48a46a1e78b6e072282d6b73 Mon Sep 17 00:00:00 2001 From: Carl Pulley Date: Fri, 25 Jan 2013 11:00:14 +0000 Subject: [PATCH] Issue #1240: Updated ensure_hostname_in_hosts to use SSH_CONNECTION with failover to hostname -i --- compute/src/test/resources/initscript_with_java.sh | 11 +++++++---- compute/src/test/resources/initscript_with_jetty.sh | 11 +++++++---- compute/src/test/resources/runscript.sh | 11 +++++++---- .../resources/test_guest_additions_installer_init.sh | 11 +++++++---- .../src/main/resources/functions/setupPublicCurl.sh | 11 +++++++---- .../resources/test_install_chef_gems_scriptbuilder.sh | 11 +++++++---- .../test/resources/test_install_git_scriptbuilder.sh | 11 +++++++---- .../test/resources/test_install_jdk_scriptbuilder.sh | 11 +++++++---- .../test/resources/test_install_ruby_scriptbuilder.sh | 11 +++++++---- 9 files changed, 63 insertions(+), 36 deletions(-) diff --git a/compute/src/test/resources/initscript_with_java.sh b/compute/src/test/resources/initscript_with_java.sh index b52d6f9363..2c7dd047ec 100644 --- a/compute/src/test/resources/initscript_with_java.sh +++ b/compute/src/test/resources/initscript_with_java.sh @@ -115,10 +115,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/compute/src/test/resources/initscript_with_jetty.sh b/compute/src/test/resources/initscript_with_jetty.sh index 45eaad57c3..0aa421875b 100644 --- a/compute/src/test/resources/initscript_with_jetty.sh +++ b/compute/src/test/resources/initscript_with_jetty.sh @@ -115,10 +115,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/compute/src/test/resources/runscript.sh b/compute/src/test/resources/runscript.sh index aaa38777f3..0715f775c4 100644 --- a/compute/src/test/resources/runscript.sh +++ b/compute/src/test/resources/runscript.sh @@ -115,10 +115,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/labs/virtualbox/src/test/resources/test_guest_additions_installer_init.sh b/labs/virtualbox/src/test/resources/test_guest_additions_installer_init.sh index 58a9a7c959..6209635882 100644 --- a/labs/virtualbox/src/test/resources/test_guest_additions_installer_init.sh +++ b/labs/virtualbox/src/test/resources/test_guest_additions_installer_init.sh @@ -112,10 +112,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh b/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh index a59dd627d4..eed22e7200 100644 --- a/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh +++ b/scriptbuilder/src/main/resources/functions/setupPublicCurl.sh @@ -30,10 +30,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/scriptbuilder/src/test/resources/test_install_chef_gems_scriptbuilder.sh b/scriptbuilder/src/test/resources/test_install_chef_gems_scriptbuilder.sh index 67cdfe5c9b..c561332bf3 100644 --- a/scriptbuilder/src/test/resources/test_install_chef_gems_scriptbuilder.sh +++ b/scriptbuilder/src/test/resources/test_install_chef_gems_scriptbuilder.sh @@ -115,10 +115,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/scriptbuilder/src/test/resources/test_install_git_scriptbuilder.sh b/scriptbuilder/src/test/resources/test_install_git_scriptbuilder.sh index 08533043b7..623e159f55 100644 --- a/scriptbuilder/src/test/resources/test_install_git_scriptbuilder.sh +++ b/scriptbuilder/src/test/resources/test_install_git_scriptbuilder.sh @@ -115,10 +115,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh b/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh index ab8210beff..0a39109b37 100644 --- a/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh +++ b/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh @@ -115,10 +115,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns diff --git a/scriptbuilder/src/test/resources/test_install_ruby_scriptbuilder.sh b/scriptbuilder/src/test/resources/test_install_ruby_scriptbuilder.sh index 6476f276a2..ad20578d93 100644 --- a/scriptbuilder/src/test/resources/test_install_ruby_scriptbuilder.sh +++ b/scriptbuilder/src/test/resources/test_install_ruby_scriptbuilder.sh @@ -115,10 +115,13 @@ function ensure_netutils_yum() { # most network services require that the hostname is in # the /etc/hosts file, or they won't operate function ensure_hostname_in_hosts() { - # NOTE: - # 1. We blindly trust existing hostname settings in /etc/hosts - # 2. We assume hostname supports the -i option to return the default NICs IP address - egrep -q `hostname` /etc/hosts || echo "`hostname -i` `hostname`" >> /etc/hosts + [ -n "$SSH_CONNECTION" ] && { + local ipaddr=`echo $SSH_CONNECTION | cut -d ' ' -f 3` + } || { + local ipaddr=`hostname -i` + } + # NOTE: we blindly trust existing hostname settings in /etc/hosts + egrep -q `hostname` /etc/hosts || echo "$ipaddr `hostname`" >> /etc/hosts } # download locations for many services are at public dns