diff options
author | H. P. <harald.p.@xmart.de> | 2018-06-27 13:44:00 +0200 |
---|---|---|
committer | H. P. <harald.p.@xmart.de> | 2018-06-27 13:44:00 +0200 |
commit | 62c5df3ab5e2a7f9087bd92941ac1d171a29186b (patch) | |
tree | 347c29120fd576f16d2d3157d43e4bc3c3a54e7c /bin | |
parent | c0845627b0a78c954cd9a8ec1f2c74fbadb319dd (diff) | |
download | batman-62c5df3ab5e2a7f9087bd92941ac1d171a29186b.tar.bz2 |
Code sanitation and line length limiting
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/batman | 47 |
1 files changed, 30 insertions, 17 deletions
@@ -1,24 +1,31 @@ #!/bin/sh -declare -x VOERBOOS +export VOERBOOS RETVAL=0;export RETVAL -BATVAL="$(echo "scale=0;$(cat /sys/class/power_supply/BAT0/charge_now)*100/$(cat /sys/class/power_supply/BAT0/charge_full)"|bc -l)";export BATVAL -BATSTATE="`cat /sys/class/power_supply/BAT0/status`";export BATSTATE +CNOW="$(cat /sys/class/power_supply/BAT0/charge_now)" +CFUL="$(cat /sys/class/power_supply/BAT0/charge_full)" +BATVAL="$(echo "scale=0;$CNOW*100/$CFUL"|bc -l)";export BATVAL +unset CNOW CFUL +BATSTATE="$(cat /sys/class/power_supply/BAT0/status)";export BATSTATE BATFILE="/tmp/batman.sd";export BATFILE export OPTCNT=0 -function batmobile { +batmobile() { if [ "$BATVAL" -le 5 ];then case "$BATSTATE" in "Charging") MSG="Battery charged at $BATVAL% with status \"$BATSTATE\", no shutdown." - [ ! -z "$VOERBOOS" ]&&[ "$VOERBOOS" -eq 1 ]&&echo "$MSG"||true - logger -p"info" -t"batman" "Battery charged at $BATVAL% with status \"$BATSTATE\", no shutdown."||RETVAL=$(("$RETVAL"+$?)) + [ ! -z "$VOERBOOS" ]&&[ "$VOERBOOS" -eq 1 ]&&echo "$MSG" + LMSG="Battery charged at $BATVAL% with status \"$BATSTATE\", no shutdown." + logger -p"info" -t"batman" "$LMSG"||RETVAL=$(("$RETVAL"+$?)) + unset LMSG [ -e "$BATFILE" ]&&/usr/sbin/shutdown -c >/dev/null 2>&1&&rm "$BATFILE" SDCRV="$?" case "$SDCRV" in 0) logger -p"info" -t"batman" "Shutdown cancelled.";; *) - logger -p"warn" -t"batman" "$BATFILE exists but couldn't cancel shutdown!" + LMSG="batman" "$BATFILE exists but couldn't cancel shutdown!" + logger -p"warn" -t"$LMSG" + unset LMSG RETVAL=$(("$RETVAL"+"$SDCRV")) ;; esac @@ -26,30 +33,36 @@ function batmobile { *) MSG="Battery charged at $BATVAL%, powering down." [ ! -z "$VOERBOOS" ]&&[ "$VOERBOOS" -eq 1 ]&&echo "$MSG"||true - logger -pwarn -t"batman" "$MSG"||RETVAL=$(("$RETVAL"+$?)) + logger -pwarn -t"batman" "$MSG";RETVAL=$((RETVAL+"$?")) if [ ! -e "$BATFILE" ];then - /usr/sbin/shutdown -P +2 "Battery low and discharging, powering down. (batman)"&&touch "$BATFILE"||RETVAL=$(("$RETVAL"+$?)) + SMSG="Battery low and discharging, powering down. (batman)" + /usr/sbin/shutdown -P +2 "$SMSG"&&touch "$BATFILE" + RETVAL=$((RETVAL+"$?")) fi ;; esac else MSG="Battery charged at $BATVAL%, no shutdown." - [ ! -z "$VOERBOOS" ]&&[ "$VOERBOOS" -eq 1 ]&&echo "$MSG"||logger -p"info" -t"batman" "$MSG"||RETVAL=$(("$RETVAL"+$?)) + [ ! -z "$VOERBOOS" ]&&[ "$VOERBOOS" -eq 1 ]&&echo "$MSG"||logger -p"info" -t"batman" "$MSG" + RETVAL=$((RETVAL+"$?")) fi } -function batarang { +batarang() { MSG="$BATVAL% ($BATSTATE)";echo "$MSG"; } while getopts :vnp SHOPT;do case "$SHOPT" in - v)VOERBOOS=1;export VOERBOOS;((OPTCNT++));; - p)batmobile;((OPTCNT++));; - ""|n)batarang;((OPTCNT++));; - *)echo "Not supported option: -""${OPTARG}" >&2;RETVAL=$(($RETVAL+1)) >&2;WRONGOPT=1;((OPTCNT++));; + v)VOERBOOS=1;export VOERBOOS;OPTCNT=$((OPTCNT+1));; + p)batmobile;OPTCNT=$((OPTCNT+1));; + n)batarang;OPTCNT=$((OPTCNT+1));; + *) + echo "Not supported option: -""${OPTARG}" >&2 + RETVAL=$((RETVAL+1));WRONGOPT=1 ;OPTCNT=$((OPTCNT+1)) + ;; esac done -shift $(( $OPTIND - 1 )) +shift $((OPTIND-1)) [ "$OPTCNT" -le 0 ]&&batarang -[ ! -z "$WRONGOPT" ]&&[ "$WRONGOPT" -eq 1 ]&&exit 1||true +[ ! -z "$WRONGOPT" ]&&[ "$WRONGOPT" -eq 1 ]&&exit 1;true exit "$RETVAL" |