Files
corsairctl/scripts/corsairctl-waybar.sh
T
nevaforget 717c54c9c1
CI / test (push) Successful in 5s
Update PKGBUILD version / update-pkgver (push) Successful in 0s
chore: harden CI and shipped script, tidy internals (audit remediation)
A four-axis audit found no HIGH/MEDIUM issues. This addresses the
remaining low-risk items and protects the release path:

- ci: add cargo test + clippy -D warnings gate on master/tags
- ci: reject malformed version tags before the pkgver sed substitution
- fix: move the shipped waybar wrapper's cache/lock to $XDG_RUNTIME_DIR
  (mode-700, no cross-user symlink) instead of predictable /tmp paths
- refactor: find_card() returns the open ALSA mixer, dropping a second
  open; collapse two if-let blocks into edition-2024 let-chains
- docs: record in DECISIONS.md why the audit's "dead code" stays (it
  mirrors the Bragi spec) and why the 5ms HID sleep is left as-is

Bump 0.1.4 -> 0.1.5: the shipped waybar script changes behavior.
2026-06-23 16:03:35 +02:00

31 lines
915 B
Bash
Executable File

#!/bin/bash
# ABOUTME: Waybar-Wrapper für corsairctl — cached JSON-Output.
# ABOUTME: Verhindert dass mehrere Waybar-Bars gleichzeitig das HID-Gerät ansprechen.
RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
CACHE="$RUNTIME_DIR/corsairctl-waybar.json"
LOCK="$RUNTIME_DIR/corsairctl-waybar.lock"
MAX_AGE=300
FALLBACK='{"text":"","tooltip":"","class":"offline","percentage":0}'
# Cache frisch genug? Direkt ausgeben.
if [[ -f "$CACHE" ]] && [[ -s "$CACHE" ]]; then
age=$(( $(date +%s) - $(stat -c %Y "$CACHE") ))
if (( age < MAX_AGE )); then
cat "$CACHE"
exit 0
fi
fi
# Lock holen, abfragen, cachen.
(
flock -w 5 9 || { cat "$CACHE" 2>/dev/null || echo "$FALLBACK"; exit 0; }
if corsairctl json > "${CACHE}.tmp" 2>/dev/null; then
mv "${CACHE}.tmp" "$CACHE"
cat "$CACHE"
else
rm -f "${CACHE}.tmp"
echo "$FALLBACK"
fi
) 9>"$LOCK"