ai need continue
This commit is contained in:
@@ -553,7 +553,7 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:`
|
||||
| `features/autostart.sh` | 14 | Boot-time feature (moved from `bin/`, flag-gated service) |
|
||||
<!-- GEN:START filetable -->
|
||||
| `bin/pos` | 270 | CLI dispatcher with smart arg matching + logging + category help |
|
||||
| `bin/pos-communication-telegram-listener` | 433 | Telegram bot listener: map /command → bash, run them on chat messages |
|
||||
| `bin/pos-communication-telegram-listener` | 437 | Telegram bot listener: map /command → bash, run them on chat messages |
|
||||
| `bin/pos-communication-telegram-sender` | 270 | Send Telegram messages/files/links/stickers via Bot API (send, test, config set) |
|
||||
| `bin/pos-config` | 80 | Interactive editor for the tools' runtime config (reads # POS_CONFIG: registry) |
|
||||
| `bin/pos-docker-compose` | 366 | Docker Compose service manager (ls/up/down/restart/logs/update/config) |
|
||||
@@ -572,13 +572,13 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:`
|
||||
| `bin/pos-network-ip` | 69 | Show interfaces, routes, public IP + location |
|
||||
| `bin/pos-network-scan` | 271 | Parallel ping sweep of CIDR |
|
||||
| `bin/pos-ssh-load-keys` | 31 | Load all SSH keys into the agent |
|
||||
| `bin/pos-system-backup` | 125 | Encrypted (AES-256) folder snapshots (tar + gpg) |
|
||||
| `bin/pos-system-backup` | 126 | Encrypted (AES-256) folder snapshots (tar + gpg) |
|
||||
| `bin/pos-system-firewall` | 291 | Interactive UFW management |
|
||||
| `bin/pos-system-health` | 275 | Host health dashboard (disk, RAM, services, backup age, fail2ban, docker); exit 1 if any FAIL |
|
||||
| `bin/pos-system-health` | 209 | Host health dashboard (disk, RAM, services, backup age, fail2ban, docker); exit 1 if any FAIL |
|
||||
| `bin/pos-system-nfs-client` | 138 | Mount NFS shares (ephemeral or persistent systemd mount units) |
|
||||
| `bin/pos-system-nfs-server` | 134 | Manage the NFS kernel server (status, share/unshare exports, enable/disable) |
|
||||
| `bin/pos-usb-server` | 218 | USB Redirector server control (--ls, --share; prompts when args omitted) |
|
||||
| `completions/pos.bash` | 279 | Dynamic bash completion |
|
||||
| `completions/pos.bash` | 278 | Dynamic bash completion |
|
||||
<!-- GEN:END filetable -->
|
||||
| `apps/install.sh` | 171 | App install/uninstall picker/orchestrator |
|
||||
|
||||
|
||||
@@ -32,7 +32,11 @@ Map: $MAP_FILE — one '/cmd=bash command' per line
|
||||
|
||||
Prefix a map value with '@quiet ' to run the command without replying —
|
||||
for commands that already send their own notification, so you don't get it
|
||||
twice (e.g. '/status=@quiet pos system health --send').
|
||||
twice (e.g. '/backup=@quiet pos system backup --send').
|
||||
|
||||
To reply with a command's stdout (e.g. the health dashboard), just map it
|
||||
without '@quiet' and the listener forwards the output:
|
||||
'/status=pos system health'
|
||||
|
||||
The listener only reacts to the owner chat (TELEGRAM_CHAT_ID). Commands run
|
||||
as your user, so 'sudo' inside them needs a NOPASSWD rule. The interactive
|
||||
@@ -154,9 +158,9 @@ ui_pick() {
|
||||
}
|
||||
|
||||
# Map entries may be prefixed with '@quiet ' to run the command without
|
||||
# replying — for commands that deliver their own notification (e.g. the
|
||||
# health check's --send). The marker is stripped before running and before
|
||||
# the editor's bash -n syntax check.
|
||||
# replying — for commands that deliver their own notification (e.g. backup's
|
||||
# --send). The marker is stripped before running and before the editor's
|
||||
# bash -n syntax check.
|
||||
QUIET_PREFIX="@quiet"
|
||||
|
||||
strip_quiet() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
set -euo pipefail
|
||||
# POS: system backup — Encrypted (AES-256) folder snapshots (tar + gpg)
|
||||
# POS_FLAGS: --service
|
||||
# POS_CONFIG: notify | notify.env | NOTIFY_PLATFORM=:Comma-separated notify platforms (default telegram) — shared by backup, firewall, nfs-client and nfs-server
|
||||
|
||||
source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh"
|
||||
source "$(dirname "$0")/../lib/notify.sh" 2>/dev/null || source "$(dirname "$0")/notify.sh"
|
||||
|
||||
+8
-74
@@ -1,95 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
# POS: system health — Host health dashboard (disk, RAM, services, backup age, fail2ban, docker); exit 1 if any FAIL
|
||||
# POS_FLAGS: --send --markdown
|
||||
# POS_CONFIG: system | system.env | BACKUP_SERVICE_ROOTS=:Roots scanned by backup --service and the health backup-age check (default: /srv $HOME/srv) | HEALTH_BACKUP_MAX_AGE_DAYS=num:Max backup age in days before health warns (default 2)
|
||||
# POS_CONFIG: notify | notify.env | NOTIFY_PLATFORM=:Comma-separated notify platforms (default telegram)
|
||||
source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh"
|
||||
source "$(dirname "$0")/../lib/notify.sh" 2>/dev/null || source "$(dirname "$0")/notify.sh"
|
||||
|
||||
load_system_env
|
||||
|
||||
# Effective dynamic values (environment > system.env > defaults) shown in --help
|
||||
EFF_PLATFORMS="$(notify_platforms)"
|
||||
EFF_MAX_AGE="${HEALTH_BACKUP_MAX_AGE_DAYS:-2}"
|
||||
EFF_ROOTS="${BACKUP_SERVICE_ROOTS:-/srv $HOME/srv}"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: pos system health [--send] [--markdown]
|
||||
Usage: pos system health
|
||||
|
||||
Host health dashboard: disk, RAM/swap, failed systemd units, backup age,
|
||||
fail2ban, docker containers. Exits 1 if any check FAILs.
|
||||
fail2ban, docker containers. Prints the report and exits 1 if any check FAILs.
|
||||
|
||||
Flags:
|
||||
--send Send the summary via the configured notify platform(s) and do
|
||||
NOT print the dashboard (notification-only — for cron/timers or
|
||||
wrappers like the Telegram listener that reply with output)
|
||||
(uses lib/notify.sh; see NOTIFY_PLATFORM below)
|
||||
--markdown Same as --send, with markdown parse mode
|
||||
-h, --help Show this help
|
||||
The dashboard is meant to be read on a terminal or forwarded by a wrapper
|
||||
such as the Telegram listener (map '/status=pos system health'). Sending is
|
||||
the wrapper's job — health itself never sends notifications.
|
||||
|
||||
Environment (effective values):
|
||||
NOTIFY_PLATFORM ${EFF_PLATFORMS}
|
||||
HEALTH_BACKUP_MAX_AGE_DAYS ${EFF_MAX_AGE}
|
||||
BACKUP_SERVICE_ROOTS ${EFF_ROOTS}
|
||||
|
||||
Loaded from ~/.config/linux_post_install/system.env (health/backup settings)
|
||||
and ~/.config/linux_post_install/notify.env (NOTIFY_PLATFORM) unless already
|
||||
exported. Defaults apply when neither is set.
|
||||
Loaded from ~/.config/linux_post_install/system.env unless already exported.
|
||||
Defaults apply when the file is absent.
|
||||
|
||||
Examples:
|
||||
pos system health
|
||||
pos system health --send
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
SEND=0
|
||||
MARKDOWN=0
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
-h|--help) usage ;;
|
||||
--send) SEND=1 ;;
|
||||
--markdown) MARKDOWN=1 ;;
|
||||
*) err "Unknown option '$arg' (see --help)" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$MARKDOWN" -eq 1 ]; then
|
||||
SEND=1
|
||||
fi
|
||||
|
||||
# --send is notification-only: suppress the dashboard output (so a wrapper
|
||||
# such as the Telegram listener doesn't echo it back as a duplicate reply).
|
||||
if [ "$SEND" -eq 1 ]; then
|
||||
exec 3>&1
|
||||
exec 1>/dev/null
|
||||
fi
|
||||
|
||||
FAILURES=0
|
||||
WARNINGS=0
|
||||
REPORT=()
|
||||
|
||||
report() {
|
||||
local st="$1" label="$2" detail="$3" line
|
||||
local st="$1" label="$2" detail="$3"
|
||||
case "$st" in
|
||||
ok)
|
||||
echo " ${GREEN}${BOLD}[ OK ]${RESET} ${label}: ${detail}"
|
||||
printf -v line "[ OK ] %s: %s" "$label" "$detail"
|
||||
;;
|
||||
warn)
|
||||
echo " ${YELLOW}${BOLD}[WARN]${RESET} ${label}: ${detail}"
|
||||
printf -v line "[WARN] %s: %s" "$label" "$detail"
|
||||
WARNINGS=$((WARNINGS + 1))
|
||||
;;
|
||||
fail)
|
||||
echo " ${RED}${BOLD}[FAIL]${RESET} ${label}: ${detail}"
|
||||
printf -v line "[FAIL] %s: %s" "$label" "$detail"
|
||||
FAILURES=$((FAILURES + 1))
|
||||
;;
|
||||
esac
|
||||
REPORT+=("$line")
|
||||
}
|
||||
|
||||
host="$(hostname -s 2>/dev/null || echo "localhost")"
|
||||
@@ -237,39 +206,4 @@ else
|
||||
echo " ${GREEN}${BOLD}VERDICT${RESET} ${verdict}"
|
||||
fi
|
||||
|
||||
if [ "$SEND" -eq 1 ]; then
|
||||
exec 1>&3 3>&-
|
||||
msg="POS Health — ${host}
|
||||
Verdict: ${verdict}"
|
||||
for line in "${REPORT[@]}"; do
|
||||
msg+="
|
||||
${line}"
|
||||
done
|
||||
if [ "$MARKDOWN" -eq 1 ]; then
|
||||
notify_send "$msg" --markdown
|
||||
else
|
||||
notify_send "$msg"
|
||||
fi
|
||||
# notify_send is silent-fail by design — confirm delivery only when a
|
||||
# platform sender actually exists, otherwise warn on stderr (still visible
|
||||
# here since only stdout was redirected while --send ran).
|
||||
delivered=0
|
||||
IFS=',' read -r -a platforms <<< "$(notify_platforms)"
|
||||
for p in "${platforms[@]}"; do
|
||||
p="${p// /}"
|
||||
[ -n "$p" ] || continue
|
||||
sname="$(notify_sender_name "$p")"
|
||||
if command -v "pos-communication-$sname" &>/dev/null \
|
||||
|| [ -x "$(dirname "$0")/pos-communication-$sname" ] \
|
||||
|| [ -x "$(dirname "$0")/../bin/pos-communication-$sname" ]; then
|
||||
delivered=1
|
||||
fi
|
||||
done
|
||||
if [ "$delivered" -eq 1 ]; then
|
||||
echo "sent: POS Health — ${host} (${verdict})"
|
||||
else
|
||||
warn "notify: no platform sender found (NOTIFY_PLATFORM=$(notify_platforms)) — digest not delivered"
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "$FAILURES" -eq 0 ]
|
||||
|
||||
@@ -8,7 +8,6 @@ _pos_flags[communication-telegram-sender]="--type --caption --parse-mode --no-pr
|
||||
_pos_flags[entertainment-send]="--print --markdown"
|
||||
_pos_flags[network-hotspot]="--foreground"
|
||||
_pos_flags[system-backup]="--service"
|
||||
_pos_flags[system-health]="--send --markdown"
|
||||
_pos_flags[usb-server]="--ls --ls-shared --share --unshare --auto-share --callback --close-callback --auto-connect --disconnect --nickname --timeout --port --info --version"
|
||||
# GEN:END posflags
|
||||
# GEN:START possubcmds
|
||||
|
||||
@@ -114,13 +114,6 @@ if [ -d systemd ] && [ -n "$(ls -A systemd/*.service 2>/dev/null)" ]; then
|
||||
fi
|
||||
run sudo systemctl daemon-reload
|
||||
|
||||
# pos-health.service runs as the installing user so the digest uses that
|
||||
# user's real Telegram config. The timer is enabled only when a telegram.env
|
||||
# is configured — re-run postinstall after configuring Telegram to pick it up.
|
||||
DIGEST_USER="${SUDO_USER:-$USER}"
|
||||
DIGEST_HOME="$(getent passwd "$DIGEST_USER" 2>/dev/null | cut -d: -f6)"
|
||||
DIGEST_HOME="${DIGEST_HOME:-$HOME}"
|
||||
|
||||
for svc in systemd/*.service; do
|
||||
svc_name=$(basename "$svc")
|
||||
# autostart.service runs features/autostart.sh — enable only when
|
||||
@@ -129,18 +122,6 @@ if [ -d systemd ] && [ -n "$(ls -A systemd/*.service 2>/dev/null)" ]; then
|
||||
warn "autostart feature not installed — skipping autostart.service (run ./install.sh --feature)"
|
||||
continue
|
||||
fi
|
||||
if [ "$svc_name" = "pos-health.service" ]; then
|
||||
run sudo sed -i "s|__POS_USER__|$DIGEST_USER|" "/etc/systemd/system/$svc_name"
|
||||
run sudo systemctl daemon-reload
|
||||
if [ -f "$DIGEST_HOME/.config/linux_post_install/telegram.env" ]; then
|
||||
run sudo systemctl enable --now pos-health.timer 2>/dev/null || \
|
||||
run sudo systemctl enable pos-health.timer
|
||||
log "Daily health digest timer enabled for $DIGEST_USER"
|
||||
else
|
||||
warn "Telegram not configured — skipping health digest timer (run 'pos communication telegram sender config set ...' then re-run postinstall)"
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
run sudo systemctl enable --now "$svc_name" 2>/dev/null || \
|
||||
run sudo systemctl enable "$svc_name"
|
||||
done
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
[Unit]
|
||||
Description=POS Health digest (daily report via configured notify platforms)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=__POS_USER__
|
||||
EnvironmentFile=-%h/.config/linux_post_install/system.env
|
||||
EnvironmentFile=-%h/.config/linux_post_install/notify.env
|
||||
ExecStart=/usr/local/bin/pos system health --send --markdown
|
||||
@@ -1,9 +0,0 @@
|
||||
[Unit]
|
||||
Description=Daily POS health digest timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 08:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Reference in New Issue
Block a user