aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LICENSE20
-rwxr-xr-xbattcheck12
-rw-r--r--conf4
-rwxr-xr-xrun23
4 files changed, 59 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..027c53c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright 2020 Tomasz Kramkowski <tk@the-tk.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/battcheck b/battcheck
new file mode 100755
index 0000000..4a6ce1f
--- /dev/null
+++ b/battcheck
@@ -0,0 +1,12 @@
+#!/bin/awk -f
+# Copyright (C) 2020 Tomasz Kramkowski <tk@the-tk.com>
+# SDPX-License-Identifier: MIT
+BEGIN { FS = "=" }
+{ a[substr($1, 14)] = $2 }
+END {
+ if (a["STATUS"] != "Discharging") exit 0
+ time_left = a["ENERGY_NOW"] / a["POWER_NOW"] * 3600
+ if (min_time && time_left < min_time) exit 1
+ if (min_pct && a["CAPACITY"] < min_pct) exit 1
+ exit 0
+}
diff --git a/conf b/conf
new file mode 100644
index 0000000..cff836d
--- /dev/null
+++ b/conf
@@ -0,0 +1,4 @@
+battery=/sys/class/power_supply/BAT0/uevent
+interval() { ./battcheck min_time=1200 min_pct=16 "$battery"; }
+check() { ./battcheck min_time=600 min_pct=8 "$battery"; }
+failed() { zzz -H; }
diff --git a/run b/run
new file mode 100755
index 0000000..784c89c
--- /dev/null
+++ b/run
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Copyright (C) 2020 Tomasz Kramkowski <tk@the-tk.com>
+# SDPX-License-Identifier: MIT
+
+. ./conf || exit 1
+trap '. ./conf' HUP
+
+check
+laststatus=$?
+
+while :; do
+ if interval; then
+ sleep "${long_interval-300}"
+ else
+ sleep "${short_interval-30}"
+ fi
+ check
+ status=$?
+ if [ "$laststatus" -eq 0 ] && [ "$status" -ne 0 ]; then
+ failed
+ fi
+ laststatus=$status
+done