#!/usr/bin/env bash # update-suite.sh — ensure taler-monitoring code is latest from Forgejo. # # Local config (NEVER overwritten by git): # ${XDG_CONFIG_HOME:-$HOME/.config}/taler-monitoring/env # # Env overrides (also settable in that file): # SUITE_GIT_URL default https://git.hacktivism.ch/hernani/koopa-admin-log.git # SUITE_GIT_REF default main # SUITE_DIR default $HOME/src/koopa-admin-log (or $HOME/koopa-admin-log) # SUITE_UPDATE_MODE ff (default) | reset (reset = hard to origin/REF) # set -uo pipefail CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/taler-monitoring" ENV_FILE="${TALER_MONITORING_ENV:-$CFG_DIR/env}" # When sourced from run-host-report.sh the env file is already loaded and # wrapper PHASES/HTML_* must not be clobbered. Only load here if needed. if [ -f "$ENV_FILE" ] && [ "${_TALER_MON_ENV_LOADED:-0}" != "1" ]; then # shellcheck disable=SC1090 set -a # shellcheck source=/dev/null source "$ENV_FILE" set +a fi SUITE_GIT_URL="${SUITE_GIT_URL:-https://git.hacktivism.ch/hernani/koopa-admin-log.git}" SUITE_GIT_REF="${SUITE_GIT_REF:-main}" # Host agents default to reset so "always latest from Forgejo" wins over local # diverged trees. Override with SUITE_UPDATE_MODE=ff for careful pulls. SUITE_UPDATE_MODE="${SUITE_UPDATE_MODE:-reset}" if [ -z "${SUITE_DIR:-}" ]; then if [ -d "$HOME/src/koopa-admin-log/.git" ]; then SUITE_DIR="$HOME/src/koopa-admin-log" elif [ -d "$HOME/koopa-admin-log/.git" ]; then SUITE_DIR="$HOME/koopa-admin-log" else SUITE_DIR="$HOME/src/koopa-admin-log" 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 \ || git remote add 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 at $SUITE_DIR" >&2 git rev-parse HEAD 2>/dev/null || true 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 checkout "$SUITE_GIT_REF" 2>/dev/null || git checkout -B "$SUITE_GIT_REF" "origin/$SUITE_GIT_REF" 2>/dev/null || true if ! git pull --ff-only origin "$SUITE_GIT_REF" 2>&1; then echo "WARN: ff-only pull failed — try SUITE_UPDATE_MODE=reset or fix local commits" >&2 fi ;; esac COMMIT=$(git rev-parse HEAD) COMMIT_SHORT=$(git rev-parse --short=12 HEAD) # Forgejo web UI SOURCE_REPO_WEB="${SOURCE_REPO_WEB:-https://git.hacktivism.ch/hernani/koopa-admin-log}" COMMIT_URL="${SOURCE_REPO_WEB}/src/commit/${COMMIT}" export COMMIT COMMIT_SHORT COMMIT_URL SOURCE_REPO_WEB echo "suite @ $COMMIT_SHORT $COMMIT_URL" echo " dir=$SUITE_DIR" echo " config=$ENV_FILE (not touched by git)" echo " note: always latest = origin/${SUITE_GIT_REF} on git.hacktivism.ch (push local work there)" # Symlink convenience path if missing or not a git clone if [ -d "$SUITE_DIR/.git" ]; then if [ ! -e "$HOME/koopa-admin-log" ]; then ln -sfn "$SUITE_DIR" "$HOME/koopa-admin-log" 2>/dev/null || true elif [ -L "$HOME/koopa-admin-log" ]; then ln -sfn "$SUITE_DIR" "$HOME/koopa-admin-log" 2>/dev/null || true fi fi # Make suite scripts executable after reset if [ -d "$SUITE_DIR/scripts/taler-monitoring" ]; then chmod +x \ "$SUITE_DIR"/scripts/taler-monitoring/taler-monitoring.sh \ "$SUITE_DIR"/scripts/taler-monitoring/check_*.sh \ "$SUITE_DIR"/scripts/taler-monitoring/host-agent/*.sh \ "$SUITE_DIR"/scripts/taler-monitoring/site-gen/*.sh \ "$SUITE_DIR"/scripts/taler-monitoring/site-gen/*.py \ 2>/dev/null || true fi