Files
Linux_post_install/bin/pos-entertainment-send
he 5ef38dc46f fix: resolve all 23 MAINTENANCE audit tickets
- deps guards before -h|--help in docker-health/ps, network-scan,
  usb-server, media-mp3/mp4 (--dry-run pre-scan kept); system-firewall
  gains usage()/--help; autostart/usb-automount get flags.sh + template
- install.sh: normalize N-M range syntax in --steps
- bin/pos: INTERACTIVE_CMDS += docker-compose docker-vbox network-hotspot
- common.sh: canonical XDG-aware CONFIG_DIR + DIM color var; notify.sh
  stderr fallback; ent_plugin_* registry renames (runtime plugin API kept)
- docker-compose SCALE_DIR/CONFIG_ENV env seams; ffmpeg in PACKAGES;
  scrcpy.sh exec bit
- docs: health is console-only (--send/--markdown removed), POS.md file
  refs for config/tree/entertainment, DEV.md no-guard exception, docmap/
  filetable regenerated (make gen), hand-maintained line rows bumped
- add scripts/lint-conventions.sh gate + Makefile lint target; record
  all VERIFIED outcomes in MAINTENANCE.md; AGENT_TODO Done entry
  (2026-08-14)
- gates: make gen/check/lint all green (0 FAIL, 0 WARN); bash -n sweep
  clean; restricted-PATH dep tests + step-matrix dry-runs verified
2026-08-14 12:57:00 -04:00

96 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# POS: entertainment send — Run a public-API plugin and send its output via the configured notify platforms
# POS_FLAGS: --print --markdown
source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh"
source "$(dirname "$0")/../lib/entertainment-lib.sh" 2>/dev/null || source "$(dirname "$0")/entertainment-lib.sh"
source "$(dirname "$0")/../lib/notify.sh" 2>/dev/null || source "$(dirname "$0")/notify.sh"
usage() {
local dir plugins
dir="$(ent_plugin_dir 2>/dev/null)" || dir=""
if [ -n "$dir" ]; then
plugins="$(list_plugins "$dir" | sed 's/^/ /')"
else
plugins=" (plugin directory not found — set ENTERTAINMENT_DIR)"
fi
cat <<EOF
Usage: pos entertainment send <plugin> [--print] [--markdown] [plugin args...]
Run an entertainment plugin, capture its output, and send it via the configured
notify platforms (NOTIFY_PLATFORM, default Telegram).
Plugins are scripts that fetch a public API and print the message to stdout —
that stdout is what gets sent.
Modes:
(default) Send the plugin output via notify_send (silent)
--print Print the output locally instead of sending
--markdown Send with Markdown parse_mode (via the notify senders)
Available plugins:
$plugins
Environment:
ENTERTAINMENT_DIR Override the plugin directory
Config (per plugin): ~/.config/linux_post_install/entertainment.env
Examples:
pos entertainment send weather
pos entertainment send weather --print
pos entertainment send joke --markdown
EOF
exit 0
}
case "${1:-}" in
-h|--help|"") usage ;;
esac
# ── Parse runner flags ──────────────────────────────────────────
PRINT=0
MARKDOWN=0
plugin_args=()
while [ $# -gt 0 ]; do
case "$1" in
--print) PRINT=1; shift ;;
--markdown) MARKDOWN=1; shift ;;
-h|--help) usage ;;
*) plugin_args+=("$1"); shift ;;
esac
done
[ ${#plugin_args[@]} -ge 1 ] || usage
plugin="${plugin_args[0]}"
unset 'plugin_args[0]'
# ── Run the plugin ──────────────────────────────────────────────
dir="$(ent_plugin_dir)"
script="$(resolve_plugin "$dir" "$plugin")"
rc=0
output="$( "$script" "${plugin_args[@]}" )" || rc=$?
if [ "$rc" -ne 0 ]; then
[ -n "${INVOCATION_ID:-}" ] && notify_send "⚠️ entertainment '$plugin' failed (exit $rc)"
save_last_run "$plugin" "$rc" "$(printf '%s' "$output" | head -1)"
err "Plugin '$plugin' failed (exit $rc)"
fi
[ -n "$output" ] || { warn "Plugin '$plugin' produced no output — nothing to send"; save_last_run "$plugin" 0 ""; exit 0; }
# ── Route the output ────────────────────────────────────────────
if [ "$PRINT" -eq 1 ]; then
printf '%s\n' "$output"
exit 0
fi
save_last_run "$plugin" 0 "$(printf '%s' "$output" | head -1)"
if [ "$MARKDOWN" -eq 1 ]; then
notify_send --markdown "$output"
else
notify_send "$output"
fi