* 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: * usr/share/byobu/profiles/tmux:
- getting tmux keybindings much closer! - 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 -- Dustin Kirkland <kirkland@ubuntu.com> Thu, 16 Jun 2011 16:16:29 -0500

View file

@ -20,6 +20,7 @@
PKG="byobu" PKG="byobu"
DATA="$HOME/.$PKG" DATA="$HOME/.$PKG"
[ -z "$BYOBU_PREFIX" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX [ -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 if ! . "${BYOBU_PREFIX}/lib/${PKG}/.shutil"; then
echo "failed to source ${BYOBU_PREFIX}/lib/${PKG}/.shutil" 2>&1 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=#) # uncommented_lines(char=#)
# does the standard input have lines that do not start with 'char'? # does the standard input have lines that do not start with 'char'?
uncommented_lines() { uncommented_lines() {
@ -81,4 +83,8 @@ readfile() {
return 0 return 0
} }
metadata_available() {
wget -q -O- --timeout=1 http://169.254.169.254
}
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

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

View file

@ -1,10 +1,12 @@
#!/bin/sh -e #!/bin/sh -e
# #
# battery: print the state of the battery # battery: print the state of the battery
#
# Copyright (C) 2009 Raphaël Pinson. # Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2011 Dustin Kirkland
# #
# Authors: Raphaël Pinson <raphink@ubuntu.com> # Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@canonical.com> # Dustin Kirkland <kirkland@ubuntu.com>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -18,22 +20,18 @@
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu" __battery_detail() {
color 2>/dev/null || color() { true; } local bat
if [ "$1" = "--detail" ]; then
for bat in /proc/acpi/battery/*; do for bat in /proc/acpi/battery/*; do
cat "$bat/info" cat "$bat/info"
cat "$bat/state" cat "$bat/state"
done done
exit 0 }
fi
battery_info() { __battery() {
local bat line present sign state percent full rem color bcolor local bat line present sign state percent full rem color bcolor
for bat in $BATTERY /proc/acpi/battery/*; do for bat in $BATTERY /proc/acpi/battery/*; do
[ -f "$bat/info" ] || continue [ -f "$bat/info" ] || continue
present=""; full=""; rem=""; state="" present=""; full=""; rem=""; state=""
while read line; do while read line; do
set -- ${line} set -- ${line}
@ -46,7 +44,6 @@ battery_info() {
esac esac
[ -n "$present" -a -n "$full" ] && break [ -n "$present" -a -n "$full" ] && break
done < "${bat}/info" done < "${bat}/info"
while read line; do while read line; do
set -- ${line} set -- ${line}
case "$line" in case "$line" in
@ -55,9 +52,7 @@ battery_info() {
esac esac
[ -n "$rem" -a -n "$state" ] && break [ -n "$rem" -a -n "$state" ] && break
done < "$bat/state" done < "$bat/state"
percent=$(((100*$rem)/$full)) percent=$(((100*$rem)/$full))
if [ "$percent" -lt 33 ]; then if [ "$percent" -lt 33 ]; then
color="R k" color="R k"
bcolor="b R k" bcolor="b R k"
@ -69,7 +64,6 @@ battery_info() {
bcolor="b G k" bcolor="b G k"
fi fi
percent="$percent%" percent="$percent%"
case $state in case $state in
charging) sign="+" ;; charging) sign="+" ;;
discharging) sign="-" ;; discharging) sign="-" ;;
@ -81,6 +75,4 @@ battery_info() {
done done
} }
battery_info "$@"
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# cpu_count: count cpu's on a systems # 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 # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # 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 grep -i "^model name" /proc/cpuinfo
exit 0 }
fi
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo) __cpu_count() {
[ "$count" = "1" ] || printf "%sx" "$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 # vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# cpu_freq: calculate current cpu frequency # 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 # 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 # it under the terms of the GNU General Public License as published by
@ -17,19 +19,17 @@
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu" __cpu_freq_detail() {
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
cat /proc/cpuinfo cat /proc/cpuinfo
exit 0 }
fi
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then __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 read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
fpdiv $hz "1000000" 1 # 1Ghz fpdiv $hz "1000000" 1 # 1Ghz
freq="$_RET" freq="$_RET"
else else
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then 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 }') freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%.1f", $2 / 1000 }')
else else
@ -38,7 +38,8 @@ else
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }') freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
freq=$(echo "$freq" "$count" | awk '{printf "%.1f\n", $1/$2/1000}') freq=$(echo "$freq" "$count" | awk '{printf "%.1f\n", $1/$2/1000}')
fi 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 # vi: syntax=sh ts=4 noexpandtab

View file

@ -1,10 +1,12 @@
#!/bin/sh -e #!/bin/sh -e
# #
# cpu_temp: cpu temperature # cpu_temp: cpu temperature
# 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 # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License. # the Free Software Foundation, version 3 of the License.
@ -16,24 +18,21 @@
# #
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#
PKG="byobu" CPU_TEMP_DIR="/proc/acpi/thermal_zone"
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" __cpu_temp_detail() {
if [ "$1" = "--detail" ] && [ -d "$DIR" ]; then local i
for i in "$DIR"/*; do for i in "$CPU_TEMP_DIR"/*; do
[ -r "$i" ] || continue [ -r "$i" ] || continue
echo "$i:" echo "$i:"
cat "$i"/* cat "$i"/*
done done
exit 0 }
fi
for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal $DIR/*/temperature; do __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 case "$i" in
*temp*_input) *temp*_input)
[ -s "$i" ] && read t < "$i" && t=$(($t/1000)) [ -s "$i" ] && read t < "$i" && t=$(($t/1000))
@ -48,9 +47,10 @@ for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/ther
t=$(($t*9/5 + 32)) t=$(($t*9/5 + 32))
unit="$ICON_F" unit="$ICON_F"
fi fi
color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s%s" "$ICON" "$unit"; color -- color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s" "$unit"; color --
break break
fi fi
done done
}
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

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

View file

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

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# disk_io: calculate the disk io rate # 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 # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu" __disk_io_detail() {
DATA="$HOME/.$PKG" if command -v iostat >/dev/null; then
color 2>/dev/null || color() { true; } iostat -d -m -h
else
echo "Please install iostat if you want detailed information on your disk throughput"
fi
}
getdisk() { getdisk() {
local t="" local t=""
if [ -L "${1}" ]; then if [ -L "${1}" ]; then
@ -32,42 +40,30 @@ getdisk() {
[ -h "/sys/block/$t" ] && _RET="$t" || rtrim "$t" "0-9" [ -h "/sys/block/$t" ] && _RET="$t" || rtrim "$t" "0-9"
} }
[ "$UTF8" = "1" ] && ICON_RD="◀" || ICON_RD="<" __disk_io() {
[ "$UTF8" = "1" ] && ICON_WR="▶" || ICON_WR=">" local part= i=
# Default to disk providing /, but let users override with MONITORED_DISK
# Default to disk providing /, but let users override with MONITORED_DISK [ -z "$MONITORED_DISK" ] && mount_point="/" || mount_point="$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 $CONFIG_DIR/status
# By default, we won't bug the user with the display of network traffic [ -n "$DISK_IO_THRESHOLD" ] || DISK_IO_THRESHOLD=50
# below DISK_IO_THRESHOLD in kB/s; override in $DATA/status case "$mount_point" in
[ -n "$DISK_IO_THRESHOLD" ] || DISK_IO_THRESHOLD=50 /dev/*) part="${mount_point}";;
*) part=$(awk '$2 == mp { print $1 ; exit(0); }' "mp=$mount_point" /etc/mtab);;
if [ "$1" = "--detail" ]; then esac
if command -v iostat >/dev/null; then getdisk "$part"
iostat -d -m -h local disk=${_RET}
else local t2=`date +%s` t1=
echo "Please install iostat if you want detailed information on your disk throughput" for i in "read" "write"; do
fi local cache="$CACHE_DIR/disk.$i"
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 t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
unit="kB/s" local unit="kB/s"
local rate= x1= x2= symbol= unit=
if [ $t2 -le $t1 ]; then if [ $t2 -le $t1 ]; then
rate=0 rate=0
else else
[ -r "$cache" ] && read x1 < "$cache" || x1=0 [ -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" read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 other < "/sys/block/$disk/stat"
if [ "$i" = "read" ]; then if [ "$i" = "read" ]; then
symbol="$ICON_RD" symbol="$ICON_RD"
@ -79,8 +75,8 @@ for i in "read" "write"; do
echo "$x2" > "$cache" echo "$x2" > "$cache"
rate=$((($x2 - $x1) / ($t2 - $t1) * 512 / 1024)) rate=$((($x2 - $x1) / ($t2 - $t1) * 512 / 1024))
if [ $rate -lt $DISK_IO_THRESHOLD ]; then if [ $rate -lt $DISK_IO_THRESHOLD ]; then
# Below threshold, exit immediately! # Below threshold, don't print
exit 0 continue
elif [ "$rate" -lt 0 ]; then elif [ "$rate" -lt 0 ]; then
rate=0 rate=0
elif [ "$rate" -gt 1048576 ]; then elif [ "$rate" -gt 1048576 ]; then
@ -97,6 +93,7 @@ for i in "read" "write"; do
fi fi
[ "$rate" != "0" ] || continue [ "$rate" != "0" ] || continue
color b M W; printf "%s%s" "$symbol" "$rate"; color -; color M W; printf "%s" "$unit"; color -- color b M W; printf "%s%s" "$symbol" "$rate"; color -; color M W; printf "%s" "$unit"; color --
done done
}
# vi: syntax=sh ts=4 noexpandtab # 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 # 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 # 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 # it under the terms of the GNU General Public License as published by
@ -17,29 +19,29 @@
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
DETAIL=0 # Data Transfer Cost Basis
PKG="byobu" # Incoming $0.10/GB
DATA="$HOME/.$PKG" # Outgoing $0.17/GB
[ -z "$BYOBU_PREFIX" ] && BYOBU_PREFIX="/usr" # (This gets more complex if you use >1TB/mo)
color 2>/dev/null || color() { true; } RX_RATE="0.10"
TX_RATE="0.15"
for arg in $@; do __ec2_cost_detail() {
case "$arg" in
-d|--detail)
DETAIL=1 DETAIL=1
;; __ec2_cost
esac }
done
# Try to use metadata service __ec2_cost() {
if host 169.254.169.254 >/dev/null 2>&1; then 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) zone=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone)
. "$BYOBU_PREFIX/share/$PKG/ec2/rates.${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") type=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-type | sed -e "s/\./_/g")
eval RATE="\$$type" eval rate="\$$type"
file_to_stat="$DATA/.ec2_instance_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 [ -f "$file_to_stat" ] || wget -q -O "$file_to_stat" http://169.254.169.254/latest/meta-data/instance-type
else else
. "$BYOBU_PREFIX/share/$PKG/ec2/rates."* . "$BYOBU_PREFIX/share/$PKG/ec2/rates."*
# Count CPUs, Memory, Architecture, hours # Count CPUs, Memory, Architecture, hours
cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1 cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1
@ -48,48 +50,36 @@ else
file_to_stat="/etc/hostname" file_to_stat="/etc/hostname"
# Guess this system's going rate, based on mem available (m* types) # Guess this system's going rate, based on mem available (m* types)
if [ $mem -lt 700000 ]; then if [ $mem -lt 700000 ]; then
RATE=$t1_micro rate=$t1_micro
elif [ $mem -gt 64000000 ]; then elif [ $mem -gt 64000000 ]; then
RATE=$m2_4xlarge rate=$m2_4xlarge
elif [ $mem -gt 32000000 ]; then elif [ $mem -gt 32000000 ]; then
RATE=$m2_2xlarge rate=$m2_2xlarge
elif [ $mem -gt 16000000 ]; then elif [ $mem -gt 16000000 ]; then
RATE=$m2_xlarge rate=$m2_xlarge
elif [ $mem -gt 14000000 ]; then elif [ $mem -gt 14000000 ]; then
RATE=$m1_xlarge rate=$m1_xlarge
elif [ $mem -gt 7000000 ]; then elif [ $mem -gt 7000000 ]; then
RATE=$m1_large rate=$m1_large
else else
# Otherwise, scale based on number of cpu's (c* types) # Otherwise, scale based on number of cpu's (c* types)
RATE=$(echo "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}') rate=$(echo "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}')
fi fi
fi fi
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1)) hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
# Auto detect network interface
# Data Transfer Cost Basis interface=`tail -n1 /proc/net/route | awk '{print $1}'`
# Incoming $0.10/GB ifconfig_out=`LC_ALL=C /sbin/ifconfig "$interface"`
# Outgoing $0.17/GB # Calculate bandwidth cost
# (This gets more complex if you use >1TB/mo) tx_gb=${ifconfig_out#*RX bytes:}
RX_RATE="0.10" tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
TX_RATE="0.15" rx_gb=${ifconfig_out#*TX bytes:}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
# Auto detect network interface network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
IF=`tail -n1 /proc/net/route | awk '{print $1}'` # Calculate uptime cost
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$rate" * $hours}"`
ifconfig_out=`LC_ALL=C /sbin/ifconfig "$IF"` total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
if [ "$DETAIL" = "1" ]; then
# 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 "================================================"
echo "Estimated cost in Amazon's EC2 since last reboot" echo "Estimated cost in Amazon's EC2 since last reboot"
echo "================================================" echo "================================================"
@ -97,14 +87,14 @@ if [ "$DETAIL" = "1" ]; then
echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB" echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB"
echo " Network cost: \$$network_cost" echo " Network cost: \$$network_cost"
echo "------------------------------------------------" echo "------------------------------------------------"
echo " Uptime: $hours hr @ \$$RATE/hr" echo " Uptime: $hours hr @ \$$rate/hr"
echo " Uptime cost: \$$uptime_cost" echo " Uptime cost: \$$uptime_cost"
echo "------------------------------------------------" echo "------------------------------------------------"
echo "Total cost: ~\$$total_cost" echo "Total cost: ~\$$total_cost"
echo "================================================" echo "================================================"
exit 0 return
fi fi
color K G; printf "A\$"; color -; color b K G; printf "%s" "$total_cost"; color --
color K G; printf "A\$"; color -; color b K G; printf "%s" "$total_cost"; color -- }
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

@ -1,10 +1,12 @@
#!/bin/sh -e #!/bin/sh -e
# #
# fan_speed: speed of the cpu or case fan # fan_speed: speed of the cpu or case fan
# 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 # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License. # the Free Software Foundation, version 3 of the License.
@ -16,20 +18,15 @@
# #
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#
PKG="byobu" __fan_speed_detail() {
color 2>/dev/null || color() { true; } # Nothing interesting to say here about fan speed
return
}
DIR="/sys/class/hwmon" __fan_speed() {
# 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() {
local i="" speed=0 local i="" speed=0
# Let's check a few different probes for fan speed
# This seems to cover most of them: # This seems to cover most of them:
for i in /sys/class/hwmon/*/*/fan1_input; do for i in /sys/class/hwmon/*/*/fan1_input; do
[ -f "$i" ] || continue [ -f "$i" ] || continue
@ -58,7 +55,4 @@ fan_speed_info() {
fi fi
} }
fan_speed_info "$@"
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

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

View file

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

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# logo: determine which logo to use # 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 # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu" get_distro() {
DATA="$HOME/.$PKG" _RET=
color 2>/dev/null || color() { true; } 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" MARKUP="false"
exit 0 __logo
else }
MARKUP="true"
fi
print_logo() { __logo() {
distro=`echo "$1" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' ` 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 case "$distro" in
*ubuntu*) *ubuntu*)
if $MARKUP; then if $MARKUP; then
@ -97,30 +118,4 @@ print_logo() {
esac 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 # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# mem: grab the current memory and usage # mem_available: grab the current memory 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 # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu" __mem_available_detail() {
DATA="$HOME/.$PKG"
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
free free
exit 0 }
fi
mem_available_info() { __mem_available() {
local mem_used comma whitespace unit mem name local mem_used comma whitespace unit mem name
. "$DATA/status" . "$CONFIG_DIR/status"
[ "$mem_used" = "1" ] && comma="," || whitespace=" " [ "$mem_used" = "1" ] && comma="," || whitespace=" "
read name mem unit < /proc/meminfo read name mem unit < /proc/meminfo
if [ $mem -ge 1048576 ]; then if [ $mem -ge 1048576 ]; then
fpdiv "$mem" 1048567 1 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" 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 # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

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

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# network: calculate the network up/down rates # 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 # 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 # it under the terms of the GNU General Public License as published by
@ -17,39 +19,36 @@
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
PKG="byobu" get_interface() {
DATA="$HOME/.$PKG" _RET=
color 2>/dev/null || color() { true; } # Allow interface overrides in $CONFIG_DIR/status
[ "$UTF8" = "1" ] && ICON_UP="▲" || ICON_UP="^" if [ -n "$MONITORED_NETWORK" ]; then
[ "$UTF8" = "1" ] && ICON_DN="▼" || ICON_DN="v" _RET="$MONITORED_NETWORK"
else
# Allow interface overrides in $DATA/status
if [ -n "$MONITORED_NETWORK" ]; then
interface="$MONITORED_NETWORK"
else
# get the last interface listed in /proc/net/route # get the last interface listed in /proc/net/route
while read cn other; do interface=$cn; done < /proc/net/route while read cn other; do _RET=$cn; done < /proc/net/route
fi fi
}
# By default, we won't bug the user with the display of network traffic __network_detail() {
# below NETWORK_THRESHOLD in kbps; override in $DATA/status get_interface; local interface="$_RET"
[ -n "$NETWORK_THRESHOLD" ] || NETWORK_THRESHOLD=20
if [ "$1" = "--detail" ]; then
LC_ALL=C /sbin/ifconfig "$interface" | sed 's/\s*$//' 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" __network() {
t2=`date +%s` get_interface; local interface="$_RET"
OIFS=$IFS # By default, we won't bug the user with the display of network traffic
for i in up down; do # 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" unit="kbps"
case $i in case $i in
up) symbol="$ICON_UP" ;; up) symbol="$ICON_UP" ;;
down) symbol="$ICON_DN" ;; down) symbol="$ICON_DN" ;;
esac esac
cache="$DIR/$PKG.network_$i" cache="$CACHE_DIR/network.$i"
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
if [ $t2 -le $t1 ]; then if [ $t2 -le $t1 ]; then
rate=0 rate=0
@ -99,6 +98,7 @@ for i in up down; do
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color -- color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
fi fi
fi fi
done done
}
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

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

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# raid: notify raid events, failures and syncing # 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 # 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 # it under the terms of the GNU General Public License as published by
@ -17,20 +19,13 @@
# You should have received a copy of the GNU General Public 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/>. # 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" __raid() {
color 2>/dev/null || color() { true; } while read line; do
local pct="%" p msg
case $1 in
--detail)
cat /proc/mdstat
exit 0
;;
esac
pct="%"
while read line; do
# Errors in your raid # Errors in your raid
case "$line" in case "$line" in
*\ blocks\ *\[*_*\]$) *\ blocks\ *\[*_*\]$)
@ -40,10 +35,8 @@ while read line; do
[ -z "$msg" ] && msg="RAID" [ -z "$msg" ] && msg="RAID"
msg="$msg,$p";; msg="$msg,$p";;
esac esac
done < /proc/mdstat done < /proc/mdstat
[ -z "$msg" ] || color B w r; printf "%s" "$msg"; color --
if [ -n "$msg" ]; then }
color B w r; printf "%s" "$msg"; color --
fi
# vi: syntax=sh ts=4 noexpandtab # 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 # rcs_cost: approximate Rackspace Cloud Server cost (USD) of the current instance
# instance
# #
# Copyright (C) 2009-2010 Jon Bernard # 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 # Derived from byobu's ec2_cost written by Dustin Kirkland, see
# Byobu's project page: https://launchpad.net/byobu for more information # Byobu's project page: https://launchpad.net/byobu for more information
@ -22,65 +23,59 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
DETAIL=0 __rcs_cost_detail() {
PKG="byobu"
color 2>/dev/null || color() { true; }
for arg in $@; do
case "$arg" in
-d|--detail)
DETAIL=1 DETAIL=1
;; __rcs_cost
esac }
done
# Approximate Instance Cost Basis __rcs_cost() {
# Memory US # Approximate Instance Cost Basis
# 256MB $0.015/h # Memory US
# 512MB $0.030/h # 256MB $0.015/h
# 1024MB $0.060/h # 512MB $0.030/h
# 2048MB $0.120/h # 1024MB $0.060/h
# 4096MB $0.240/h # 2048MB $0.120/h
# 8192MB $0.480/h # 4096MB $0.240/h
# 15872MB $0.960/h # 8192MB $0.480/h
# 15872MB $0.960/h
# Instance memory # Instance memory
memory=`grep "^MemTotal:" /proc/meminfo | awk '{print $2}'` memory=`grep "^MemTotal:" /proc/meminfo | awk '{print $2}'`
# Round memory down to the nearest multiple of 64MB # Round memory down to the nearest multiple of 64MB
memory=$((${memory} - (${memory} % (64 * 1024)))) memory=$((${memory} - (${memory} % (64 * 1024))))
# Apply the going rate # Apply the going rate
INCREMENTS="256 512 1024 2048 4096 8192 16384 32768 65536" INCREMENTS="256 512 1024 2048 4096 8192 16384 32768 65536"
for X in ${INCREMENTS}; do for X in ${INCREMENTS}; do
test "$((${X} * 1024 + 65536))" -ge ${memory} && break test "$((${X} * 1024 + 65536))" -ge ${memory} && break
done done
MEMORY_RATE=`echo "$X" | awk '{printf "%f", $1 / 256 * 15 / 1000}'` MEMORY_RATE=`echo "$X" | awk '{printf "%f", $1 / 256 * 15 / 1000}'`
# Data Transfer Cost Basis # Data Transfer Cost Basis
# Incoming $0.08/GB # Incoming $0.08/GB
# Outgoing $0.22/GB # Outgoing $0.22/GB
RX_RATE="0.08" RX_RATE="0.08"
TX_RATE="0.22" TX_RATE="0.22"
# Auto detect network interface # Auto detect network interface
IF=`tail -n1 /proc/net/route | awk '{print $1}'` 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 # Calculate bandwidth cost
tx_gb=${ifconfig_out#*RX bytes:} tx_gb=${ifconfig_out#*RX bytes:}
tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') tx_gb=$(echo ${tx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }')
rx_gb=${ifconfig_out#*TX bytes:} rx_gb=${ifconfig_out#*TX bytes:}
rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') 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}'` 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 # Calculate uptime cost
hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1)) hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1))
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$MEMORY_RATE" * $hours}"` uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$MEMORY_RATE" * $hours}"`
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'` total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
if [ "$DETAIL" = "1" ]; then if [ "$DETAIL" = "1" ]; then
echo "==========================================================" echo "=========================================================="
echo "Estimated cost in Rackspace Cloud Server since last reboot" echo "Estimated cost in Rackspace Cloud Server since last reboot"
echo "==========================================================" echo "=========================================================="
@ -93,9 +88,10 @@ if [ "$DETAIL" = "1" ]; then
echo "----------------------------------------------------------" echo "----------------------------------------------------------"
echo "Total cost: ~\$$total_cost" echo "Total cost: ~\$$total_cost"
echo "==========================================================" echo "=========================================================="
exit 0 return
fi 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 # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

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

View file

@ -3,8 +3,9 @@
# services: show what services are running on this server (configurable) # services: show what services are running on this server (configurable)
# #
# Copyright (C) 2009 Canonical Ltd. # 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 # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
__services_detail() {
return
}
PKG="byobu" service_running() {
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() {
if [ -f "/etc/init/$1.conf" ]; then if [ -f "/etc/init/$1.conf" ]; then
# Use upstart # Use upstart
case "$(status $1 2>/dev/null)" in case "$(status $1 2>/dev/null)" in
@ -51,13 +42,23 @@ running() {
fi fi
} }
output= __services() {
for i in $SERVICES; do 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%|*} service=${i%|*}
nick=${i#*|} nick=${i#*|}
case "$service" in case "$service" in
eucalyptus-nc) eucalyptus-nc)
if running $service; then if service_running $service; then
# This is a node controller, determine VM usage # This is a node controller, determine VM usage
. /etc/eucalyptus/eucalyptus.conf . /etc/eucalyptus/eucalyptus.conf
count=$(pgrep -c -f /usr/bin/kvm || true) count=$(pgrep -c -f /usr/bin/kvm || true)
@ -65,12 +66,12 @@ for i in $SERVICES; do
fi fi
;; ;;
*) *)
running $service && output="$output,$nick" service_running $service && output="$output,$nick"
;; ;;
esac esac
done done
[ -n "$output" ] || exit 0 [ -n "$output" ] || return
color w c; printf "%s" ${output#,}; color --
color w c; printf "%s" ${output#,}; color -- }
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

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

View file

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

View file

@ -1,10 +1,13 @@
#!/bin/sh -e #!/bin/sh -e
# #
# trash: show icon (and optionally count) if entries in trash. # trash: show icon (and optionally count) if entries in trash.
#
# Copyright (C) 2011 Canonical Ltd. # Copyright (C) 2011 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
# #
# Authors: James Hunt <james.hunt@canonical.com> # Authors: James Hunt <james.hunt@canonical.com>
# Dustin Kirkland <kirkland@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License. # the Free Software Foundation, version 3 of the License.
@ -16,16 +19,19 @@
# #
# You should have received a copy of the GNU General Public 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/>. # 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" __trash_detail() {
[ ! -d $dir ] && exit 0 find "$TRASH_DIR"
}
count=$(ls $dir|wc -l) __trash() {
[ "$count" -eq 0 ] && exit 0 local count
[ -d "$TRASH_DIR" ] || return
echo -n "$ICON[$count] " count=$(ls $dir|wc -l)
[ "$count" = "0" ] && return
printf "%s[%s]" "$ICON_TRASH" "$count"
}
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

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

View file

@ -1,11 +1,13 @@
#!/bin/sh -e #!/bin/sh -e
# #
# uptime: condensed uptime of the machine # uptime: condensed uptime of the machine
#
# Copyright (C) 2009 Raphaël Pinson. # Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2009 Canonical Ltd. # Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
# #
# Authors: Raphaël Pinson <raphink@ubuntu.com> # Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@canonical.com> # Dustin Kirkland <kirkland@ubuntu.com>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -18,29 +20,25 @@
# #
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#
PKG="byobu" __uptime_detail() {
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
uptime uptime
exit 0 }
fi
read u idle < /proc/uptime __uptime() {
u=${u%.*} local u idle str
color w b read u idle < /proc/uptime
if [ "$u" -gt 86400 ]; then u=${u%.*}
if [ "$u" -gt 86400 ]; then
str="$(($u / 86400))d$((($u % 86400) / 3600))h" str="$(($u / 86400))d$((($u % 86400) / 3600))h"
elif [ "$u" -gt 3600 ]; then elif [ "$u" -gt 3600 ]; then
str="$(($u / 3600))h$((($u % 3600) / 60))m" str="$(($u / 3600))h$((($u % 3600) / 60))m"
elif [ "$u" -gt 60 ]; then elif [ "$u" -gt 60 ]; then
str="$(($u / 60))m" str="$(($u / 60))m"
else else
str="${u}s" str="${u}s"
fi fi
printf "%s" "${str}" color w b; printf "%s" "${str}"; color --
color -- }
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

@ -1,11 +1,13 @@
#!/bin/sh -e #!/bin/sh -e
# #
# users: print the number of remote users on the machine # users: print the number of remote users on the machine
#
# Copyright (C) 2009 Raphaël Pinson. # Copyright (C) 2009 Raphaël Pinson.
# Copyright (C) 2009 Canonical Ltd. # Copyright (C) 2009 Canonical Ltd.
# Copyright (C) 2011 Dustin Kirkland
# #
# Authors: Raphaël Pinson <raphink@ubuntu.com> # Authors: Raphaël Pinson <raphink@ubuntu.com>
# Dustin Kirkland <kirkland@canonical.com> # Dustin Kirkland <kirkland@ubuntu.com>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -18,22 +20,19 @@
# #
# You should have received a copy of the GNU General Public 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#
PKG="byobu" __users_detail() {
color 2>/dev/null || color() { true; }
if [ "$1" = "--detail" ]; then
ps -ef | grep "sshd;.*@" | grep -v grep ps -ef | grep "sshd;.*@" | grep -v grep
exit 0 }
fi
# Note: we'd like to use pgrep -c, however, this isn't available in __users() {
# busybox and some distro's pgrep (and it doesn't exit non-zero). local count
count=`pgrep -f "sshd:.*@" | wc -l` || exit 0 # 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).
if [ $count -gt 0 ]; then 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 -- color b w r; printf "%d" "$count"; color -; color w r; printf "#"; color --
fi fi
}
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab

View file

@ -1,9 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
# #
# whoami - report current logged in user # whoami: report current logged in user
# 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 # 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 # 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
color 2>/dev/null || color() { true; } __whoami_detail() {
if [ "$1" = "--detail" ]; then
getent -- passwd "$USER" 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 # vi: syntax=sh ts=4 noexpandtab

View file

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