diff --git a/spacestatus.sh b/spacestatus.sh index d3e97f2..d4bcb7c 100755 --- a/spacestatus.sh +++ b/spacestatus.sh @@ -5,55 +5,55 @@ #set -eu function write_html { - status=$1 - STATUS_HTML=/srv/www/spacestatus.html - TEMPLATE_HTML='Status /usr/space: %s

%s

' - CLOSED_HTML='Closed darkred Closed' - OPEN_HTML='Open brightgreen Open' - - if [ "$status" -gt 0 ] - then - printf "$TEMPLATE_HTML" $OPEN_HTML > $STATUS_HTML - else - printf "$TEMPLATE_HTML" $CLOSED_HTML > $STATUS_HTML - fi + status=$1 + STATUS_HTML=/srv/www/spacestatus.html + TEMPLATE_HTML='Status /usr/space: %s

%s

' + CLOSED_HTML='Closed darkred Closed' + OPEN_HTML='Open brightgreen Open' + + if [ "$status" -gt 0 ] + then + printf "$TEMPLATE_HTML" $OPEN_HTML > $STATUS_HTML + else + printf "$TEMPLATE_HTML" $CLOSED_HTML > $STATUS_HTML + fi } function write_json { - status=$1 - STATUS_JSON=/srv/www/spacestatus.json - TEMPLATE_JSON=$( cat /usr/local/etc/spacestatus.json ) - CLOSED_JSON='false' - OPEN_JSON='true' + status=$1 + STATUS_JSON=/srv/www/spacestatus.json + TEMPLATE_JSON=$( cat /usr/local/etc/spacestatus.json ) + CLOSED_JSON='false' + OPEN_JSON='true' # Previous status Open & Open now -> skip grep -q '"open":true' $STATUS_JSON - if [[ $? -eq 0 && "$status" -gt 0 ]] + if [[ $? -eq 0 && "$status" -gt 0 ]] then return fi # Previous status Closed & Closed now -> skip grep -q '"open":false' $STATUS_JSON - if [[ $? -eq 0 && "$status" -eq 0 ]] + if [[ $? -eq 0 && "$status" -eq 0 ]] then - return + return fi - if [ "$status" -eq 0 ] - then - printf "$TEMPLATE_JSON" $OPEN_JSON $( date +%s ) > $STATUS_JSON - else - printf "$TEMPLATE_JSON" $CLOSED_JSON $( date +%s ) > $STATUS_JSON - fi + if [ "$status" -gt 0 ] + then + printf "$TEMPLATE_JSON" $OPEN_JSON $( date +%s ) > $STATUS_JSON + else + printf "$TEMPLATE_JSON" $CLOSED_JSON $( date +%s ) > $STATUS_JSON + fi } tmpcount=$(mktemp) exec 3>$tmpcount /usr/sbin/dhcp-lease-list --parsable | awk '{print $4}' | while read ip do - /usr/bin/arping -w 1 -f -q $ip - [ $? -eq 0 ] && echo 1 >&3 + /usr/bin/arping -w 1 -f -q $ip + [ $? -eq 0 ] && echo 1 >&3 done exec 3>&-