#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SKILL_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" source "$SKILL_ROOT/scripts/_common.sh" : "${TUNNEL_NAME:=}" : "${CONFIG_DIR:=$SKILL_ROOT/outputs/config}" main() { confirm_gate [[ -n "$TUNNEL_NAME" ]] || die "TUNNEL_NAME is required." if [[ -f "$CONFIG_DIR/tunnel.json" ]]; then local tunnel_id; tunnel_id="$(jq -r '.id' "$CONFIG_DIR/tunnel.json")" if [[ -n "$tunnel_id" && "$tunnel_id" != "null" ]]; then log_warn "Deleting tunnel via cloudflared: $TUNNEL_NAME ($tunnel_id)" cloudflared tunnel delete -f "$tunnel_id" || cloudflared tunnel delete -f "$TUNNEL_NAME" || true fi else log_warn "No tunnel.json snapshot; attempting delete by name: $TUNNEL_NAME" cloudflared tunnel delete -f "$TUNNEL_NAME" || true fi rm -f "$CONFIG_DIR/tunnel.json" "$CONFIG_DIR/config.yml" || true log_info "Tunnel rollback complete." } main "$@"