From 7d9345c9564370bdb32cbb06d24b238986572ea6 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 19 Aug 2021 12:42:52 +0200 Subject: Added battery-low-notify script and crontab to run it every 10min --- crontab/laptop.crontab | 3 +++ install | 11 +++++++++-- local/bin/battery-low-check | 5 ----- local/bin/battery-low-notify | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 crontab/laptop.crontab delete mode 100755 local/bin/battery-low-check create mode 100755 local/bin/battery-low-notify diff --git a/crontab/laptop.crontab b/crontab/laptop.crontab new file mode 100644 index 0000000..18f36f1 --- /dev/null +++ b/crontab/laptop.crontab @@ -0,0 +1,3 @@ +*/10 * * * * . $HOME/.zprofile ; DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u $USER)/bus" DISPLAY=:0 battery-low-notify + +# vim:ft=crontab diff --git a/install b/install index 2c6ee73..892e845 100755 --- a/install +++ b/install @@ -6,7 +6,7 @@ if [ "$USER" = 'root' ] then - crontab 'crontab/root.crontab' + crontab crontab/root.crontab exit fi @@ -96,7 +96,14 @@ parallel_wait ############################################################################### echo '---------------------------- INSTALL CRONTAB -----------------------------' -crontab 'crontab/user.crontab' + +if [ "$(hostname)" = 'charleslaptopcarbon' ] +then + cat crontab/user.crontab crontab/laptop.crontab | crontab - +else + crontab crontab/user.crontab +fi + echo 'INFO: Run this script as root if you want to install the root contab' ############################################################################### diff --git a/local/bin/battery-low-check b/local/bin/battery-low-check deleted file mode 100755 index dbbdc6b..0000000 --- a/local/bin/battery-low-check +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -capacity=$(cat /sys/class/power_supply/BAT0/capacity) - -[ "$capacity" -lt 10 ] && notify-send -u critical "Battery low $capacity%" diff --git a/local/bin/battery-low-notify b/local/bin/battery-low-notify new file mode 100755 index 0000000..605ea91 --- /dev/null +++ b/local/bin/battery-low-notify @@ -0,0 +1,14 @@ +#!/bin/sh + +battery_dir='/sys/class/power_supply/BAT0' + +[ ! -d "$battery_dir" ] && exit 1 + +if [ "$(cat "$battery_dir/status")" != 'Charging' ] +then + capacity="$(cat "$battery_dir/capacity")" + [ "$capacity" -lt 15 ] && + notify-send -u critical "Battery low: $capacity%" +fi + +exit 0 -- cgit