#!/usr/bin/env bash set -euo pipefail REPO_URL=${1:-} BRANCH=${2:-main} REPO_DIR=${3:-.} COMPOSE_FILE=${4:-docker-compose.yml} BASE_URL=${5:-http://localhost:57778} ADMIN_TOKEN=${6:-} mkdir -p "$REPO_DIR" if [ ! -d "$REPO_DIR/.git" ]; then [ -z "$REPO_URL" ] && { echo "RepoUrl required"; exit 1; } git clone -b "$BRANCH" "$REPO_URL" "$REPO_DIR" fi cd "$REPO_DIR" git remote set-url origin "$REPO_URL" git fetch origin git checkout "$BRANCH" git pull origin "$BRANCH" [ -f "$COMPOSE_FILE" ] || { echo "compose not found: $COMPOSE_FILE"; exit 1; } docker compose -f "$COMPOSE_FILE" up -d --build HDR=( ) if [ -n "$ADMIN_TOKEN" ]; then HDR=( -H "X-Admin-Token: $ADMIN_TOKEN" ); fi curl -s -X POST "${BASE_URL}/api/admin/reload_cutoff" "${HDR[@]}" || true curl -s "${BASE_URL}/api/metrics" || true curl -s -X POST "${BASE_URL}/api/admin/test_push" "${HDR[@]}" || true