aboutsummaryrefslogtreecommitdiffstats
path: root/bin/updates-sample.sh
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-30 19:56:47 +0200
committerDanilo M. <danix@danix.xyz>2026-09-30 19:56:47 +0200
commite55896ce41d6165105671da5b6f33813106ef1b8 (patch)
tree082c5a7dffda63bbe740363fb35ca6dd1927b5ab /bin/updates-sample.sh
parent9f6414838d4fabc174bb193f34225de8d9fc8079 (diff)
downloadconky-theme-udt-e55896ce41d6165105671da5b6f33813106ef1b8.tar.gz
conky-theme-udt-e55896ce41d6165105671da5b6f33813106ef1b8.zip
feat: add an updates card showing nvtable's package table
Moves the nvchecker/nvtable table the login shell printed onto the dashboard, as a wide card at the bottom centre. bin/updates-sample.sh caches `nvtable -C -E` every ten minutes and starts nvchecker, fully detached, at most every 30 minutes. The widget parses the cache and colours it in the board's language: installed behind upstream is critical, a shipped .info behind is a warning, with nvtable's status dots per row and a legend on the bottom line. The mouse wheel scrolls rows that do not fit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'bin/updates-sample.sh')
-rwxr-xr-xbin/updates-sample.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/bin/updates-sample.sh b/bin/updates-sample.sh
new file mode 100755
index 0000000..0c9ee3a
--- /dev/null
+++ b/bin/updates-sample.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+# Sample nvtable's package-update table into a cache file, for
+# widgets/updates.lua. Replaces the table the login shell used to print.
+#
+# nvchecker itself is slow (one network request per stanza), so it is started
+# in the background at most every 30 minutes, fully detached: conky's execi
+# waits for stdout to close, and a child holding it would stall the dashboard.
+# nvtable then reads whatever results the last completed run left, so a fresh
+# nvchecker run shows up on the next sample.
+
+set -u
+
+CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/udt"
+CACHE="$CACHE_DIR/updates.txt"
+STAMP="$CACHE_DIR/nvchecker.stamp"
+NVCHECK_EVERY=1800
+
+# conky launched from the compositor does not inherit the login shell's PATH.
+PATH="$HOME/bin:$HOME/.local/bin:$PATH"
+
+command -v nvtable >/dev/null || { echo "updates-sample: nvtable not found" >&2; exit 1; }
+
+mkdir -p "$CACHE_DIR"
+
+if command -v nvchecker >/dev/null; then
+ last=$(cat "$STAMP" 2>/dev/null || echo 0)
+ now=$(date +%s)
+ if (( now - ${last:-0} >= NVCHECK_EVERY )); then
+ echo "$now" > "$STAMP"
+ setsid nvchecker </dev/null >/dev/null 2>&1 &
+ fi
+fi
+
+TMP="$CACHE.tmp.$$"
+trap 'rm -f "$TMP"' EXIT
+
+# -C and -E: plain ASCII, which the widget parses and colours itself.
+# Keep the old cache when nvtable fails, rather than replacing it with nothing.
+nvtable -C -E > "$TMP" 2>/dev/null && mv -f "$TMP" "$CACHE"