diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/disks-sample.sh | 40 | ||||
| -rwxr-xr-x | bin/pubip-sample.sh | 48 |
2 files changed, 0 insertions, 88 deletions
diff --git a/bin/disks-sample.sh b/bin/disks-sample.sh deleted file mode 100755 index 5291bcf..0000000 --- a/bin/disks-sample.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -# Sample filesystem usage into a cache file, for widgets/disks.lua. -# -# This exists so the draw hook never calls statfs on an NFS path. An -# unreachable server blocks that call, and blocking the Cairo draw freezes the -# whole dashboard; here it costs a stale cache and nothing else. -# -# One NFS mount per server: Library and Slackware are the same export on one -# server, shared and backup_danix the same on another, so showing all four -# printed every number twice. - -set -u - -CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/udt" -CACHE="$CACHE_DIR/disks.txt" - -MOUNTS=(/ /home /data /mnt/nfs/Library /mnt/nfs/shared) - -umask 077 -mkdir -p "$CACHE_DIR" - -TMP="$CACHE.tmp.$$" -trap 'rm -f "$TMP"' EXIT - -# /usr/bin/df by absolute path with -P -B1, deliberately: -# - the user's shell aliases df to `df -h`, and an alias or a function would -# hand the parser '1.6G' where it expects an integer -# - -P is the POSIX format, one line per filesystem, mountpoint last -# - -B1 is bytes, so the widget does the formatting and the parser never -# has to interpret a suffix -if ! /usr/bin/df -P -B1 "${MOUNTS[@]}" > "$TMP" 2>/dev/null; then - # A single unreachable mount must not discard the others: df still reports - # the ones it could stat, so keep the output if it has any data rows. - if [ "$(wc -l < "$TMP")" -lt 2 ]; then - echo "disks-sample: df produced nothing usable" >&2 - exit 1 - fi -fi - -mv -f "$TMP" "$CACHE" diff --git a/bin/pubip-sample.sh b/bin/pubip-sample.sh deleted file mode 100755 index c5100f8..0000000 --- a/bin/pubip-sample.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -# Fetch the public IP address into a cache file, for widgets/network.lua. -# -# Run from conky's ${execi} every 30 minutes. The draw hook must never make a -# network call: a hung request would block the Cairo draw and freeze the whole -# dashboard, and a residential address is stable for days anyway. -# -# Exits non-zero with a message on stderr when it cannot fetch, leaving any -# existing cache untouched rather than replacing a good address with an error -# page. - -set -u - -CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/udt" -CACHE="$CACHE_DIR/pubip.txt" - -umask 077 -mkdir -p "$CACHE_DIR" - -# The temp file sits in the same directory as the target: rename is only -# atomic within a filesystem, and the widget reads this on its own 2s cadence. -TMP="$CACHE.tmp.$$" -trap 'rm -f "$TMP"' EXIT - -# --max-time, not just --connect-timeout: a server that accepts the connection -# and then stalls would otherwise hold a curl process for as long as it likes. -if ! IP=$(curl -fsS --max-time 10 https://ipinfo.io/ip 2>/dev/null); then - echo "pubip-sample: fetch failed" >&2 - exit 1 -fi - -# Validate before writing. A captive portal, a rate-limit message and an error -# page all arrive with a 200 and would otherwise be written to the cache and -# drawn on the dashboard as though they were an address. -IP=$(echo "$IP" | tr -d '[:space:]') -if ! echo "$IP" | grep -qE '^([0-9]{1,3}\.){3}[0-9]{1,3}$'; then - echo "pubip-sample: response is not an IPv4 address" >&2 - exit 1 -fi - -# The epoch travels with the address so the widget can refuse to show a stale -# one. -{ - echo "ip $IP" - echo "fetched $(date +%s)" -} > "$TMP" - -mv -f "$TMP" "$CACHE" |
