From 9a776566e97f10a1ba756c871d4e3ac78496907f Mon Sep 17 00:00:00 2001 From: Zdenek Behan Date: Fri, 18 Feb 2011 00:51:21 +0100 Subject: [PATCH] image_to_live.sh: fix ip address detection Change-Id: I6d05da5d1deaf45c42a3285c105fd310a588ef4e BUG=5246 TEST=update an image, live Review URL: http://codereview.chromium.org/6531005 --- image_to_live.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/image_to_live.sh b/image_to_live.sh index 79e15b1f35..84072398b1 100755 --- a/image_to_live.sh +++ b/image_to_live.sh @@ -101,10 +101,20 @@ function remote_reboot_sh { # 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} + # Try to parse ifconfig for ip address. Use sudo, because not all distros + # allow a common user to call ifconfig. + # TODO(zbehan): What if target is not connected via eth0? Update over wifi? + # Dedicated usb NIC? Perhaps this detection should be done in the target, + # which will get the return address in one way or another. Or maybe we should + # just open a ssh tunnel and use localhost. + hostname=$(sudo ifconfig eth0 | + grep 'inet addr' | + cut -f2 -d':' | + cut -f1 -d' ') + + # Fallback to $HOSTNAME if that failed + [ -z "${hostname}" ] && hostname=${HOSTNAME} + echo ${hostname} }