レポジトリ種類: SVN
#!/bin/sh -e
__ip_address_detail() {
if [ "$(uname -s)" = "Linux" ]; then
/sbin/ip -4 addr list
/sbin/ip -6 addr list
else
/sbin/ifconfig -a | grep 'inet '
/sbin/ifconfig -a | grep 'inet6 '
fi
}
__ip_address() {
local interface ipaddr cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ip_address"
$ifconfig=/sbin/ifconfig
if [ "$(uname -s)" = "Linux" ]; then
ifconfig=/sbin/ip
fi
if [ -n "$MONITORED_NETWORK" ]; then
interface="$MONITORED_NETWORK"
else
if [ "$(uname -s)" = "Linux" ]; then
case "$IPV6" in
1|true|yes) interface=$(awk '$10 != "lo" { iface=$10 ; }; END { print iface; }' /proc/net/ipv6_route);;
*) get_network_interface; interface="$_RET";;
esac
else
case "$IPV6" in
1|true|yes)interface=$(ifconfig -a | awk '/inet6/ && $2 != "fe80::" { iface=$1; } END { print iface; }');;
*) get_network_interface; interface="$_RET";;
esac
fi
fi
case "$IPV6" in
1|true|yes)
if [ "$IP_EXTERNAL" = "1" ]; then
timeout 1 curl -s http://v6.ipv6-test.com/api/myip.php </dev/null >"$cache" 2>/dev/null &
sleep 0.02
else
if [ -x /sbin/ip ]; then
LC_ALL=C /sbin/ip -6 addr list dev "$interface" scope global </dev/null >"$cache" 2>/dev/null &
elif eval $BYOBU_TEST ifconfig >/dev/null 2>&1; then
LC_ALL=c /sbin/ifconfig "$interface" | grep "inet6 " | awk '{print $2}' | sed -e "s/%.*//" >"$cache" 2>/dev/null &
fi
fi
[ -s "$cache" ] && read ipaddr < "$cache"
[ -z "$ipaddr" ] && ipaddr="None"
ipaddr=${ipaddr#* inet6 }
ipaddr=${ipaddr%%/*}
;;
*)
if [ "$IP_EXTERNAL" = "1" ]; then
timeout 1 curl -s http://v4.ipv6-test.com/api/myip.php </dev/null >"$cache" 2>/dev/null &
sleep 0.02
[ -s "$cache" ] && read ipaddr < "$cache"
elif metadata_available; then
# AWS
timeout 0.2 curl -s http://169.254.169.254/latest/meta-data/public-ipv4 </dev/null >"$cache" 2>/dev/null &
sleep 0.02
[ -s "$cache" ] && read ipaddr < "$cache"
else
if [ -x /sbin/ip ]; then
ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global 2>/dev/null)
ipaddr=${ipaddr#* inet }
ipaddr=${ipaddr%%/*}
elif eval $BYOBU_TEST ifconfig >/dev/null 2>&1; then
ipaddr=$(ifconfig "$interface" | grep "inet " | awk '{sub(/\/[0-9]+/, "", $2); print $2}')
fi
fi
;;
esac
if [ -n "$ipaddr" ]; then
if [ "$1" = "t" ]; then
printf "%s" "$ipaddr"
else
color b w k; printf "%s" "$ipaddr"; color --
fi
fi
}