* usr/bin/byobu-status, usr/lib/byobu/apport, usr/lib/byobu/arch,

usr/lib/byobu/battery, usr/lib/byobu/.constants,
  usr/lib/byobu/cpu_count, usr/lib/byobu/cpu_freq,
  usr/lib/byobu/cpu_temp, usr/lib/byobu/custom, usr/lib/byobu/date,
  usr/lib/byobu/disk, usr/lib/byobu/disk_io, usr/lib/byobu/ec2_cost,
  usr/lib/byobu/fan_speed, usr/lib/byobu/hostname,
  usr/lib/byobu/ip_address, usr/lib/byobu/load_average,
  usr/lib/byobu/logo, usr/lib/byobu/mail, usr/lib/byobu/mem_available,
  usr/lib/byobu/mem_used, usr/lib/byobu/menu, usr/lib/byobu/network,
  usr/lib/byobu/notify_osd, usr/lib/byobu/processes,
  usr/lib/byobu/raid, usr/lib/byobu/rcs_cost,
  usr/lib/byobu/reboot_required, usr/lib/byobu/release,
  usr/lib/byobu/services, usr/lib/byobu/.shutil, usr/lib/byobu/swap,
  usr/lib/byobu/time, usr/lib/byobu/time_utc, usr/lib/byobu/trash,
  usr/lib/byobu/updates_available, usr/lib/byobu/uptime,
  usr/lib/byobu/users, usr/lib/byobu/whoami,
  usr/lib/byobu/wifi_quality:
  - rework status scripts into sourcable functions
  - update copyright info, update email address, standardize headers
This commit is contained in:
Dustin Kirkland 2011-06-25 22:53:23 -04:00
commit d44755ede2
41 changed files with 982 additions and 1025 deletions

19
debian/changelog vendored
View file

@ -2,6 +2,25 @@ byobu (4.14) unreleased; urgency=low
* usr/share/byobu/profiles/tmux:
- getting tmux keybindings much closer!
* usr/bin/byobu-status, usr/lib/byobu/apport, usr/lib/byobu/arch,
usr/lib/byobu/battery, usr/lib/byobu/.constants,
usr/lib/byobu/cpu_count, usr/lib/byobu/cpu_freq,
usr/lib/byobu/cpu_temp, usr/lib/byobu/custom, usr/lib/byobu/date,
usr/lib/byobu/disk, usr/lib/byobu/disk_io, usr/lib/byobu/ec2_cost,
usr/lib/byobu/fan_speed, usr/lib/byobu/hostname,
usr/lib/byobu/ip_address, usr/lib/byobu/load_average,
usr/lib/byobu/logo, usr/lib/byobu/mail, usr/lib/byobu/mem_available,
usr/lib/byobu/mem_used, usr/lib/byobu/menu, usr/lib/byobu/network,
usr/lib/byobu/notify_osd, usr/lib/byobu/processes,
usr/lib/byobu/raid, usr/lib/byobu/rcs_cost,
usr/lib/byobu/reboot_required, usr/lib/byobu/release,
usr/lib/byobu/services, usr/lib/byobu/.shutil, usr/lib/byobu/swap,
usr/lib/byobu/time, usr/lib/byobu/time_utc, usr/lib/byobu/trash,
usr/lib/byobu/updates_available, usr/lib/byobu/uptime,
usr/lib/byobu/users, usr/lib/byobu/whoami,
usr/lib/byobu/wifi_quality:
- rework status scripts into sourcable functions
- update copyright info, update email address, standardize headers
-- Dustin Kirkland <kirkland@ubuntu.com> Thu, 16 Jun 2011 16:16:29 -0500

View file

@ -20,6 +20,7 @@
PKG="byobu"
DATA="$HOME/.$PKG"
[ -z "$BYOBU_PREFIX" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX
[ -d "/var/run/screen/S-$USER" ] && RUNDIR="/var/run/screen/S-$USER" || RUNDIR="$DATA"
if ! . "${BYOBU_PREFIX}/lib/${PKG}/.shutil"; then
echo "failed to source ${BYOBU_PREFIX}/lib/${PKG}/.shutil" 2>&1

34
usr/lib/byobu/.constants Executable file
View file

@ -0,0 +1,34 @@
#!/bin/sh
PKG="byobu"
CONFIG_DIR="$HOME/.$PKG"
mkdir -p "$CONFIG_DIR"
if mkdir -p "/var/run/screen/S-$USER/$PKG/cache" 2>/dev/null; then
CACHE_DIR="/var/run/screen/S-$USER/$PKG/cache"
else
mkdir -p "$CONFIG_DIR/cache"
CACHE_DIR="$CONFIG_DIR/cache"
fi
[ -n "$BYOBU_PREFIX" ] || BYOBU_PREFIX="/usr"
if [ "$UTF8" = "1" ]; then
ICON_C="℃"
ICON_F="℉"
ICON_RD="◀"
ICON_WR="▶"
ICON_MAIL="⍌"
ICON_UP="▲"
ICON_DN="▼"
ICON_TRASH="♸"
ICON_WIFI=ICON="⚚"
else
ICON_C="C"
ICON_F="F"
ICON_RD="<"
ICON_WR=">"
ICON_MAIL="[M]"
ICON_UP="^"
ICON_DN="v"
ICON_TRASH="T"
ICON_WIFI=
fi

View file

@ -1,3 +1,5 @@
color 2>/dev/null || color() { true; }
# uncommented_lines(char=#)
# does the standard input have lines that do not start with 'char'?
uncommented_lines() {
@ -81,4 +83,8 @@ readfile() {
return 0
}
metadata_available() {
wget -q -O- --timeout=1 http://169.254.169.254
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# apport: note if there are crash dumps available for apporting
# Copyright (C) 2009 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,10 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__apport_detail() {
if ls /var/crash/*.crash >/dev/null 2>&1; then
printf "\nTo file bugs on the existing crash reports, run:\n"
which apport-cli >/dev/null || printf " sudo apt-get install apport\n"
@ -32,13 +31,14 @@ if [ "$1" = "--detail" ]; then
else
printf "No pending crash reports\n"
fi
exit 0
fi
}
# Print {!} if a /var/crash/*.crash file exists
for i in /var/crash/*.crash; do
color y k; printf "{!}"; color --
exit 0
done
__apport() {
# Print {!} if a /var/crash/*.crash file exists
for i in /var/crash/*.crash; do
color y k; printf "{!}"; color --
return
done
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# arch: print the machine architecture
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,11 +19,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [ "$1" = "--detail" ]; then
__arch_detail() {
uname -a
exit 0
fi
}
printf "%s " $(uname -m)
__arch() {
printf "%s" $(uname -m)
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,39 +1,37 @@
#!/bin/sh -e
#
# battery: print the state of the battery
# Copyright (C) 2009 Raphaël Pinson.
# battery: print the state of the battery
#
# Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2011 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
# the Free Software Foundation, version 3 of the License.
# Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@ubuntu.com>
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 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
# the Free Software Foundation, version 3 of the License.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__battery_detail() {
local bat
for bat in /proc/acpi/battery/*; do
cat "$bat/info"
cat "$bat/state"
done
exit 0
fi
}
battery_info() {
__battery() {
local bat line present sign state percent full rem color bcolor
for bat in $BATTERY /proc/acpi/battery/*; do
[ -f "$bat/info" ] || continue
present=""; full=""; rem=""; state=""
while read line; do
set -- ${line}
@ -46,7 +44,6 @@ battery_info() {
esac
[ -n "$present" -a -n "$full" ] && break
done < "${bat}/info"
while read line; do
set -- ${line}
case "$line" in
@ -55,9 +52,7 @@ battery_info() {
esac
[ -n "$rem" -a -n "$state" ] && break
done < "$bat/state"
percent=$(((100*$rem)/$full))
if [ "$percent" -lt 33 ]; then
color="R k"
bcolor="b R k"
@ -69,7 +64,6 @@ battery_info() {
bcolor="b G k"
fi
percent="$percent%"
case $state in
charging) sign="+" ;;
discharging) sign="-" ;;
@ -81,6 +75,4 @@ battery_info() {
done
}
battery_info "$@"
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# cpu_count: count cpu's on a systems
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,11 +19,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [ "$1" = "--detail" ]; then
__cpu_count_detail() {
grep -i "^model name" /proc/cpuinfo
exit 0
fi
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
[ "$count" = "1" ] || printf "%sx" "$count"
}
__cpu_count() {
local c
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
[ "$c" = "1" ] || printf "%sx" "$c"
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# cpu_freq: calculate current cpu frequency
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,28 +19,27 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__cpu_freq_detail() {
cat /proc/cpuinfo
exit 0
fi
}
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
fpdiv $hz "1000000" 1 # 1Ghz
freq="$_RET"
else
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%.1f", $2 / 1000 }')
__cpu_freq() {
local hz freq count
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
fpdiv $hz "1000000" 1 # 1Ghz
freq="$_RET"
else
# Must scale frequency by number of processors, if counting bogomips
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
freq=$(echo "$freq" "$count" | awk '{printf "%.1f\n", $1/$2/1000}')
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%.1f", $2 / 1000 }')
else
# Must scale frequency by number of processors, if counting bogomips
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
freq=$(echo "$freq" "$count" | awk '{printf "%.1f\n", $1/$2/1000}')
fi
fi
fi
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "GHz"; color --
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "GHz"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,56 +1,56 @@
#!/bin/sh -e
#
# cpu_temp: cpu temperature
# Copyright (C) 2008 Canonical Ltd.
# cpu_temp: cpu temperature
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
CPU_TEMP_DIR="/proc/acpi/thermal_zone"
PKG="byobu"
color 2>/dev/null || color() { true; }
[ "$UTF8" = "1" ] && ICON_C="℃" || ICON_C="C"
[ "$UTF8" = "1" ] && ICON_F="℉" || ICON_F="F"
DIR="/proc/acpi/thermal_zone"
if [ "$1" = "--detail" ] && [ -d "$DIR" ]; then
for i in "$DIR"/*; do
__cpu_temp_detail() {
local i
for i in "$CPU_TEMP_DIR"/*; do
[ -r "$i" ] || continue
echo "$i:"
cat "$i"/*
done
exit 0
fi
}
for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal $DIR/*/temperature; do
case "$i" in
*temp*_input)
[ -s "$i" ] && read t < "$i" && t=$(($t/1000))
;;
*)
[ -s "$i" ] && t=$(sed -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i")
;;
esac
if [ -n "$t" ]; then
unit="$ICON_C"
if [ "$TEMP" = "F" ]; then
t=$(($t*9/5 + 32))
unit="$ICON_F"
__cpu_temp() {
local i t unit
for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal "$CPU_TEMP_DIR"/*/temperature; do
case "$i" in
*temp*_input)
[ -s "$i" ] && read t < "$i" && t=$(($t/1000))
;;
*)
[ -s "$i" ] && t=$(sed -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i")
;;
esac
if [ -n "$t" ]; then
unit="$ICON_C"
if [ "$TEMP" = "F" ]; then
t=$(($t*9/5 + 32))
unit="$ICON_F"
fi
color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s" "$unit"; color --
break
fi
color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s%s" "$ICON" "$unit"; color --
break
fi
done
done
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -3,8 +3,9 @@
# custom: run the user's custom status scripts
#
# Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -18,41 +19,41 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
[ -d "$DATA/bin" ] || exit 0
color 2>/dev/null || color() { true; }
__custom_detail() {
return
}
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$DATA"
NOW=$(date +%s)
CACHE="$DIR/$PKG.custom"
# Loop over custom scripts
for i in "$DATA/bin/"[0-9]*_*; do
[ -x "$i" ] || continue
script=${i##*/}
freq=${script%%_*}
freq=${freq#0}
[ -r "$CACHE.$script.last" ] && read lastrun < "$CACHE.$script.last" || lastrun=0
expiration=$(($lastrun+$freq))
if [ $NOW -ge $expiration ]; then
"$i" "$@" > "$CACHE.$script" 2>/dev/null
echo "${NOW}" > "$CACHE.$script.last"
fi
readfile < "$CACHE.$script"
output="${_RET}"
case "$output" in
*"$ESC{"*)
# User has formatted the colors
OUTPUT="$OUTPUT$(printf "$output")"
;;
*)
# Default to inverted coloring
OUTPUT="$OUTPUT$(color invert; printf "%s" "$output"; color --)"
;;
esac
done
echo "$OUTPUT" | sed ':a;N;$!ba;s/\n//g'
__custom() {
local cache="$CACHE_DIR/custom"
local i= output=
for i in "$HOME/.$PKG/bin/"[0-9]*_*; do
# Loop over custom scripts
[ -x "$i" ] || continue
local now="$(date +%s)"
local script=${i##*/}
local freq=${script%%_*}
freq=${freq#0}
local lastrun=
[ -r "$cache.$script.last" ] && read lastrun < "$cache.$script.last" || lastrun=0
local expiration=$(($lastrun+$freq))
if [ $now -ge $expiration ]; then
"$i" > "$cache.$script" 2>/dev/null
echo "${now}" > "$cache.$script.last"
fi
readfile < "$cache.$script"
local str="${_RET}"
case "$str" in
*"$ESC{"*)
# User has formatted the colors
output="$output$(printf "$str")"
;;
*)
# Default to inverted coloring
output="$output$(color invert; printf "%s" "$str"; color --)"
;;
esac
done
echo -n "$output" | sed ':a;N;$!ba;s/\n//g'
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# date - print the date in YYYY-MM-DD format
# Copyright (C) 2008 Canonical Ltd.
# date: print the date in YYYY-MM-DD format
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,20 +19,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
case "$1" in
--detail)
date
;;
--short)
date +%Y-%m-%d
;;
*)
bd=$(date "+%m%d")
[ "$bd" = "0320" ] &&
msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" &&
screen -X -S "byobu" at "*" echo "[$msg]"
printf "\005Y-\005m-\005d "
;;
esac
__date_detail() {
date
}
__date() {
bd=$(date "+%m%d")
[ "$bd" = "0320" ] && msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" && screen -X -S "byobu" at "*" echo "[$msg]"
printf "\005Y-\005m-\005d"
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# disk: print the current disk space and usage
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,39 +19,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__disk_detail() {
df -h -P
exit 0
fi
}
# Default to /, but let users override
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
case $MP in
/dev/*) MP=$(awk '$1 == m { print $2; exit(0); }' "m=$MP" /proc/mounts);;
esac
get_size_pct() {
__disk() {
local out="" MP="" size="" pct="" unit=""
# Default to /, but let users override
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
case $MP in
/dev/*) MP=$(awk '$1 == m { print $2; exit(0); }' "m=$MP" /proc/mounts);;
esac
# this could be done faster with 'stat --file-system --format'
# but then we'd have to do blocks -> human units ourselves
local out="" MP=$1 size="" pct="" unit=""
out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } |
awk 'END { printf("%s %s", $2, $5); }')
out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } | awk 'END { printf("%s %s", $2, $5); }')
set -- ${out}
size=${1}; pct=${2};
unit=${size#${size%?}} # get the unit (last char)
size=${size%?}; # take the unit off
pct=${pct%?}; # take off the '%'
_UNIT=${unit}; _SIZE=${size}; _PCT=${pct};
color b M W; echo -n "$_SIZE"; color -; color M W; echo -n "${_UNIT}B,"; color -;
color b M W; echo -n "$_PCT"; color -; color M W; echo -n "%" ; color --;
}
get_size_pct "${MP}"
color b M W; echo -n "$_SIZE"; color -; color M W; echo -n "${_UNIT}B,"; color -;
color b M W; echo -n "$_PCT"; color -; color M W; echo -n "%" ; color --;
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# disk_io: calculate the disk io rate
# Copyright (C) 2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2010 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,9 +19,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
__disk_io_detail() {
if command -v iostat >/dev/null; then
iostat -d -m -h
else
echo "Please install iostat if you want detailed information on your disk throughput"
fi
}
getdisk() {
local t=""
if [ -L "${1}" ]; then
@ -32,71 +40,60 @@ getdisk() {
[ -h "/sys/block/$t" ] && _RET="$t" || rtrim "$t" "0-9"
}
[ "$UTF8" = "1" ] && ICON_RD="◀" || ICON_RD="<"
[ "$UTF8" = "1" ] && ICON_WR="▶" || ICON_WR=">"
# Default to disk providing /, but let users override with MONITORED_DISK
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
# By default, we won't bug the user with the display of network traffic
# below DISK_IO_THRESHOLD in kB/s; override in $DATA/status
[ -n "$DISK_IO_THRESHOLD" ] || DISK_IO_THRESHOLD=50
if [ "$1" = "--detail" ]; then
if command -v iostat >/dev/null; then
iostat -d -m -h
else
echo "Please install iostat if you want detailed information on your disk throughput"
fi
exit 0
fi
case "$MP" in
/dev/*) part="${MP}";;
*) part=$(awk '$2 == mp { print $1 ; exit(0); }' "mp=$MP" /etc/mtab);;
esac
getdisk "$part"
disk=${_RET}
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$DATA"
t2=`date +%s`
for i in "read" "write"; do
cache="$DIR/$PKG.disk_$i"
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
unit="kB/s"
if [ $t2 -le $t1 ]; then
rate=0
else
[ -r "$cache" ] && read x1 < "$cache" || x1=0
read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 other < "/sys/block/$disk/stat"
if [ "$i" = "read" ]; then
symbol="$ICON_RD"
x2="$a3"
else
symbol="$ICON_WR"
x2="$a7"
fi
echo "$x2" > "$cache"
rate=$((($x2 - $x1) / ($t2 - $t1) * 512 / 1024))
if [ $rate -lt $DISK_IO_THRESHOLD ]; then
# Below threshold, exit immediately!
exit 0
elif [ "$rate" -lt 0 ]; then
__disk_io() {
local part= i=
# Default to disk providing /, but let users override with MONITORED_DISK
[ -z "$MONITORED_DISK" ] && mount_point="/" || mount_point="$MONITORED_DISK"
# By default, we won't bug the user with the display of network traffic
# below DISK_IO_THRESHOLD in kB/s; override in $CONFIG_DIR/status
[ -n "$DISK_IO_THRESHOLD" ] || DISK_IO_THRESHOLD=50
case "$mount_point" in
/dev/*) part="${mount_point}";;
*) part=$(awk '$2 == mp { print $1 ; exit(0); }' "mp=$mount_point" /etc/mtab);;
esac
getdisk "$part"
local disk=${_RET}
local t2=`date +%s` t1=
for i in "read" "write"; do
local cache="$CACHE_DIR/disk.$i"
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
local unit="kB/s"
local rate= x1= x2= symbol= unit=
if [ $t2 -le $t1 ]; then
rate=0
elif [ "$rate" -gt 1048576 ]; then
unit="GB/s"
fpdiv "$rate" 1048576 0
rate=${_RET}
elif [ "$rate" -gt 1024 ]; then
unit="MB/s"
fpdiv "$rate" 1024 0
rate=${_RET}
else
unit="kB/s"
[ -r "$cache" ] && read x1 < "$cache" || x1=0
local a1= a2= a3= a4= a5= a6= a7= a8= a9= a10=
read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 other < "/sys/block/$disk/stat"
if [ "$i" = "read" ]; then
symbol="$ICON_RD"
x2="$a3"
else
symbol="$ICON_WR"
x2="$a7"
fi
echo "$x2" > "$cache"
rate=$((($x2 - $x1) / ($t2 - $t1) * 512 / 1024))
if [ $rate -lt $DISK_IO_THRESHOLD ]; then
# Below threshold, don't print
continue
elif [ "$rate" -lt 0 ]; then
rate=0
elif [ "$rate" -gt 1048576 ]; then
unit="GB/s"
fpdiv "$rate" 1048576 0
rate=${_RET}
elif [ "$rate" -gt 1024 ]; then
unit="MB/s"
fpdiv "$rate" 1024 0
rate=${_RET}
else
unit="kB/s"
fi
fi
fi
[ "$rate" != "0" ] || continue
color b M W; printf "%s%s" "$symbol" "$rate"; color -; color M W; printf "%s" "$unit"; color --
done
[ "$rate" != "0" ] || continue
color b M W; printf "%s%s" "$symbol" "$rate"; color -; color M W; printf "%s" "$unit"; color --
done
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh
#!/bin/sh -e
#
# ec2_cost: approximate EC2 cost (USD) of the current instance
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,55 +19,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
DETAIL=0
PKG="byobu"
DATA="$HOME/.$PKG"
[ -z "$BYOBU_PREFIX" ] && BYOBU_PREFIX="/usr"
color 2>/dev/null || color() { true; }
for arg in $@; do
case "$arg" in
-d|--detail)
DETAIL=1
;;
esac
done
# Try to use metadata service
if host 169.254.169.254 >/dev/null 2>&1; then
zone=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone)
. "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}"
type=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-type | sed -e "s/\./_/g")
eval RATE="\$$type"
file_to_stat="$DATA/.ec2_instance_type"
[ -f "$file_to_stat" ] || wget -q -O "$file_to_stat" http://169.254.169.254/latest/meta-data/instance-type
else
. "$BYOBU_PREFIX/share/$PKG/ec2/rates."*
# Count CPUs, Memory, Architecture, hours
cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1
mem=$(grep ^MemTotal /proc/meminfo | awk '{print $2}')
# /etc/hostname gets created at installation (but might get updated...other ideas?)
file_to_stat="/etc/hostname"
# Guess this system's going rate, based on mem available (m* types)
if [ $mem -lt 700000 ]; then
RATE=$t1_micro
elif [ $mem -gt 64000000 ]; then
RATE=$m2_4xlarge
elif [ $mem -gt 32000000 ]; then
RATE=$m2_2xlarge
elif [ $mem -gt 16000000 ]; then
RATE=$m2_xlarge
elif [ $mem -gt 14000000 ]; then
RATE=$m1_xlarge
elif [ $mem -gt 7000000 ]; then
RATE=$m1_large
else
# Otherwise, scale based on number of cpu's (c* types)
RATE=$(echo "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}')
fi
fi
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
# Data Transfer Cost Basis
# Incoming $0.10/GB
# Outgoing $0.17/GB
@ -73,38 +26,75 @@ hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
RX_RATE="0.10"
TX_RATE="0.15"
# Auto detect network interface
IF=`tail -n1 /proc/net/route | awk '{print $1}'`
__ec2_cost_detail() {
DETAIL=1
__ec2_cost
}
ifconfig_out=`LC_ALL=C /sbin/ifconfig "$IF"`
# Calculate bandwidth cost
tx_gb=${ifconfig_out#*RX bytes:}
tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
rx_gb=${ifconfig_out#*TX bytes:}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
# Calculate uptime cost
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$RATE" * $hours}"`
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
if [ "$DETAIL" = "1" ]; then
echo "================================================"
echo "Estimated cost in Amazon's EC2 since last reboot"
echo "================================================"
echo " Network sent: $tx_gb GB @ \$$RX_RATE/GB"
echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB"
echo " Network cost: \$$network_cost"
echo "------------------------------------------------"
echo " Uptime: $hours hr @ \$$RATE/hr"
echo " Uptime cost: \$$uptime_cost"
echo "------------------------------------------------"
echo "Total cost: ~\$$total_cost"
echo "================================================"
exit 0
fi
color K G; printf "A\$"; color -; color b K G; printf "%s" "$total_cost"; color --
__ec2_cost() {
local zone type file_to_stat cpu mem rate hours tx_gb rx_gb network_cost uptime_cost total_cost interface
# Try to use metadata service
if metadata_available; then
zone=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone)
. "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}"
type=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-type | sed -e "s/\./_/g")
eval rate="\$$type"
file_to_stat="$CACHE_DIR/ec2_cost.instance_type"
[ -f "$file_to_stat" ] || wget -q -O "$file_to_stat" http://169.254.169.254/latest/meta-data/instance-type
else
. "$BYOBU_PREFIX/share/$PKG/ec2/rates."*
# Count CPUs, Memory, Architecture, hours
cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1
mem=$(grep ^MemTotal /proc/meminfo | awk '{print $2}')
# /etc/hostname gets created at installation (but might get updated...other ideas?)
file_to_stat="/etc/hostname"
# Guess this system's going rate, based on mem available (m* types)
if [ $mem -lt 700000 ]; then
rate=$t1_micro
elif [ $mem -gt 64000000 ]; then
rate=$m2_4xlarge
elif [ $mem -gt 32000000 ]; then
rate=$m2_2xlarge
elif [ $mem -gt 16000000 ]; then
rate=$m2_xlarge
elif [ $mem -gt 14000000 ]; then
rate=$m1_xlarge
elif [ $mem -gt 7000000 ]; then
rate=$m1_large
else
# Otherwise, scale based on number of cpu's (c* types)
rate=$(echo "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}')
fi
fi
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
# Auto detect network interface
interface=`tail -n1 /proc/net/route | awk '{print $1}'`
ifconfig_out=`LC_ALL=C /sbin/ifconfig "$interface"`
# Calculate bandwidth cost
tx_gb=${ifconfig_out#*RX bytes:}
tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
rx_gb=${ifconfig_out#*TX bytes:}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
# Calculate uptime cost
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$rate" * $hours}"`
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
if [ "$DETAIL" = "1" ]; then
echo "================================================"
echo "Estimated cost in Amazon's EC2 since last reboot"
echo "================================================"
echo " Network sent: $tx_gb GB @ \$$RX_RATE/GB"
echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB"
echo " Network cost: \$$network_cost"
echo "------------------------------------------------"
echo " Uptime: $hours hr @ \$$rate/hr"
echo " Uptime cost: \$$uptime_cost"
echo "------------------------------------------------"
echo "Total cost: ~\$$total_cost"
echo "================================================"
return
fi
color K G; printf "A\$"; color -; color b K G; printf "%s" "$total_cost"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,35 +1,32 @@
#!/bin/sh -e
#
# fan_speed: speed of the cpu or case fan
# Copyright (C) 2009 Canonical Ltd.
# fan_speed: speed of the cpu or case fan
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# 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
# the Free Software Foundation, version 3 of the License.
# Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
__fan_speed_detail() {
# Nothing interesting to say here about fan speed
return
}
DIR="/sys/class/hwmon"
# Nothing interesting to say here about fan speed
[ "$1" = "--detail" ] && exit 0
# Let's check a few different probes for fan speed
fan_speed_info() {
__fan_speed() {
local i="" speed=0
# Let's check a few different probes for fan speed
# This seems to cover most of them:
for i in /sys/class/hwmon/*/*/fan1_input; do
[ -f "$i" ] || continue
@ -58,7 +55,4 @@ fan_speed_info() {
fi
}
fan_speed_info "$@"
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,7 +1,9 @@
#!/bin/sh -e
#
# hostname - report a host's name
# hostname: report a host's name
#
# Copyright (C) 2008-2011 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
@ -17,22 +19,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__hostname_detail() {
hostname -f
exit 0
fi
}
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" "$h"; color --
__hostname() {
if metadata_available; 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" "$h"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,7 +1,9 @@
#!/bin/sh -e
#
# ip_address - report a host's ip address
# ip_address: report a host's ip address
#
# Copyright (C) 2008-2011 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
@ -17,51 +19,43 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__ip_address_detail() {
[ -x /sbin/ifconfig ] && /sbin/ifconfig
/sbin/ip -4 addr list
/sbin/ip -6 addr list
exit 0
fi
}
. "$DATA/status"
# Allow interface overrides in $DATA/statusrc
if [ -n "$MONITORED_NETWORK" ]; then
interface="$MONITORED_NETWORK"
else
__ip_address() {
local interface ipaddr
# Allow interface overrides in $CONFIG_DIR/statusrc
if [ -n "$MONITORED_NETWORK" ]; then
interface="$MONITORED_NETWORK"
else
case "$IPV6" in
1|true|yes) interface=$(awk '$10 != "lo" { iface=$10 ; }; END { print iface; }' /proc/net/ipv6_route);;
*) interface=$(awk 'END {print $1}' /proc/net/route);;
esac
fi
case "$IPV6" in
1|true|yes)
interface=$(awk '$10 != "lo" { iface=$10 ; }; END { print iface; }' \
/proc/net/ipv6_route);;
*) interface=$(awk 'END {print $1}' /proc/net/route);;
esac
fi
case "$IPV6" in
1|true|yes)
ipaddr=$(LC_ALL=C /sbin/ip -6 addr list dev "$interface" scope global)
# Print 'None' if we have no global address
[ -z "$ipaddr" ] && ipaddr="None"
ipaddr=${ipaddr#* inet6 }
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=$(LC_ALL=C /sbin/ip -6 addr list dev "$interface" scope global)
# Print 'None' if we have no global address
[ -z "$ipaddr" ] && ipaddr="None"
ipaddr=${ipaddr#* inet6 }
ipaddr=${ipaddr%%/*}
fi
;;
esac
color bold2; printf "%s" "$ipaddr"; color --
;;
*)
if metadata_available; 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
color bold2; printf "%s" "$ipaddr"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# load_average: grab the current load average
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,14 +19,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__load_average_detail() {
cat /proc/loadavg
exit 0
fi
read one five fifteen other < /proc/loadavg
color Y k; printf "$one"; color --
}
__load_average() {
read one five fifteen other < /proc/loadavg
color Y k; printf "$one"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# logo: determine which logo to use
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,19 +19,38 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
get_distro() {
_RET=
if [ -n "$DISTRO" ]; then
# Allow manual override of distro in $CONFIG_DIR/status
_RET="$DISTRO"
elif [ -r "/etc/issue" ]; then
# Otherwise, check /etc/issue
_RET=`grep -m1 "^[A-Za-z]" /etc/issue`
elif which lsb_release >/dev/null 2>&1; then
# This can be a very expensive operation, do it only
# if all other methods fail
_RET=`lsb_release -s -a 2>/dev/null`
else
# No idea!
printf "[B]"
fi
}
if [ "$1" = "--detail" ]; then
__logo_detail() {
MARKUP="false"
exit 0
else
MARKUP="true"
fi
__logo
}
print_logo() {
distro=`echo "$1" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' `
__logo() {
local logo=
if [ -n "$LOGO" ]; then
# Allow users to define their own logo in $CONFIG_DIR/status
printf "%s" "$LOGO"
return
fi
get_distro
local distro="$(echo "$_RET" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')"
case "$distro" in
*ubuntu*)
if $MARKUP; then
@ -97,30 +118,4 @@ print_logo() {
esac
}
if [ -n "$LOGO" ]; then
# Allow users to define their own logo in $DATA/status
printf "%s" "$LOGO" && exit 0 || true
fi
if [ -n "$DISTRO" ]; then
# Allow manual override of distro in $DATA/status
print_logo "$DISTRO" && exit 0 || true
fi
if [ -r "/etc/issue" ]; then
# Otherwise, check /etc/issue
distro=`grep -m1 "^[A-Za-z]" /etc/issue`
print_logo "$distro" && exit 0 || true
fi
# This can be a very expensive operation, do it only
# if all other methods fail
if which lsb_release >/dev/null 2>&1; then
distro=`lsb_release -s -a 2>/dev/null`
print_logo "$distro" && exit 0 || true
fi
# No idea!
printf "|B|"
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# mail: notify the user if they have system mail
# Copyright (C) 2009 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,18 +19,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
[ "$UTF8" = "1" ] && ICON="⍌" || ICON="[M]"
MAILFILE="/var/spool/mail/$USER"
mailfile="/var/spool/mail/$USER"
if [ "$1" = "--detail" ]; then
[ -s "$mailfile" ] && ls -alF "$mailfile" 2>&1
exit 0
fi
__mail_detail() {
[ -s "$MAILFILE" ] && ls -alF "$MAILFILE" 2>&1
}
if [ -s "$mailfile" ]; then
color b; printf "%s" "$ICON"; color --
fi
__mail() {
if [ -s "$MAILFILE" ]; then
color b; printf "%s" "$ICON_MAIL"; color --
fi
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# mem: grab the current memory and usage
# Copyright (C) 2008 Canonical Ltd.
# mem_available: grab the current memory and usage
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,20 +19,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__mem_available_detail() {
free
exit 0
fi
}
mem_available_info() {
__mem_available() {
local mem_used comma whitespace unit mem name
. "$DATA/status"
. "$CONFIG_DIR/status"
[ "$mem_used" = "1" ] && comma="," || whitespace=" "
read name mem unit < /proc/meminfo
if [ $mem -ge 1048576 ]; then
fpdiv "$mem" 1048567 1
@ -47,6 +43,4 @@ mem_available_info() {
color b g W; printf "%s" "$mem"; color -; color g W; printf "%s%s" "$unit" "$comma"; color -; printf "%s" "$whitespace"
}
mem_available_info "$@"
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# mem_used: grab the current memory usage
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,20 +19,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__mem_used_detail() {
cat /proc/meminfo
exit 0
fi
}
meminfo_used() {
__mem_used() {
# originally, this script did:
# f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
# this method is more dependent on /proc/meminfo, but uses the same formula
# for deriving the output of 'free' that is used in procps 'free.c'
# kb_main_free, kb_main_total, kb_main_buffers, kb_main_cached
local free="" total="" buffers="" cached=""
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
@ -43,24 +40,14 @@ meminfo_used() {
esac
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
done < /proc/meminfo
kb_main_used=$(($total-$free))
buffers_plus_cached=$(($buffers+$cached))
# "free output" buffers and cache (output from 'free')
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
fo_cached=$(($kb_main_free + $buffers_plus_cached))
fpdiv $((100*${fo_buffers})) "${total}" 0;
f=${_RET}
color b g W; printf "%s" "$f"; color -; color g W; printf "%%"; color --
}
if [ -r /proc/meminfo ]; then
meminfo_used
f=${_RET}
else
f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
fi
color b g W; printf "%s" "$f"; color -; color g W; printf "%%"; color --
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# menu: display the menu text
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,23 +19,23 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
[ "$1" = "--detail" ] && exit 0
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
__menu_detail() {
return
}
[ -r "$DATA/keybindings" ] && bindings="$DATA/keybindings" || bindings="$HOME/.screenrc"
if grep -qs "^source.*screen-escape-keys$" $bindings 2>/dev/null || [ "$1" = "--disable-f-keys" ]; then
esc=`grep "^escape" $bindings | sed "s/^.*\(.\)$/\1/"`
[ -n "$esc" ] && key="^$esc-@" || key="^a-@"
elif grep -qs "^source.*none$" $bindings 2>/dev/null; then
key="byobu-config"
else
key="F9"
fi
text=$(gettext "Menu")
color k w; printf "%s:<" "$text"; color -; color b k w; printf "%s" "$key"; color k w; printf ">"
__menu() {
local bindings esc key text
[ -r "$CONFIG_DIR/keybindings" ] && bindings="$CONFIG_DIR/keybindings" || bindings="$HOME/.screenrc"
if grep -qs "^source.*screen-escape-keys$" $bindings 2>/dev/null || [ "$1" = "--disable-f-keys" ]; then
esc=`grep "^escape" $bindings | sed "s/^.*\(.\)$/\1/"`
[ -n "$esc" ] && key="^$esc-@" || key="^a-@"
elif grep -qs "^source.*none$" $bindings 2>/dev/null; then
key="byobu-config"
else
key="F9"
fi
text=$(gettext "Menu")
color k w; printf "%s:<" "$text"; color -; color b k w; printf "%s" "$key"; color k w; printf ">"
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# network: calculate the network up/down rates
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,88 +19,86 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
[ "$UTF8" = "1" ] && ICON_UP="▲" || ICON_UP="^"
[ "$UTF8" = "1" ] && ICON_DN="▼" || ICON_DN="v"
# Allow interface overrides in $DATA/status
if [ -n "$MONITORED_NETWORK" ]; then
interface="$MONITORED_NETWORK"
else
# get the last interface listed in /proc/net/route
while read cn other; do interface=$cn; done < /proc/net/route
fi
# By default, we won't bug the user with the display of network traffic
# below NETWORK_THRESHOLD in kbps; override in $DATA/status
[ -n "$NETWORK_THRESHOLD" ] || NETWORK_THRESHOLD=20
if [ "$1" = "--detail" ]; then
LC_ALL=C /sbin/ifconfig "$interface" | sed 's/\s*$//'
exit 0
fi
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$DATA"
t2=`date +%s`
OIFS=$IFS
for i in up down; do
unit="kbps"
case $i in
up) symbol="$ICON_UP" ;;
down) symbol="$ICON_DN" ;;
esac
cache="$DIR/$PKG.network_$i"
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
if [ $t2 -le $t1 ]; then
rate=0
get_interface() {
_RET=
# Allow interface overrides in $CONFIG_DIR/status
if [ -n "$MONITORED_NETWORK" ]; then
_RET="$MONITORED_NETWORK"
else
[ -r "$cache" ] && read x1 < "$cache" || tx1=0
IFS="$OIFS:"
while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do
if [ "$iface" = "${interface}" ]; then
[ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes}
break;
fi
done < /proc/net/dev
IFS=$OIFS
echo "$x2" > "$cache"
rate=$((8*($x2 - $x1) / ($t2 - $t1) / 1024)) # in kbps
[ "$rate" -lt 0 ] && rate=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
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
fi
# get the last interface listed in /proc/net/route
while read cn other; do _RET=$cn; done < /proc/net/route
fi
done
}
__network_detail() {
get_interface; local interface="$_RET"
LC_ALL=C /sbin/ifconfig "$interface" | sed 's/\s*$//'
}
__network() {
get_interface; local interface="$_RET"
# By default, we won't bug the user with the display of network traffic
# below NETWORK_THRESHOLD in kbps; override in $CONFIG_DIR/status
[ -n "$NETWORK_THRESHOLD" ] || NETWORK_THRESHOLD=20
t2=`date +%s`
OIFS=$IFS
for i in up down; do
unit="kbps"
case $i in
up) symbol="$ICON_UP" ;;
down) symbol="$ICON_DN" ;;
esac
cache="$CACHE_DIR/network.$i"
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
if [ $t2 -le $t1 ]; then
rate=0
else
[ -r "$cache" ] && read x1 < "$cache" || tx1=0
IFS="$OIFS:"
while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do
if [ "$iface" = "${interface}" ]; then
[ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes}
break;
fi
done < /proc/net/dev
IFS=$OIFS
echo "$x2" > "$cache"
rate=$((8*($x2 - $x1) / ($t2 - $t1) / 1024)) # in kbps
[ "$rate" -lt 0 ] && rate=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
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
fi
fi
done
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# notify_osd: print notify-osd messages in screen's notification buffer
# Copyright (C) 2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2010 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
# with help from Mathias Gug <mathias.gug@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
@ -18,23 +20,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
LOG="$HOME"/.cache/notify-osd.log
[ -z "$BYOBU_PREFIX" ] && BYOBU_PREFIX="/usr"
NOTIFY_OSD_LOG="$HOME"/.cache/notify-osd.log
case "$1" in
--short)
exit 0
;;
--detail)
cat "$LOG" || true
exit 0
;;
esac
__notify_osd_detail() {
cat "$NOTIFY_OSD_LOG" || true
}
# This line operates basically as a daemon, watching the notify-osd log file,
# processing new messages and sending them to screen
CMD="tail --pid $PPID -n 0 -F $LOG"
pkill -f "$CMD" || true
$CMD | $BYOBU_PREFIX/lib/byobu/.notify_osd "$PPID"
__notify_osd() {
# This line operates basically as a daemon, watching the notify-osd log file,
# processing new messages and sending them to screen
CMD="tail --pid $PPID -n 0 -F $NOTIFY_OSD_LOG"
pkill -f "$CMD" || true
$CMD | $BYOBU_PREFIX/lib/byobu/.notify_osd "$PPID" &
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# processes - report number of running processes
# Copyright (C) 2008 Canonical Ltd.
# processes: report number of running processes
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,15 +19,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__processes_detail() {
ps -ejH
exit 0
fi
}
count=$(ls -d /proc/[0-9]* 2>/dev/null| wc -l)
color b y w; printf "%s" "$count"; color -; color y w; printf "&"; color --
__processes() {
local count=$(ls -d /proc/[0-9]* 2>/dev/null| wc -l)
color b y w; printf "%s" "$count"; color -; color y w; printf "&"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# raid: notify raid events, failures and syncing
# Copyright (C) 2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2010 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,33 +19,24 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
[ -r /proc/mdstat ] || exit 0
__raid_detail() {
[ -r /proc/mdstat ] && cat /proc/mdstat || true
}
PKG="byobu"
color 2>/dev/null || color() { true; }
case $1 in
--detail)
cat /proc/mdstat
exit 0
;;
esac
pct="%"
while read line; do
# Errors in your raid
case "$line" in
*\ blocks\ *\[*_*\]$)
[ -z "${msg}" ] && msg="RAID";;
*%*)
p="${line%%${pct}*}${pct}"; p=${p##* };
[ -z "$msg" ] && msg="RAID"
msg="$msg,$p";;
esac
done < /proc/mdstat
if [ -n "$msg" ]; then
color B w r; printf "%s" "$msg"; color --
fi
__raid() {
while read line; do
local pct="%" p msg
# Errors in your raid
case "$line" in
*\ blocks\ *\[*_*\]$)
[ -z "${msg}" ] && msg="RAID";;
*%*)
p="${line%%${pct}*}${pct}"; p=${p##* };
[ -z "$msg" ] && msg="RAID"
msg="$msg,$p";;
esac
done < /proc/mdstat
[ -z "$msg" ] || color B w r; printf "%s" "$msg"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,11 +1,12 @@
#!/bin/sh
#!/bin/sh -e
#
# rcs_cost: approximate Rackspace Cloud Server cost (USD) of the current
# instance
# rcs_cost: approximate Rackspace Cloud Server cost (USD) of the current instance
#
# Copyright (C) 2009-2010 Jon Bernard
# Copyright (C) 2011 Dustin Kirkland
#
# Author: Jon Bernard <jbernard@debian.org>
# Author(s): Jon Bernard <jbernard@debian.org>
# Dustin Kirkland <kirkland@ubuntu.com>
#
# Derived from byobu's ec2_cost written by Dustin Kirkland, see
# Byobu's project page: https://launchpad.net/byobu for more information
@ -22,80 +23,75 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
DETAIL=0
PKG="byobu"
color 2>/dev/null || color() { true; }
__rcs_cost_detail() {
DETAIL=1
__rcs_cost
}
for arg in $@; do
case "$arg" in
-d|--detail)
DETAIL=1
;;
esac
done
__rcs_cost() {
# Approximate Instance Cost Basis
# Memory US
# 256MB $0.015/h
# 512MB $0.030/h
# 1024MB $0.060/h
# 2048MB $0.120/h
# 4096MB $0.240/h
# 8192MB $0.480/h
# 15872MB $0.960/h
# Approximate Instance Cost Basis
# Memory US
# 256MB $0.015/h
# 512MB $0.030/h
# 1024MB $0.060/h
# 2048MB $0.120/h
# 4096MB $0.240/h
# 8192MB $0.480/h
# 15872MB $0.960/h
# Instance memory
memory=`grep "^MemTotal:" /proc/meminfo | awk '{print $2}'`
# Instance memory
memory=`grep "^MemTotal:" /proc/meminfo | awk '{print $2}'`
# Round memory down to the nearest multiple of 64MB
memory=$((${memory} - (${memory} % (64 * 1024))))
# Round memory down to the nearest multiple of 64MB
memory=$((${memory} - (${memory} % (64 * 1024))))
# Apply the going rate
INCREMENTS="256 512 1024 2048 4096 8192 16384 32768 65536"
for X in ${INCREMENTS}; do
test "$((${X} * 1024 + 65536))" -ge ${memory} && break
done
MEMORY_RATE=`echo "$X" | awk '{printf "%f", $1 / 256 * 15 / 1000}'`
# Apply the going rate
INCREMENTS="256 512 1024 2048 4096 8192 16384 32768 65536"
for X in ${INCREMENTS}; do
test "$((${X} * 1024 + 65536))" -ge ${memory} && break
done
MEMORY_RATE=`echo "$X" | awk '{printf "%f", $1 / 256 * 15 / 1000}'`
# Data Transfer Cost Basis
# Incoming $0.08/GB
# Outgoing $0.22/GB
RX_RATE="0.08"
TX_RATE="0.22"
# Data Transfer Cost Basis
# Incoming $0.08/GB
# Outgoing $0.22/GB
RX_RATE="0.08"
TX_RATE="0.22"
# Auto detect network interface
IF=`tail -n1 /proc/net/route | awk '{print $1}'`
# Auto detect network interface
IF=`tail -n1 /proc/net/route | awk '{print $1}'`
ifconfig_out=`LC_ALL=C /sbin/ifconfig "$IF"`
ifconfig_out=`LC_ALL=C /sbin/ifconfig "$IF"`
# Calculate bandwidth cost
tx_gb=${ifconfig_out#*RX bytes:}
tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
rx_gb=${ifconfig_out#*TX bytes:}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
# Calculate bandwidth cost
tx_gb=${ifconfig_out#*RX bytes:}
tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
rx_gb=${ifconfig_out#*TX bytes:}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
# Calculate uptime cost
hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1))
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$MEMORY_RATE" * $hours}"`
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
# Calculate uptime cost
hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1))
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$MEMORY_RATE" * $hours}"`
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
if [ "$DETAIL" = "1" ]; then
echo "=========================================================="
echo "Estimated cost in Rackspace Cloud Server since last reboot"
echo "=========================================================="
echo " Network sent: $tx_gb GB @ \$$RX_RATE/GB"
echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB"
echo " Network cost: \$$network_cost"
echo "----------------------------------------------------------"
echo " Uptime: $hours hr @ \$$MEMORY_RATE/hr"
echo " Uptime cost: \$$uptime_cost"
echo "----------------------------------------------------------"
echo "Total cost: ~\$$total_cost"
echo "=========================================================="
return
fi
if [ "$DETAIL" = "1" ]; then
echo "=========================================================="
echo "Estimated cost in Rackspace Cloud Server since last reboot"
echo "=========================================================="
echo " Network sent: $tx_gb GB @ \$$RX_RATE/GB"
echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB"
echo " Network cost: \$$network_cost"
echo "----------------------------------------------------------"
echo " Uptime: $hours hr @ \$$MEMORY_RATE/hr"
echo " Uptime cost: \$$uptime_cost"
echo "----------------------------------------------------------"
echo "Total cost: ~\$$total_cost"
echo "=========================================================="
exit 0
fi
color K G; printf "R\$%s"; color -; color b K G; printf "%s" "$total_cost"; color --
color K G; printf "R\$%s"; color -; color b K G; printf "%s" "$total_cost"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# reboot_required: determine if a reboot is required
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,29 +19,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
REBOOT_FLAG="/var/run/reboot-required"
RELOAD_FLAG="$CACHE_DIR/reload-required"
reboot="/var/run/reboot-required"
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$DATA"
reload="$DIR/$PKG.reload-required"
case "$1" in
--detail)
[ -e "$reboot" ] && ls -alF "$reboot" 2>&1
[ -e "$reload" ] && ls -alF "$reload" 2>&1
;;
--short)
[ -e "$reboot" ] && printf "Yes" || printf "No"
;;
*)
if [ -e "$reboot" ]; then
color b W; printf "("; color -; color b b W; printf "R"; color -; color b W; printf ")"; color --
fi
if [ -e "$reload" ]; then
color b W; printf "<"; color -; color b b W; printf "F5"; color -; color b W; printf ">"; color -; printf " "
fi
;;
esac
__reboot_required_detail() {
[ -e "$REBOOT_FLAG" ] && ls -alF "$REBOOT_FLAG" 2>&1
[ -e "$RELOAD_FLAG" ] && ls -alF "$RELOAD_FLAG" 2>&1
}
__reboot_required() {
if [ -e "$REBOOT_FLAG" ]; then
color b W; printf "("; color -; color b b W; printf "R"; color -; color b W; printf ")"; color --
fi
if [ -e "$RELOAD_FLAG" ]; then
color b W; printf "<"; color -; color b b W; printf "F5"; color -; color b W; printf ">"; color -; printf " "
fi
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# release: grab the os/distro release
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,15 +19,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
__release_detail() {
lsb_release -a 2>/dev/null
}
if [ "$1" = "--detail" ]; then
cat /etc/issue
exit 0
fi
release_info() {
__release() {
local DISTRO="${DISTRO}" issue ver r i
if [ -n "$DISTRO" ]; then
# user defined
@ -49,10 +47,6 @@ release_info() {
;;
esac
elif command -v lsb_release >/dev/null 2>&1; then
if [ "$1" = "--detail" ]; then
lsb_release -a 2>/dev/null
exit 0
fi
# If lsb_release is available, use it
r=$(lsb_release -s -d)
case "$r" in
@ -71,10 +65,7 @@ release_info() {
else
DISTRO="Byobu"
fi
color bold2; printf "%s" "$DISTRO"; color --
}
release_info "$@"
# vi: syntax=sh ts=4 noexpandtab

View file

@ -3,8 +3,9 @@
# services: show what services are running on this server (configurable)
#
# Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -18,21 +19,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__services_detail() {
return
}
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
# Users can define a list of SERVICES to monitor in $DATA/status
if [ -z "$SERVICES" ]; then
if [ -f "/etc/eucalyptus/eucalyptus.conf" ]; then
# If the user has not defined any SERVICES, but this system is a
# UEC system, default to the list of Ubuntu Enterprise Cloud Services
SERVICES="eucalyptus-cloud|CLC eucalyptus-walrus|WC eucalyptus-cc|CC eucalyptus-sc|SC eucalyptus-nc|NC"
fi
fi
running() {
service_running() {
if [ -f "/etc/init/$1.conf" ]; then
# Use upstart
case "$(status $1 2>/dev/null)" in
@ -51,26 +42,36 @@ running() {
fi
}
output=
for i in $SERVICES; do
service=${i%|*}
nick=${i#*|}
case "$service" in
eucalyptus-nc)
if running $service; then
# This is a node controller, determine VM usage
. /etc/eucalyptus/eucalyptus.conf
count=$(pgrep -c -f /usr/bin/kvm || true)
output="$output,NC:$count"
fi
;;
*)
running $service && output="$output,$nick"
;;
esac
done
[ -n "$output" ] || exit 0
color w c; printf "%s" ${output#,}; color --
__services() {
local services=
# Users can define a list of services to monitor in $CONFIG_DIR/status
if [ -z "$services" ]; then
if [ -f "/etc/eucalyptus/eucalyptus.conf" ]; then
# If the user has not defined any services, but this system is a
# UEC system, default to the list of Ubuntu Enterprise Cloud Services
services="eucalyptus-cloud|CLC eucalyptus-walrus|WC eucalyptus-cc|CC eucalyptus-sc|SC eucalyptus-nc|NC"
fi
fi
output=
for i in $services; do
service=${i%|*}
nick=${i#*|}
case "$service" in
eucalyptus-nc)
if service_running $service; then
# This is a node controller, determine VM usage
. /etc/eucalyptus/eucalyptus.conf
count=$(pgrep -c -f /usr/bin/kvm || true)
output="$output,NC:$count"
fi
;;
*)
service_running $service && output="$output,$nick"
;;
esac
done
[ -n "$output" ] || return
color w c; printf "%s" ${output#,}; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# mem_swap: show the current swap available and used
# Copyright (C) 2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2010 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,17 +19,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__swap_detail() {
cat /proc/meminfo
exit 0
fi
}
swap_info() {
__swap() {
local stotal="" sfree="" name val unit mem f;
while read name val unit; do
while read name val unit; do
if [ "$name" = "SwapTotal:" ]; then
stotal="$val"
elif [ "$name" = "SwapFree:" ]; then
@ -37,9 +35,7 @@ swap_info() {
fi
[ -n "$stotal" -a -n "$sfree" ] && break;
done < /proc/meminfo
[ "${stotal:-0}" = "0" ] && return 0
mem=${stotal}
f=$(((100*($stotal-$sfree))/$stotal))
[ "$f" = "0" ] && return 0
@ -55,12 +51,8 @@ swap_info() {
mem="$mem"
unit="KB"
fi
color b G W; printf "s%s" "$mem"; color -; color G W; printf "%s," "$unit"; color -;
color b G W; printf "%s" "$f"; color -; color G W; printf "%%"; color --
return
}
swap_info "$@"
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# time - print the time in HH:MM:SS format
# Copyright (C) 2008 Canonical Ltd.
# time: print the time in HH:MM:SS format
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,17 +19,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
case "$1" in
--detail)
date
;;
--short)
date +%H:%M:%S
;;
*)
printf "\0050c:\005s"
;;
esac
__time_detail() {
date
}
__time() {
printf "\0050c:\005s"
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# time_utc - print UTC time in HH:MM
# Copyright (C) 2010 Canonical Ltd.
# time_utc: print UTC time in HH:MM
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2010 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,17 +19,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
color 2>/dev/null || color() { true; }
case "$1" in
--detail)
date -u
;;
*)
d=$(date -u +%H:%M)
color invert; printf "%s UTC" "$d"; color --
;;
esac
__time_utc_detail() {
date -u
}
__time_utc() {
d=$(date -u +%H:%M)
color invert; printf "%s UTC" "$d"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,31 +1,37 @@
#!/bin/sh -e
#
# trash: show icon (and optionally count) if entries in trash.
# Copyright (C) 2011 Canonical Ltd.
# trash: show icon (and optionally count) if entries in trash.
#
# Authors: James Hunt <james.hunt@canonical.com>
# 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
# the Free Software Foundation, version 3 of the License.
# Copyright (C) 2011 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Authors: James Hunt <james.hunt@canonical.com>
# Dustin Kirkland <kirkland@ubuntu.com>
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
[ "$UTF8" = "1" ] && ICON="♸" || ICON="T"
TRASH_DIR="$HOME/.local/share/Trash/files"
dir="$HOME/.local/share/Trash/files"
[ ! -d $dir ] && exit 0
__trash_detail() {
find "$TRASH_DIR"
}
count=$(ls $dir|wc -l)
[ "$count" -eq 0 ] && exit 0
echo -n "$ICON[$count] "
__trash() {
local count
[ -d "$TRASH_DIR" ] || return
count=$(ls $dir|wc -l)
[ "$count" = "0" ] && return
printf "%s[%s]" "$ICON_TRASH" "$count"
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# updates_available: calculate and cache the number of updates available
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,24 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" -o "$1" = "--short" ]; then
if command -v apt-get >/dev/null; then
detail=`apt-get -s -o Debug::NoLocking=true upgrade`
if [ "$1" = "--detail" ]; then
printf "$detail"
else
short=`printf "%s" "$detail" | grep -c ^Inst`
printf "$short"
fi
fi
exit 0
fi
print_updates() {
___print_updates() {
u=$1
s=$2
if [ -n "$u" ]; then
@ -50,7 +35,7 @@ print_updates() {
fi
}
update_cache() {
___update_cache() {
mycache=$1
# Now we actually have to do hard computational work to calculate updates.
# Let's try to be "nice" about it:
@ -78,9 +63,9 @@ update_cache() {
fi
}
# Checks if we need to update the cache.
# TODO: add more distro
update_needed() {
___update_needed() {
# Checks if we need to update the cache.
# TODO: add more distro
mycache=$1
# The cache doesn't exist: create it
[ ! -e "$mycache" ] && return 0
@ -98,14 +83,25 @@ update_needed() {
return 1
}
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$DATA"
mycache="$DIR/$PKG.updates-available"
__updates_available_detail() {
if command -v apt-get >/dev/null; then
detail=`apt-get -s -o Debug::NoLocking=true upgrade`
if [ "$1" = "--detail" ]; then
printf "$detail"
else
short=`printf "%s" "$detail" | grep -c ^Inst`
printf "$short"
fi
fi
}
# If mycache is present, use it
[ -r $mycache ] && print_updates `sed -n '/[^0-9]/s/ .*$//p' $mycache`
# If we really need to do so (mycache doesn't exist, or the package database has changed),
# background an update now
update_needed "$mycache" && update_cache "$mycache"
__updates_available() {
local mycache="$CACHE_DIR/updates-available"
# If mycache is present, use it
[ -r $mycache ] && ___print_updates `sed -n '/[^0-9]/s/ .*$//p' $mycache`
# If we really need to do so (mycache doesn't exist, or the package database has changed),
# background an update now
___update_needed "$mycache" && ___update_cache "$mycache"
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,46 +1,44 @@
#!/bin/sh -e
#
# uptime: condensed uptime of the machine
# Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2009 Canonical Ltd.
# uptime: condensed uptime of the machine
#
# Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 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
# the Free Software Foundation, version 3 of the License.
# Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@ubuntu.com>
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 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
# the Free Software Foundation, version 3 of the License.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__uptime_detail() {
uptime
exit 0
fi
}
read u idle < /proc/uptime
u=${u%.*}
color w b
if [ "$u" -gt 86400 ]; then
str="$(($u / 86400))d$((($u % 86400) / 3600))h"
elif [ "$u" -gt 3600 ]; then
str="$(($u / 3600))h$((($u % 3600) / 60))m"
elif [ "$u" -gt 60 ]; then
str="$(($u / 60))m"
else
str="${u}s"
fi
printf "%s" "${str}"
color --
__uptime() {
local u idle str
read u idle < /proc/uptime
u=${u%.*}
if [ "$u" -gt 86400 ]; then
str="$(($u / 86400))d$((($u % 86400) / 3600))h"
elif [ "$u" -gt 3600 ]; then
str="$(($u / 3600))h$((($u % 3600) / 60))m"
elif [ "$u" -gt 60 ]; then
str="$(($u / 60))m"
else
str="${u}s"
fi
color w b; printf "%s" "${str}"; color --
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,39 +1,38 @@
#!/bin/sh -e
#
# users: print the number of remote users on the machine
# Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2009 Canonical Ltd.
# users: print the number of remote users on the machine
#
# Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 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
# the Free Software Foundation, version 3 of the License.
# Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@ubuntu.com>
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 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
# the Free Software Foundation, version 3 of the License.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__users_detail() {
ps -ef | grep "sshd;.*@" | grep -v grep
exit 0
fi
}
# Note: we'd like to use pgrep -c, however, this isn't available in
# busybox and some distro's pgrep (and it doesn't exit non-zero).
count=`pgrep -f "sshd:.*@" | wc -l` || exit 0
if [ $count -gt 0 ]; then
color b w r; printf "%d" "$count"; color -; color w r; printf "#"; color --
fi
__users() {
local count
# Note: we'd like to use pgrep -c, however, this isn't available in
# busybox and some distro's pgrep (and it doesn't exit non-zero).
count=`pgrep -f "sshd:.*@" | wc -l` || return
if [ $count -gt 0 ]; then
color b w r; printf "%d" "$count"; color -; color w r; printf "#"; color --
fi
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# whoami - report current logged in user
# Copyright (C) 2008 Canonical Ltd.
# whoami: report current logged in user
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,13 +19,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
__whoami_detail() {
getent -- passwd "$USER"
exit 0
fi
}
color bold2; printf "%s@" "$(whoami)"; color -
__whoami() {
color bold2; printf "%s@" "$(whoami)"; color -
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e
#
# wifi_quality: display wifi signal quality
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
# Copyright (C) 2008 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
# 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
@ -17,34 +19,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu"
color 2>/dev/null || color() { true; }
[ "$UTF8" = "1" ] && ICON="⚚" || ICON=
if [ "$1" = "--detail" ]; then
__wifi_quality_detail() {
/sbin/iwconfig 2>/dev/null
exit 0
fi
}
# iwconfig is expected to output lines like:
# Bit Rate=54 Mb/s Tx-Power=15 dBm
# Link Quality=60/70 Signal level=-50 dBm
# the awk below tokenizes the output and prints shell evalable results
out=`iwconfig $MONITORED_NETWORK 2>/dev/null |
awk '$0 ~ /[ ]*Link Quality./ {
__wifi_quality() {
local out bitrate quality
# iwconfig is expected to output lines like:
# Bit Rate=54 Mb/s Tx-Power=15 dBm
# Link Quality=60/70 Signal level=-50 dBm
# the awk below tokenizes the output and prints shell evalable results
out=`iwconfig $MONITORED_NETWORK 2>/dev/null |
awk '$0 ~ /[ ]*Link Quality./ {
sub(/.*=/,"",$2); split($2,a,"/");
printf "quality=%.0f\n", 100*a[1]/a[2] };
$0 ~ /[ ]*Bit Rate/ { sub(/.*=/,"",$2); printf("bitrate=%s\n", $2); }
'`
eval "$out"
[ -z "$bitrate" ] && bitrate="0"
if [ -z "$quality" ] || [ "$quality" = "0" ]; then
quality="0"
fi
[ "$quality" = "0" ] && exit 0
printf "${ICON}"; color b C k; printf "%s" "$bitrate"; color -; color C k; printf "%s," "Mbps"; color -; color b C k; printf "%s" "$quality"; color -; color C k; printf "%%"; color --
eval "$out"
[ -z "$bitrate" ] && bitrate="0"
if [ -z "$quality" ] || [ "$quality" = "0" ]; then
quality="0"
fi
[ "$quality" = "0" ] && return
printf "${ICON_WIFI}"; color b C k; printf "%s" "$bitrate"; color -; color C k; printf "%s," "Mbps"; color -; color b C k; printf "%s" "$quality"; color -; color C k; printf "%%"; color --
}
# vi: syntax=sh ts=4 noexpandtab