38 lines
1.5 KiB
Bash
Executable file
38 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ======== CONFIGURE THESE ========
|
|
MONGO_CONT="chat-mongodb" # Docker container name/ID for MongoDB
|
|
DB_NAME="LibreChat" # MongoDB database name
|
|
EXPORT_JS="/opt/agent-sync/export_shared_agents.js"
|
|
OUT_JSON="/opt/agent-sync/shared_agents.json"
|
|
PY_SCRIPT="/opt/agent-sync/register_agents.py"
|
|
|
|
# Path to the Python executable inside your EXISTING venv
|
|
VENV_PY="/opt/agent-sync/venv/bin/python"
|
|
|
|
# Optional log file; set to /dev/null to disable
|
|
LOG_FILE="/opt/agent-sync/log/agent_sync.log"
|
|
# =================================
|
|
|
|
timestamp() { date -Is; }
|
|
|
|
# quick sanity checks
|
|
[[ -x "$VENV_PY" ]] || { echo "[$(timestamp)] ERROR: venv python not found at $VENV_PY"; exit 1; }
|
|
command -v docker >/dev/null 2>&1 || { echo "[$(timestamp)] ERROR: docker not found"; exit 1; }
|
|
|
|
echo "[$(timestamp)] Starting weekly agent sync" >> "$LOG_FILE"
|
|
|
|
# 1) Export from Mongo (valid JSON to host file)
|
|
docker exec -i "$MONGO_CONT" env MONGOSH_NO_RC=1 mongosh --norc --quiet "$DB_NAME" --file /dev/stdin < "$EXPORT_JS" > "$OUT_JSON"
|
|
|
|
|
|
# 2) (Optional) sanity-check JSON if jq is present
|
|
if command -v jq >/dev/null 2>&1; then
|
|
jq -e . "$OUT_JSON" >/dev/null 2>&1 || { echo "[$(timestamp)] ERROR: Output is not valid JSON: $OUT_JSON" >> "$LOG_FILE"; exit 1; }
|
|
fi
|
|
|
|
# 3) Register with the API using your existing venv
|
|
"$VENV_PY" "$PY_SCRIPT" --input "$OUT_JSON" >> "$LOG_FILE" 2>&1
|
|
|
|
echo "[$(timestamp)] Done" >> "$LOG_FILE"
|