git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/localfs/usr/local/bin/batman
diff options
context:
space:
mode:
Diffstat (limited to 'localfs/usr/local/bin/batman')
-rwxr-xr-xlocalfs/usr/local/bin/batman41
1 files changed, 41 insertions, 0 deletions
diff --git a/localfs/usr/local/bin/batman b/localfs/usr/local/bin/batman
new file mode 100755
index 0000000..bfa00c0
--- /dev/null
+++ b/localfs/usr/local/bin/batman
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+declare -x VOERBOOS
+export RETVAL=0
+export BATVAL="$(echo "scale=0;$(cat /sys/class/power_supply/BAT0/charge_now)*100/$(cat /sys/class/power_supply/BAT0/charge_full)"|bc -l)"
+export BATSTATE="$(cat /sys/class/power_supply/BAT0/status)"
+function 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"+$?))
+ ;;
+ *)
+ MSG="Battery charged at $BATVAL%, powering down."
+ [ ! -z "$VOERBOOS" ]&&[ "$VOERBOOS" -eq 1 ]&&echo "$MSG"||true
+ logger -pwarn -t"batman" "$MSG"||RETVAL=$(("$RETVAL"+$?))
+ sudo shutdown -P +2 "$MSG"||RETVAL=$(("$RETVAL"+$?))
+ ;;
+ esac
+ else
+ MSG="Battery charged at $BATVAL%, no shutdown."
+ [ ! -z "$VOERBOOS" ]&&[ "$VOERBOOS" -eq 1 ]&&echo "$MSG"||logger -p"info" -t"batman" "$MSG"||RETVAL=$(("$RETVAL"+$?))
+ fi
+}
+function batarang {
+ MSG="$BATVAL% ($BATSTATE)";echo "$MSG";
+}
+
+while getopts :vnp SHOPT;do
+ case "$SHOPT" in
+ v)export VOERBOOS=1;;
+ p)batmobile;;
+ ""|n)batarang;;
+ *)echo "Not supported option: -""${OPTARG}" >&2;RETVAL=$(($RETVAL+1)) >&2;WRONGOPT=1;;
+ esac
+done
+shift $(( $OPTIND - 1 ))
+[ ! -z "$WRONGOPT" ]&&[ "$WRONGOPT" -eq 1 ]&&exit 1||true
+exit "$RETVAL"