#!/bin/sh set -eu HOST="elias.reynafamily.com" ROUTE_JSON="/home/adolforeyna/elias-caddy-route.json" API="http://127.0.0.1:2019/config/apps/http/servers/srv2/routes" INDEX=$(curl -fsS "$API" | python3 -c ' import json, sys host = sys.argv[1] routes = json.load(sys.stdin) for index, route in enumerate(routes): if any(host in match.get("host", []) for match in route.get("match", [])): print(index) break ' "$HOST") if [ -n "$INDEX" ]; then curl -fsS -X DELETE "$API/$INDEX" fi curl -fsS -X POST -H "Content-Type: application/json" --data-binary "@$ROUTE_JSON" "$API"