#!/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 # set -euo pipefail ROOT=$(cd "$(dirname "$0")" && pwd) REMOTE="${1:-}" [ "${1:-}" = "--remote" ] && REMOTE="${2:-koopa-external}" install_local() { local mon home_unit mon=$(cd "$ROOT/.." && pwd) # Prefer ~/koopa-admin-log on live host if [ -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 # Prefer a real git clone for update-suite.sh if [ ! -d "$HOME/src/koopa-admin-log/.git" ] && [ ! -d "$HOME/koopa-admin-log/.git" ]; then if [ -d "$HOME/src/taler-monitoring" ] && [ ! -d "$HOME/koopa-admin-log/.git" ]; then echo "note: $HOME/koopa-admin-log has no .git — update-suite will clone to ~/src/koopa-admin-log" fi git clone https://git.hacktivism.ch/hernani/taler-monitoring.git "$HOME/src/koopa-admin-log" 2>/dev/null \ || echo "WARN: clone failed (auth/network) — will use existing tree if any" fi # 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 # Units reference %h/koopa-admin-log — prefer git clone or symlink if [ -d "$HOME/src/koopa-admin-log/.git" ] && [ ! -e "$HOME/koopa-admin-log" ]; then ln -sfn "$HOME/src/koopa-admin-log" "$HOME/koopa-admin-log" echo "symlink $HOME/koopa-admin-log → $HOME/src/koopa-admin-log" elif [ ! -e "$HOME/koopa-admin-log" ]; then admin_root=$(cd "$mon/../.." && pwd) ln -sfn "$admin_root" "$HOME/koopa-admin-log" echo "symlink $HOME/koopa-admin-log → $admin_root" fi 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/" install -m 644 "$ROOT/taler-monitoring-aptdeploy.service" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-aptdeploy.timer" "$home_unit/" # Fix ExecStart if install path differs (units use %h/koopa-admin-log) 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 # 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 (hacktivism 4h + surface 1h + aptdeploy 4h)" echo "manual: systemctl --user start taler-monitoring-hacktivism.service" echo "manual surface: systemctl --user start taler-monitoring-surface.service" echo "manual aptdeploy: systemctl --user start taler-monitoring-aptdeploy.service" echo "after upgrades: $ROOT/touch-software-stamp.sh" } if [ -n "$REMOTE" ] && [ "$REMOTE" != "--remote" ]; then echo "install on $REMOTE …" rsync -az --delete \ --exclude secrets.env \ --exclude 'android-test/artifacts' \ "$ROOT/../../" \ "${REMOTE}:src/taler-monitoring/" # ensure full tree for %h/koopa-admin-log if missing configs etc. ssh -o BatchMode=yes -o ConnectTimeout=20 "$REMOTE" \ 'test -d $HOME/koopa-admin-log || git clone https://git.hacktivism.ch/hernani/taler-monitoring.git $HOME/koopa-admin-log 2>/dev/null || true' rsync -az "$ROOT/" "${REMOTE}:src/taler-monitoring/host-agent/" rsync -az "$ROOT/../site-gen/" "${REMOTE}:src/taler-monitoring/site-gen/" 2>/dev/null || true ssh -o BatchMode=yes "$REMOTE" \ 'bash $HOME/src/taler-monitoring/host-agent/install-host-agent.sh' else install_local fi