#!/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 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"