ratox-nuggets

useful ratox related scripts
git clone git://git.2f30.org/ratox-nuggets
Log | Files | Refs | LICENSE

commit 2f339068e35ab015c29f76f6cc46efa9af8eeae4
parent fbda05176627a450e1f2ee7bb16ad5376bab9a2c
Author: Kill Your TV <killyourtv@i2pmail.org>
Date:   Wed,  8 Oct 2014 18:22:26 +0000

basic error checking, online statuses

Diffstat:
Mrat-list | 38++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/rat-list b/rat-list @@ -1,9 +1,35 @@ #!/bin/sh +set -e # List friends -IDS=$(ls |grep '[A-Z0-9]\{64\}') -for ID in $IDS; do - NAME=$(cat $ID/name) - STATUS=$(cat $ID/status) - printf "%s\t%s\t\t%s\n" $(echo $ID | cut -c-12) "$NAME" "$STATUS" -done +online() { + if [ $1 -eq 1 ]; then + echo "Online" + else + echo "Offline" + fi +} + +# Try to determine whether this is run from within +# a ratox directory and complain if not. +check_if_dir(){ + # "grouping hack" to prevent output to stdout on FreeBSD + if ! { lsof id |grep -q '^ratox';} > /dev/null 2>&1 || [ ! -r id ]; then + echo "ERROR: Is this a ratox directory?" >&2 + exit 1 + fi +} + +print_output() { + IDS=$(ls |grep '[A-Z0-9]\{64\}') + for ID in $IDS; do + NAME=$(cat $ID/name | tr -d '\n') + STATUS=$(cat $ID/status | cut -c-30 |tr -d '\n') + ONLINE=$(online $(cat $ID/online)) + printf "%-12s\t%-10s\t%-30s\t\t%-30s\n" $(echo $ID | cut -c-12) "$ONLINE" "$NAME" "$STATUS" + done +} + + +check_if_dir +print_output