add auto trig for api and send via telegram

This commit is contained in:
Your Name
2026-08-05 11:49:27 -04:00
parent bd92c7f899
commit d722842d20
19 changed files with 739 additions and 61 deletions
+2
View File
@@ -116,6 +116,8 @@ EXAMPLES
pos entertainment send weather Fetch Open-Meteo weather → Telegram
pos entertainment send joke --print Preview a joke locally (no send)
pos entertainment enable weather 5m Auto-send weather to Telegram every 5 min
pos entertainment status Show enabled plugins + next run
pos docker vbox create lab1 Create disposable Docker VM
pos docker vbox create lab1 --dir . Create VM using current directory
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -euo pipefail
# POS: entertainment config — Show or edit the entertainment config (ENABLED auto-trigger list, weather location)
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"
usage() {
cat <<EOF
Usage: pos entertainment config [set KEY=VALUE ...]
Show the entertainment config file, or set one or more keys.
After 'set', auto-trigger timers are re-synced from ENABLED.
Config file: $CONFIG_FILE
Keys:
ENABLED Auto-trigger list: comma-separated 'plugin, interval' pairs,
e.g. ENABLED="weather, 5m gold, 1h"
WEATHER_LAT Weather plugin latitude (required for weather)
WEATHER_LON Weather plugin longitude (required for weather)
WEATHER_CITY Optional city label
Intervals: 5m 10m 15m 30m 45m hourly 2h 6h 12h daily weekly, or OnCalendar=...
Examples:
pos entertainment config
pos entertainment config set ENABLED="weather, 5m gold, 1h"
pos entertainment config set WEATHER_LAT=36.51 WEATHER_LON=40.75
pos entertainment config set ENABLED=""
EOF
exit 0
}
case "${1:-}" in
-h|--help) usage ;;
set)
shift
[ $# -ge 1 ] || usage
for pair in "$@"; do
key="${pair%%=*}"
val="${pair#*=}"
case "$key" in
ENABLED|WEATHER_LAT|WEATHER_LON|WEATHER_CITY) ;;
*) err "Unknown key '$key' (allowed: ENABLED, WEATHER_LAT, WEATHER_LON, WEATHER_CITY)" ;;
esac
[ -z "$val" ] && [ "$key" != "ENABLED" ] && err "No value given (expected $key=...)"
write_config_key "$key" "$val"
ok "$key saved to $CONFIG_FILE"
done
sync_timers
;;
*)
echo "Config: $CONFIG_FILE"
if [ -f "$CONFIG_FILE" ]; then
cat "$CONFIG_FILE"
else
echo "(not created yet — run 'pos entertainment enable <plugin> [interval]' or 'pos entertainment config set ...')"
fi
echo
echo "ENABLED: $(config_value ENABLED)"
echo "Intervals: 5m 10m 15m 30m 45m hourly 2h 6h 12h daily weekly, or OnCalendar=..."
;;
esac
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
# POS: entertainment disable — Disable a plugin's auto-trigger (remove it from ENABLED)
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"
usage() {
cat <<EOF
Usage: pos entertainment disable <plugin>
Remove a plugin from the ENABLED list in
$CONFIG_FILE
and disable/remove its systemd user timer.
Examples:
pos entertainment disable weather
pos entertainment disable gold
EOF
exit 0
}
case "${1:-}" in
-h|--help) usage ;;
esac
[ $# -eq 1 ] || usage
plugin="$1"
enabled_remove "$plugin"
sync_timers
ok "'$plugin' disabled — schedule synced"
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -euo pipefail
# POS: entertainment enable — Enable an auto-trigger for a plugin (systemd user timer)
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"
usage() {
cat <<EOF
Usage: pos entertainment enable <plugin> [interval]
Enable an auto-trigger: writes '<plugin>, <interval>' into the ENABLED list in
$CONFIG_FILE
and creates/enables a systemd user timer that runs 'pos entertainment send <plugin>'
on the schedule. Re-running without an interval keeps the plugin's current one.
Available plugins:
$(list_plugins "$(plugin_dir)" | sed 's/^/ /')
Intervals: 5m 10m 15m 30m 45m hourly 2h 6h 12h daily weekly, or OnCalendar=...
Default: $DEFAULT_INTERVAL
Stop it with: pos entertainment disable <plugin>
Examples:
pos entertainment enable weather 5m
pos entertainment enable gold hourly
pos entertainment enable joke
EOF
exit 0
}
case "${1:-}" in
-h|--help) usage ;;
esac
[ $# -ge 1 ] || usage
plugin="$1"
interval="${2:-}"
resolve_plugin "$(plugin_dir)" "$plugin" >/dev/null
if [ -n "$interval" ]; then
interval_to_oncalendar "$interval" >/dev/null || \
err "Invalid interval '$interval' (allowed: 5m 10m 15m 30m 45m hourly 2h 6h 12h daily weekly, or OnCalendar=...)"
fi
enabled_upsert "$plugin" "$interval"
sync_timers
ok "'$plugin' enabled${interval:+ (every $interval)} — schedule synced"
+1 -32
View File
@@ -4,38 +4,7 @@ set -euo pipefail
# POS_FLAGS: --print --markdown
source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh"
# ── Plugin directory lookup ─────────────────────────────────────
plugin_dir() {
if [ -n "${ENTERTAINMENT_DIR:-}" ]; then
echo "$ENTERTAINMENT_DIR"
elif [ -d "$(dirname "$0")/../entertainment" ]; then
echo "$(cd "$(dirname "$0")/../entertainment" && pwd)"
elif [ -d "/usr/local/share/linux_post_install/entertainment" ]; then
echo "/usr/local/share/linux_post_install/entertainment"
else
err "entertainment plugin dir not found (set ENTERTAINMENT_DIR)"
fi
}
list_plugins() {
local dir="$1" f
for f in "$dir"/*; do
[ -f "$f" ] && [ -x "$f" ] && echo "$(basename "$f")"
done
}
resolve_plugin() {
local dir="$1" name="$2" f
[ -n "$name" ] || err "No plugin given"
for f in "$dir/$name" "$dir/$name.sh"; do
if [ -f "$f" ] && [ -x "$f" ]; then
echo "$f"
return 0
fi
done
err "Plugin '$name' not found in $dir — try one of: $(list_plugins "$dir" | tr '\n' ' ')"
}
source "$(dirname "$0")/../lib/entertainment-lib.sh" 2>/dev/null || source "$(dirname "$0")/entertainment-lib.sh"
usage() {
local dir plugins
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -euo pipefail
# POS: entertainment status — Show enabled plugins and their timer state
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"
usage() {
cat <<EOF
Usage: pos entertainment status
Show the enabled plugins (from ENABLED in $CONFIG_FILE)
and each one's systemd user timer state + next fire time.
Enable plugins with: pos entertainment enable <plugin> [interval]
EOF
exit 0
}
case "${1:-}" in
-h|--help) usage ;;
esac
raw="$(config_value ENABLED)"
echo "Config: $CONFIG_FILE"
if [ -z "$raw" ]; then
echo "No plugins enabled."
echo "Enable one with: pos entertainment enable <plugin> [interval]"
exit 0
fi
parse_enabled "$raw"
echo "Enabled plugins:"
for entry in "${ENABLED_ENTRIES[@]}"; do
plugin="${entry%%,*}"; interval="${entry##*,}"
[ "$interval" = "$plugin" ] && interval="$DEFAULT_INTERVAL"
printf ' %-12s %s\n' "$plugin" "$(interval_label "$interval")"
done
echo
echo "Scheduler: $(if systemctl --user show-environment >/dev/null 2>&1; then echo 'systemd user timers'; elif command -v crontab >/dev/null 2>&1; then echo 'cron (user crontab)'; else echo 'none available'; fi)"
if systemctl --user show-environment >/dev/null 2>&1; then
echo "Timers (systemd --user):"
systemctl --user list-timers --no-pager 'pos-entertainment-*.timer' 2>/dev/null || \
echo " (no timers)"
elif command -v crontab >/dev/null 2>&1; then
echo "Cron jobs (user crontab):"
block="$(cron_block)"
if [ -n "$block" ]; then
printf '%s\n' "$block" | sed 's/^/ /'
else
echo " (none)"
fi
fi