#!/usr/bin/env bash # update-suite.sh — latest taler-monitoring from Forgejo (standalone repo root). set -uo pipefail CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/taler-monitoring" ENV_FILE="${TALER_MONITORING_ENV:-$CFG_DIR/env}" if [ -f "$ENV_FILE" ] && [ "${_TALER_MON_ENV_LOADED:-0}" != "1" ]; then set -a; source "$ENV_FILE"; set +a fi SUITE_GIT_URL="${SUITE_GIT_URL:-https://git.hacktivism.ch/hernani/taler-monitoring.git}" SUITE_GIT_REF="${SUITE_GIT_REF:-main}" SUITE_UPDATE_MODE="${SUITE_UPDATE_MODE:-reset}" if [ -z "${SUITE_DIR:-}" ]; then if [ -d "$HOME/src/taler-monitoring/.git" ]; then SUITE_DIR="$HOME/src/taler-monitoring" elif [ -d "$HOME/taler-monitoring/.git" ]; then SUITE_DIR="$HOME/taler-monitoring" else SUITE_DIR="$HOME/src/taler-monitoring"; fi fi export SUITE_DIR mkdir -p "$(dirname "$SUITE_DIR")" "$CFG_DIR" if [ ! -d "$SUITE_DIR/.git" ]; then echo "clone $SUITE_GIT_URL → $SUITE_DIR" git clone --branch "$SUITE_GIT_REF" "$SUITE_GIT_URL" "$SUITE_DIR" || git clone "$SUITE_GIT_URL" "$SUITE_DIR" fi cd "$SUITE_DIR" || exit 1 git remote set-url origin "$SUITE_GIT_URL" 2>/dev/null || true echo "fetch origin ($SUITE_GIT_REF) …" if ! git fetch --tags origin 2>&1; then echo "WARN: git fetch failed — using existing tree" >&2 return 0 2>/dev/null || exit 0 fi case "$SUITE_UPDATE_MODE" in reset) git checkout -B "$SUITE_GIT_REF" "origin/$SUITE_GIT_REF" 2>/dev/null || git checkout -B "$SUITE_GIT_REF" FETCH_HEAD git reset --hard "origin/$SUITE_GIT_REF" 2>/dev/null || git reset --hard FETCH_HEAD ;; *) git pull --ff-only origin "$SUITE_GIT_REF" 2>&1 || true ;; esac COMMIT=$(git rev-parse HEAD) COMMIT_SHORT=$(git rev-parse --short=12 HEAD) SOURCE_REPO_WEB="${SOURCE_REPO_WEB:-https://git.hacktivism.ch/hernani/taler-monitoring}" COMMIT_URL="${SOURCE_REPO_WEB}/src/commit/${COMMIT}" export COMMIT COMMIT_SHORT COMMIT_URL SOURCE_REPO_WEB # Release tag for sticky bar (exact tag if HEAD is tagged, else nearest) SUITE_VERSION="" if command -v git >/dev/null 2>&1; then SUITE_VERSION=$(git describe --tags --exact-match 2>/dev/null || true) if [ -z "$SUITE_VERSION" ]; then SUITE_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || true) fi fi if [ -z "$SUITE_VERSION" ] && [ -f "$SUITE_DIR/VERSION" ]; then SUITE_VERSION="v$(tr -d '[:space:]' <"$SUITE_DIR/VERSION" | sed 's/^v//')" case "$SUITE_VERSION" in v*) ;; *) SUITE_VERSION="v${SUITE_VERSION#v}" ;; esac fi [ -z "$SUITE_VERSION" ] && SUITE_VERSION="unknown" # normalize: ensure leading v for tags case "$SUITE_VERSION" in unknown) ;; v*) ;; *) SUITE_VERSION="v${SUITE_VERSION}" ;; esac SUITE_VERSION_URL="" if [ -n "$SOURCE_REPO_WEB" ] && [ "$SUITE_VERSION" != "unknown" ]; then SUITE_VERSION_URL="${SOURCE_REPO_WEB}/src/tag/${SUITE_VERSION}" fi export SUITE_VERSION SUITE_VERSION_URL echo " version=$SUITE_VERSION ${SUITE_VERSION_URL:+· $SUITE_VERSION_URL}" echo "suite @ $COMMIT_SHORT $COMMIT_URL" echo " dir=$SUITE_DIR" ln -sfn "$SUITE_DIR" "$HOME/taler-monitoring" 2>/dev/null || true chmod +x taler-monitoring.sh check_*.sh host-agent/*.sh site-gen/*.sh site-gen/*.py 2>/dev/null || true