From d727b382a0a925ffc83683ddb03155e550e5e687 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Thu, 16 Jun 2011 10:15:12 -0500 Subject: [PATCH] * usr/lib/byobu/hostname, usr/lib/byobu/ip_address: - in EC2, use metadata for ip and hostname, far more useful in that environment --- debian/changelog | 3 +++ usr/lib/byobu/hostname | 13 +++++++++---- usr/lib/byobu/ip_address | 15 ++++++++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 993f12a8..4208c09c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,9 @@ byobu (4.12) unreleased; urgency=low - update docs to reflect reality * usr/share/byobu/profiles/tmux: - added an early draft of a tmux profile + * usr/lib/byobu/hostname, usr/lib/byobu/ip_address: + - in EC2, use metadata for ip and hostname, far more useful + in that environment -- Dustin Kirkland Sun, 12 Jun 2011 23:37:24 -0500 diff --git a/usr/lib/byobu/hostname b/usr/lib/byobu/hostname index 90e58660..32c10bc6 100755 --- a/usr/lib/byobu/hostname +++ b/usr/lib/byobu/hostname @@ -1,9 +1,9 @@ #!/bin/sh -e # # hostname - report a host's name -# Copyright (C) 2008 Canonical Ltd. +# Copyright (C) 2008-2011 Canonical Ltd. # -# Authors: Dustin Kirkland +# Authors: Dustin Kirkland # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,6 +26,11 @@ if [ "$1" = "--detail" ]; then exit 0 fi -. "$DATA/status" +if host 169.254.169.254 >/dev/null 2>&1; then + # We're in EC2, so get our public hostname + h=$(wget -q -O - http://169.254.169.254/latest/meta-data/public-hostname) +else + h=$(hostname -s 2>/dev/null || hostname) +fi -color bold2; printf "%s" "$(hostname -s 2>/dev/null || hostname)"; color -- +color bold2; printf "%s" "$h "; color -- diff --git a/usr/lib/byobu/ip_address b/usr/lib/byobu/ip_address index c8388095..377b42bc 100755 --- a/usr/lib/byobu/ip_address +++ b/usr/lib/byobu/ip_address @@ -1,9 +1,9 @@ #!/bin/sh -e # # ip_address - report a host's ip address -# Copyright (C) 2008 Canonical Ltd. +# Copyright (C) 2008-2011 Canonical Ltd. # -# Authors: Dustin Kirkland +# Authors: Dustin Kirkland # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -51,9 +51,14 @@ case "$IPV6" in ipaddr=${ipaddr%%/*} ;; *) - ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global) - ipaddr=${ipaddr#* inet } - ipaddr=${ipaddr%%/*} + if host 169.254.169.254 >/dev/null 2>&1; then + # We're in EC2, so get our public IP address + ipaddr=$(wget -q -O- http://169.254.169.254/latest/meta-data/public-ipv4) + else + ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global) + ipaddr=${ipaddr#* inet } + ipaddr=${ipaddr%%/*} + fi ;; esac