From 67e86457b0ef7e24734860acea6f3db9a6b0dfd4 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 14 Sep 2009 23:52:28 -0500 Subject: [PATCH] make the status scripts compatible with busybox shells tested on the palm pre mostly, this consists of making sure that utilities called are available and failing over properly in some cases, it's a matter of particular options not being available or perhaps directories not being available Signed-off-by: Dustin Kirkland --- bin/cpu_count | 2 +- bin/disk | 3 ++- bin/logo | 6 +++++- bin/network | 3 ++- bin/reboot_required | 3 ++- bin/release | 25 ++++++++++++++++--------- bin/temp_c | 4 ++-- bin/temp_f | 2 +- bin/updates_available | 3 ++- debian/changelog | 6 ++++-- 10 files changed, 37 insertions(+), 20 deletions(-) diff --git a/bin/cpu_count b/bin/cpu_count index 93c68c65..e7233921 100755 --- a/bin/cpu_count +++ b/bin/cpu_count @@ -21,5 +21,5 @@ if [ "$1" = "--detail" ]; then grep -i "^model name" /proc/cpuinfo exit 0 fi -count=`getconf _NPROCESSORS_ONLN` +count=`getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo` [ "$count" = "1" ] || printf "%sx" "$count" diff --git a/bin/disk b/bin/disk index 6f1bc75f..4e93afe2 100755 --- a/bin/disk +++ b/bin/disk @@ -31,4 +31,5 @@ case $MP in /dev/*) MP=`grep "$MP" /proc/mounts | awk '{print $2}'` ;; esac -df -h -P "$MP" | tail -n 1 | awk '{print $2 " " $5}' | sed "s/\([^0-9\. ]\)/ \1/g" | awk '{printf "\005{=b MW}%d\005{-}\005{= MW}%sB,\005{-}\005{=b MW}%d\005{-}\005{= MW}%%\005{-} ", $1, $2, $3}' +disk=`df -h -P "$MP" 2>/dev/null || df -h "$MP"` +echo "$disk" | tail -n 1 | awk '{print $2 " " $5}' | sed "s/\([^0-9\. ]\)/ \1/g" | awk '{printf "\005{=b MW}%d\005{-}\005{= MW}%sB,\005{-}\005{=b MW}%d\005{-}\005{= MW}%%\005{-} ", $1, $2, $3}' diff --git a/bin/logo b/bin/logo index 0a643135..bce20ff9 100755 --- a/bin/logo +++ b/bin/logo @@ -27,7 +27,7 @@ else fi print_logo() { - distro=`echo "$1" | tr '[:upper:]' '[:lower:]'` + distro=`echo "$1" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' ` case "$distro" in *ubuntu*) $MARKUP && printf "\005{=b kr}\\\\\005{= ky}o\005{=b kY}/" || printf "\\o/" @@ -68,6 +68,10 @@ print_logo() { logo=" RH " $MARKUP && printf "\005{= Rk}$logo" || printf "$logo" ;; + *rockhopper*) + logo="palm" + $MARKUP && printf "\005{=b YW}$logo" || printf "$logo" + ;; *slackware*) logo=",S " $MARKUP && printf "\005{=u Bk}$logo" || printf "$logo" diff --git a/bin/network b/bin/network index fc54d71a..a1b54f05 100755 --- a/bin/network +++ b/bin/network @@ -31,9 +31,10 @@ if [ "$1" = "--detail" ]; then exit 0 fi +[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$HOME/.byobu" t2=`date +%s` for i in up down; do - cache="/var/run/screen/S-$USER/$PKG.network_$i" + cache="$DIR/$PKG.network_$i" t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 unit="kB/s" if [ $t2 -le $t1 ]; then diff --git a/bin/reboot_required b/bin/reboot_required index cde59763..59b93bfd 100755 --- a/bin/reboot_required +++ b/bin/reboot_required @@ -19,7 +19,8 @@ PKG="byobu" reboot="/var/run/reboot-required" -reload="/var/run/screen/S-$USER/$PKG.reload-required" +[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$HOME/.byobu" +reload="$DIR/$PKG.reload-required" case "$1" in --detail) ls -alF "$reboot" "$reload" 2>&1 diff --git a/bin/release b/bin/release index a1a3f0e6..5f4d16f8 100755 --- a/bin/release +++ b/bin/release @@ -19,8 +19,14 @@ PKG="byobu" +if [ "$1" = "--detail" ]; then + cat /etc/issue + exit 0 +fi + if [ -n "$DISTRO" ]; then - printf "\005{+b }%s\005{-} " "$DISTRO" + # skip down to the bottom + true elif which lsb_release >/dev/null 2>&1; then if [ "$1" = "--detail" ]; then lsb_release -a 2>/dev/null @@ -30,21 +36,22 @@ elif which lsb_release >/dev/null 2>&1; then r=$(lsb_release -s -d) if echo "$r" | grep -qs "^Ubuntu .*\..*\..*$"; then # Use the -d if an Ubuntu LTS - printf "\005{+b }%s\005{-} " "$r" + DISTRO="$r" else # But for other distros the description # is too long, so build from -i and -r i=$(lsb_release -s -i) r=$(lsb_release -s -r) - printf "\005{+b }%s %s\005{-} " "$i" "$r" + DISTRO="$i $r" fi +elif [ -r "/etc/palm-build-info" ]; then + # Palm Pre hack + DISTRO=$(grep "^PRODUCT_VERSION_STRING=Palm " /etc/palm-build-info | sed "s/^.*=Palm //") elif [ -r "/etc/issue" ]; then - if [ "$1" = "--detail" ]; then - cat /etc/issue - exit 0 - fi # Otherwise, grab part of /etc/issue, ideally the distro and version - printf "\005{+b }%s\005{-} " $(head -n1 /etc/issue | sed "s/ [^0-9]* / /" | awk '{print $1 " " $2}') + DISTRO=$(head -n1 /etc/issue | sed "s/ [^0-9]* / /" | awk '{print $1 " " $2}') else - echo "Byobu" + DISTRO="Byobu" fi + +printf "\005{+b }%s\005{-} " "$DISTRO" diff --git a/bin/temp_c b/bin/temp_c index 290acb40..4442cbad 100755 --- a/bin/temp_c +++ b/bin/temp_c @@ -20,14 +20,14 @@ DIR="/proc/acpi/thermal_zone" if [ "$1" = "--detail" ]; then - for i in `ls $DIR`; do + for i in `ls $DIR 2>/dev/null`; do echo "$i:" cat "$DIR/$i"/* done exit 0 fi -for i in $MONITORED_TEMP `ls $DIR/*/temperature`; do +for i in $MONITORED_TEMP `ls $DIR/*/temperature 2>/dev/null`; do t=$(sed -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i") printf "\005{=b kY}%s\005{-}\005{= kY}\260C\005{-} " "$t" break diff --git a/bin/temp_f b/bin/temp_f index c928e090..0fd04078 100755 --- a/bin/temp_f +++ b/bin/temp_f @@ -23,7 +23,7 @@ if [ "$1" = "--detail" ]; then exit 0 fi -for i in `ls $DIR/*/temperature`; do +for i in `ls $DIR/*/temperature 2>/dev/null`; do t=$(sed -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i" | awk '{printf "%.0f", $1 *9/5 + 32}') printf "\005{=b kY}%s\005{-}\005{= kY}\260F\005{-} " "$t" break diff --git a/bin/updates_available b/bin/updates_available index 117cb14b..9bcb389c 100755 --- a/bin/updates_available +++ b/bin/updates_available @@ -80,7 +80,8 @@ PKG="byobu" # I would welcome contributions from other distros to make this # more distro-agnostic. -mycache="/var/run/screen/S-$USER/$PKG.updates-available" +[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$HOME/.byobu" +mycache="$DIR/$PKG.updates-available" if [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]; then # If apt is newer than mycache, background an update now diff --git a/debian/changelog b/debian/changelog index ff6b4528..9bb84cb9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,10 @@ byobu (2.33) unreleased; urgency=low - * UNRELEASED + * cpu_count, disk, logo, network, reboot_required, release, temp_c, + temp_f, updates_available: make byobu status scripts friendlier + for busybox environments (tested on the Palm Pre) - -- Dustin Kirkland Fri, 11 Sep 2009 08:04:05 -0500 + -- Dustin Kirkland Mon, 14 Sep 2009 23:47:29 -0500 byobu (2.32-0ubuntu1) karmic; urgency=low