diff --git a/DOC/AGENT_Context_Project.md b/DOC/AGENT_Context_Project.md index 3f3dc5f..10e64d4 100644 --- a/DOC/AGENT_Context_Project.md +++ b/DOC/AGENT_Context_Project.md @@ -107,7 +107,8 @@ Linux_post_install/ │ └── pos.bash # Bash tab-completion for the pos CLI │ ├── config/ -│ └── authorized_keys # SSH public keys (gitignored) +│ ├── authorized_keys # SSH public keys (gitignored) +│ └── entertainment.env # Default weather location (auto-installed by postinstall) │ ├── compose/ │ └── scale-tail/ # Git submodule → ScaleTail templates (119+ services) @@ -364,6 +365,7 @@ All `.service` files in `systemd/` are automatically copied to `/etc/systemd/sys ### Runtime Config - `~/.config/linux_post_install/compose.env` — Docker Compose global defaults +- `~/.config/linux_post_install/entertainment.env` — entertainment plugin defaults (e.g. weather location); auto-installed from `config/entertainment.env` by `postinstall.sh` (no clobber) - `~/.bashrc` — Modified by postinstall (PATH, bash completion) ### Feature Flags @@ -468,7 +470,7 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:` |------|-------|---------| | `install.sh` | 192 | Main orchestrator — 4 phases with CLI flags, `--feature`, prebuilt arch bins | | `preinstall.sh` | 54 | System packages + hotspot deps + yt-dlp + fail2ban | -| `postinstall.sh` | 97 | fail2ban config, PATH, bash completion, systemd (flag-gated) | +| `postinstall.sh` | 114 | fail2ban config, PATH, bash completion, systemd (flag-gated) | | `lib/common.sh` | 121 | Shared library | | `lib/flags.sh` | 60 | Feature flag store (set/clear/is_set/value/list/status) | | `bin/flag-reader` | 58 | Inspect flags (list/status/`--raw`) | @@ -482,7 +484,7 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:` | `bin/pos-docker-health` | 110 | One-glance container health dashboard (exits 1 if unhealthy) | | `bin/pos-docker-ps` | 128 | Enhanced container overview (health, IPs, ports, uptime) | | `bin/pos-docker-vbox` | 157 | Disposable Docker-based VMs (create/enter/start/stop/rm/ls) | -| `bin/pos-entertainment-send` | 122 | Run a public-API plugin and send its output via Telegram (default sender) | +| `bin/pos-entertainment-send` | 124 | Run a public-API plugin and send its output via Telegram (default sender) | | `bin/pos-media-mp3` | 35 | Download audio as MP3 (yt-dlp) | | `bin/pos-media-mp4` | 38 | Download video as MP4 (interactive format select) | | `bin/pos-network-checkport` | 45 | Check TCP port connectivity | diff --git a/DOC/POS.md b/DOC/POS.md index 76ff2da..cc842d2 100644 --- a/DOC/POS.md +++ b/DOC/POS.md @@ -225,6 +225,8 @@ Plugins: | `weather` | Open-Meteo (no API key) | `~/.config/linux_post_install/entertainment.env`: `WEATHER_LAT`, `WEATHER_LON` (required), `WEATHER_CITY` (optional label) | | `joke` | icanhazdadjoke.com (no API key) | None | +**Config auto-install:** `postinstall.sh` copies the repo's `config/entertainment.env` (default: Al-Hasakah, Syria) to `~/.config/linux_post_install/entertainment.env` on install — but only if you haven't already created your own (no clobber). Override the default by creating/editing that file. + **Adding a plugin:** drop an executable script in `entertainment/` (e.g. `myfeed.sh`). It must be non-interactive and print the message to stdout; errors go to stderr (exit nonzero). If it needs coordinates/tokens, read them from `~/.config/linux_post_install/entertainment.env` (chmod 600, env precedence). No registration needed. Dependencies beyond `curl`/`jq` (both in `preinstall.sh` PACKAGES) should be guarded with `command -v … || exit 1`. **Automation:** the runner is headless/timer-friendly — no TTY prompts, exit 0 on success / 1 on failure. A systemd timer (e.g. hourly) can call `pos entertainment send weather` directly. Note the config files live under the user's `$HOME`, so the timer must run as that user (a systemd **user** unit, or a system unit with `Environment=HOME=/home/`). diff --git a/bin/pos-entertainment-send b/bin/pos-entertainment-send index bccc0be..0c7447e 100755 --- a/bin/pos-entertainment-send +++ b/bin/pos-entertainment-send @@ -99,8 +99,10 @@ unset 'plugin_args[0]' dir="$(plugin_dir)" script="$(resolve_plugin "$dir" "$plugin")" -if ! output="$("$script" "$@")"; then - err "Plugin '$plugin' failed (exit $?)" +rc=0 +output="$( "$script" "$@" )" || rc=$? +if [ "$rc" -ne 0 ]; then + err "Plugin '$plugin' failed (exit $rc)" fi [ -n "$output" ] || { warn "Plugin '$plugin' produced no output — nothing to send"; exit 0; } diff --git a/config/entertainment.env b/config/entertainment.env new file mode 100644 index 0000000..bb3d2a0 --- /dev/null +++ b/config/entertainment.env @@ -0,0 +1,3 @@ +WEATHER_CITY=Al-Hasakah, Syria +WEATHER_LAT=36.51 +WEATHER_LON=40.75 diff --git a/postinstall.sh b/postinstall.sh index 6bd8d12..bea13d7 100755 --- a/postinstall.sh +++ b/postinstall.sh @@ -13,7 +13,24 @@ if [ -f config/rclone.conf ]; then chmod 600 "$HOME/.config/rclone/rclone.conf" log "Installed rclone.conf" else - warn "fail2ban not found, skipping" + warn "config/rclone.conf not found, skipping" +fi + +# ── entertainment config ─────────────────────────────────────── +# Default location for the weather plugin — copied only if the user +# has not already created their own entertainment.env (no clobber). +ENT_DIR="$HOME/.config/linux_post_install" +if [ -f config/entertainment.env ]; then + mkdir -p "$ENT_DIR" + if [ -f "$ENT_DIR/entertainment.env" ]; then + log "entertainment.env already exists, keeping it" + else + cp config/entertainment.env "$ENT_DIR/entertainment.env" + chmod 600 "$ENT_DIR/entertainment.env" + log "Installed entertainment.env (default weather location)" + fi +else + warn "config/entertainment.env not found, skipping" fi # ── Ensure all bin dirs are in PATH ────────────────────────────