From ccfa2ac9709864b78aaaf3ed9a1ffcf33ee9511d Mon Sep 17 00:00:00 2001 From: Chris Sosa Date: Fri, 15 Oct 2010 10:43:23 -0700 Subject: [PATCH] Change hostname to ip address if we can get it from ifconfig. Change-Id: I6719ffe0c3c9356cf48b391b0a257e268eec94dc BUG=7780 TEST=Ran it with cros_run_vm_test. Review URL: http://codereview.chromium.org/3829002 --- image_to_live.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/image_to_live.sh b/image_to_live.sh index 26a52997de..6329cafc2f 100755 --- a/image_to_live.sh +++ b/image_to_live.sh @@ -69,6 +69,20 @@ function remote_reboot_sh { remote_sh "$@" } +# Returns the hostname of this machine. +# It tries to find the ipaddress using ifconfig, however, it will +# default to $HOSTNAME on failure. We try to use the ip address first as +# some targets may have dns resolution issues trying to contact back +# to us. +function get_hostname { + local hostname + # Try to parse ifconfig for ip address + hostname=$(ifconfig eth0 \ + | grep 'inet addr' \ + | sed 's/.\+inet addr:\(\S\+\).\+/\1/') || hostname=${HOSTNAME} + echo ${hostname} +} + # Reinterprets path from outside the chroot for use inside. # $1 - The path to reinterpret. function reinterpret_path_for_chroot() { @@ -169,7 +183,7 @@ function get_devserver_url { local devserver_url="" if [ ${FLAGS_ignore_hostname} -eq ${FLAGS_TRUE} ]; then if [ -z ${FLAGS_update_url} ]; then - devserver_url="http://$HOSTNAME:${FLAGS_devserver_port}/update" + devserver_url="http://$(get_hostname):${FLAGS_devserver_port}/update" else devserver_url="${FLAGS_update_url}" fi