#!/usr/bin/env bash # install-host-agent.sh — install hernani user systemd units on koopa # # # on koopa as hernani: # ~/src/taler-monitoring/host-agent/install-host-agent.sh # # or from laptop: # ./install-host-agent.sh --remote koopa-external # # Suite tree is ONLY ~/src/taler-monitoring (standalone repo). No koopa-admin-log. # set -euo pipefail ROOT=$(cd "$(dirname "$0")" && pwd) REMOTE="${1:-}" [ "${1:-}" = "--remote" ] && REMOTE="${2:-koopa-external}" SUITE_URL="${SUITE_GIT_URL:-https://git.hacktivism.ch/hernani/taler-monitoring.git}" install_local() { local mon home_unit mon=$(cd "$ROOT/.." && pwd) if [ -d "$HOME/src/taler-monitoring/.git" ] || [ -d "$HOME/src/taler-monitoring" ]; then mon="$HOME/src/taler-monitoring" fi home_unit="$HOME/.config/systemd/user" mkdir -p "$home_unit" \ "$HOME/.local/state/taler-hacktivism-monitoring" \ "$HOME/monitoring-sites-staging" \ "$HOME/.config/taler-monitoring" \ "$HOME/src" # Local env (never in git) — create from example if missing if [ ! -f "$HOME/.config/taler-monitoring/env" ] && [ -f "$ROOT/env.example" ]; then cp "$ROOT/env.example" "$HOME/.config/taler-monitoring/env" echo "created ~/.config/taler-monitoring/env" fi # Ensure suite git clone at canonical path if [ ! -d "$HOME/src/taler-monitoring/.git" ]; then if [ -d "$mon/.git" ] && [ "$mon" != "$HOME/src/taler-monitoring" ]; then mkdir -p "$HOME/src" ln -sfn "$mon" "$HOME/src/taler-monitoring" echo "symlink $HOME/src/taler-monitoring → $mon" else echo "clone $SUITE_URL → $HOME/src/taler-monitoring" git clone "$SUITE_URL" "$HOME/src/taler-monitoring" \ || echo "WARN: clone failed (auth/network) — using tree at $mon if present" fi fi mon="$HOME/src/taler-monitoring" # Convenience link (update-suite.sh also creates this) ln -sfn "$mon" "$HOME/taler-monitoring" 2>/dev/null || true # Ensure suite is executable chmod +x "$mon"/taler-monitoring.sh "$mon"/check_*.sh 2>/dev/null || true chmod +x "$mon/host-agent"/*.sh 2>/dev/null || true chmod +x "$mon/site-gen"/*.sh "$mon/site-gen/console_to_html.py" 2>/dev/null || true install -m 644 "$ROOT/taler-monitoring-hacktivism.service" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-hacktivism.path" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-hacktivism.timer" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-surface.service" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-surface.timer" "$home_unit/" # optional aptdeploy (not a public mon page layout — v1.8.0 simplified overview) install -m 644 "$ROOT/taler-monitoring-aptdeploy.service" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-aptdeploy.timer" "$home_unit/" # units still installed for migration; timers disabled (folded into surface) install -m 644 "$ROOT/taler-monitoring-mattermost.service" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-mattermost.timer" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-mail.service" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-mail.timer" "$home_unit/" systemctl --user daemon-reload systemctl --user enable --now taler-monitoring-hacktivism.path systemctl --user enable --now taler-monitoring-hacktivism.timer systemctl --user enable --now taler-monitoring-surface.timer systemctl --user enable --now taler-monitoring-aptdeploy.timer # v1.8.0: mail + mattermost folded into surface — stop separate timers systemctl --user disable --now taler-monitoring-mattermost.timer 2>/dev/null || true systemctl --user disable --now taler-monitoring-mail.timer 2>/dev/null || true # initial stamp so path exists "$ROOT/touch-software-stamp.sh" systemctl --user start taler-monitoring-hacktivism.service || true systemctl --user start taler-monitoring-surface.service || true systemctl --user start taler-monitoring-aptdeploy.service || true echo "--- status ---" systemctl --user status taler-monitoring-hacktivism.path --no-pager -l | head -15 systemctl --user status taler-monitoring-hacktivism.timer --no-pager -l | head -12 systemctl --user status taler-monitoring-surface.timer --no-pager -l | head -12 systemctl --user status taler-monitoring-aptdeploy.timer --no-pager -l | head -12 systemctl --user list-timers --all | grep taler-monitoring || true echo "OK host-agent (v1.8.0 simplified):" echo " · hacktivism 4h → /monitoring on bank/exchange/taler (landing stacks)" echo " · surface 1h → /taler-monitoring-surface* (ecosystem versions/software)" echo " · aptdeploy 4h (optional tests; not a public mon-page type)" echo " · mail/mattermost timers disabled (content in surface)" echo "suite: $mon" echo "manual surface: systemctl --user start taler-monitoring-surface.service" echo "after upgrades: $ROOT/touch-software-stamp.sh" } if [ -n "$REMOTE" ] && [ "$REMOTE" != "--remote" ]; then echo "install on $REMOTE …" # ROOT = …/taler-monitoring/host-agent → suite root is parent rsync -az --delete \ --exclude secrets.env \ --exclude 'android-test/artifacts' \ --exclude '.git' \ "$ROOT/../" \ "${REMOTE}:src/taler-monitoring/" ssh -o BatchMode=yes "$REMOTE" \ 'bash $HOME/src/taler-monitoring/host-agent/install-host-agent.sh' else install_local fi