summaryrefslogtreecommitdiff
path: root/scripts/daemons
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2025-11-25 18:47:27 +0400
committerSuleyman Farajli <suleyman@farajli.net>2025-11-25 18:47:27 +0400
commitd947956270b092df10637bb3531441caca698b86 (patch)
tree8c32170ef044687b11be79398140a36430e2ff0a /scripts/daemons
parentc388ade6b6d955138698731af02dfbe5c676439a (diff)
feat: new api for scripts
Diffstat (limited to 'scripts/daemons')
-rwxr-xr-xscripts/daemons/bat-checkd16
-rwxr-xr-xscripts/daemons/mail-syncd6
-rwxr-xr-xscripts/daemons/notifd35
3 files changed, 57 insertions, 0 deletions
diff --git a/scripts/daemons/bat-checkd b/scripts/daemons/bat-checkd
new file mode 100755
index 0000000..2c272b8
--- /dev/null
+++ b/scripts/daemons/bat-checkd
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# FIXME: hardcoded battery
+BAT="/sys/class/power_supply/BAT0"
+
+while true; do
+ percent=$(cat "${BAT}/capacity")
+ status=$(cat "${BAT}/status")
+
+ # Only notify if battery is low AND not charging
+ if [ "${status}" = "Discharging" ] && [ "${percent}" -lt 7 ]; then
+ nsend -s "Battery" "Critically low: ${percent}%"
+ fi
+
+ sleep 120
+done
diff --git a/scripts/daemons/mail-syncd b/scripts/daemons/mail-syncd
new file mode 100755
index 0000000..e317ace
--- /dev/null
+++ b/scripts/daemons/mail-syncd
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+while true; do
+ mbsync -a
+ sleep 300
+done
diff --git a/scripts/daemons/notifd b/scripts/daemons/notifd
new file mode 100755
index 0000000..9ad5697
--- /dev/null
+++ b/scripts/daemons/notifd
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+. "lib_handle.sh"
+
+FIFO=/tmp/noti.fifo
+FILE=/tmp/noti.txt
+
+[ -p "${FIFO}" ] || mkfifo "${FIFO}"
+
+exec 3<"${FIFO}"
+exec 4>"${FIFO}"
+
+tpid=""
+
+cancel() {
+ [ -n "${tpid}" ] && kill "${tpid}" 2>/dev/null
+ tpid=""
+}
+
+while read n <&3; do
+ [ "${n}" = "-1" ] && { cancel; continue; }
+
+ case "${n}" in ''|*[!0-9]*) continue ;; esac
+
+ cancel
+
+ [ "${n}" -gt 0 ] || { :>"${FILE}"; notify_handle reload; continue; }
+
+ (
+ sleep "${n}"
+ :>"${FILE}"
+ notify_handle reload
+ ) &
+ tpid=$!
+done