Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: image_to_live.sh

Issue 6531005: image_to_live.sh: fix ip address detection (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: . Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: image_to_live.sh
diff --git a/image_to_live.sh b/image_to_live.sh
index 79e15b1f35a62bb6038ac992bd846f1f00b61661..84072398b17ef901a774cedf4a0f95ac41d55ab5 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}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698