From 7c3683fa33ba9f918536956d0fbe73dd61412fcc Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Sat, 28 May 2011 21:33:11 -0500 Subject: [PATCH] * usr/lib/byobu/network: - fix shell comparator bug when number has decimal --- debian/changelog | 3 +- usr/lib/byobu/network | 65 +++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5c969095..7b5ad586 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ byobu (4.7) unreleased; urgency=low - * UNRELEASED + * usr/lib/byobu/network: + - fix shell comparator bug when number has decimal -- Dustin Kirkland Sat, 28 May 2011 12:58:05 -0500 diff --git a/usr/lib/byobu/network b/usr/lib/byobu/network index b24c6c35..9628a331 100755 --- a/usr/lib/byobu/network +++ b/usr/lib/byobu/network @@ -22,6 +22,7 @@ DATA="$HOME/.$PKG" color 2>/dev/null || color() { true; } [ "$UTF8" = "1" ] && ICON_UP="▲" || ICON_UP="^" [ "$UTF8" = "1" ] && ICON_DN="▼" || ICON_DN="v" +. /usr/lib/byobu/.shutil # Allow interface overrides in $DATA/status if [ -n "$MONITORED_NETWORK" ]; then @@ -63,41 +64,39 @@ for i in up down; do echo "$x2" > "$cache" rate=$((8*($x2 - $x1) / ($t2 - $t1) / 1024)) # in kbps [ "$rate" -lt 0 ] && rate=0 - if [ $rate -lt $NETWORK_THRESHOLD ]; then - # Below threshold, exit immediately! - exit 0 + if [ $rate -gt $NETWORK_THRESHOLD ]; then + case "$NETWORK_UNITS" in + bytes) + rate=$(($rate/8)) + if [ "$rate" -gt 1048576 ]; then + fpdiv "$rate" 1048576 1 + rate=${_RET} + unit="GB/s" + elif [ "$rate" -gt 1024 ]; then + fpdiv "$rate" 1024 1 + rate=${_RET} + unit="MB/s" + else + unit="kB/s" + fi + ;; + *) + # Default to bps + # Why 1000 and not 1024? http://en.wikipedia.org/wiki/Data_rate_units + if [ "$rate" -gt 1000000 ]; then + fpdiv "$rate" 1000000 1 + rate=${_RET} + unit="Gbps" + elif [ "$rate" -gt 1000 ]; then + fpdiv "$rate" 1000 1 + rate=${_RET} + unit="Mbps" + fi + ;; + esac fi - case "$NETWORK_UNITS" in - bytes) - rate=$(($rate/8)) - if [ "$rate" -gt 1048576 ]; then - fpdiv "$rate" 1048576 1 - rate=${_RET} - unit="GB/s" - elif [ "$rate" -gt 1024 ]; then - fpdiv "$rate" 1024 1 - rate=${_RET} - unit="MB/s" - else - unit="kB/s" - fi - ;; - *) - # Default to bps - # Why 1000 and not 1024? http://en.wikipedia.org/wiki/Data_rate_units - if [ "$rate" -gt 1000000 ]; then - fpdiv "$rate" 1000000 1 - rate=${_RET} - unit="Gbps" - elif [ "$rate" -gt 1000 ]; then - fpdiv "$rate" 1000 1 - rate=${_RET} - unit="Mbps" - fi - ;; - esac fi - if [ "$rate" -gt 0 ]; then + if [ "$rate" != "0" ]; then color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color -- fi done