diff --git a/bin/disinto b/bin/disinto index c9f1845..ffc9a26 100755 --- a/bin/disinto +++ b/bin/disinto @@ -1715,11 +1715,8 @@ disinto_edge() { # Write to .env (replace existing entries to avoid duplicates) local tmp_env tmp_env=$(mktemp) - grep -v "^EDGE_TUNNEL_HOST=" "$env_file" > "$tmp_env" 2>/dev/null || true - grep -v "^EDGE_TUNNEL_PORT=" "$env_file" >> "$tmp_env" 2>/dev/null || true - grep -v "^EDGE_TUNNEL_FQDN=" "$env_file" >> "$tmp_env" 2>/dev/null || true - cat "$tmp_env" > "$env_file" - rm -f "$tmp_env" + grep -Ev "^EDGE_TUNNEL_(HOST|PORT|FQDN)=" "$env_file" > "$tmp_env" 2>/dev/null || true + mv "$tmp_env" "$env_file" echo "EDGE_TUNNEL_HOST=${edge_host}" >> "$env_file" echo "EDGE_TUNNEL_PORT=${port}" >> "$env_file" echo "EDGE_TUNNEL_FQDN=${fqdn}" >> "$env_file" @@ -1763,7 +1760,7 @@ disinto_edge() { # SSH to edge host and deregister echo "Deregistering tunnel for ${project} on ${edge_host}..." local response - response=$(ssh -o StrictHostKeyChecking=no -o BatchMode=yes \ + response=$(ssh -o StrictHostKeyChecking=accept-new -o BatchMode=yes \ "disinto-register@${edge_host}" \ "deregister ${project}" 2>&1) || { echo "Error: failed to deregister tunnel" >&2 @@ -1804,7 +1801,7 @@ disinto_edge() { # SSH to edge host and get status echo "Checking tunnel status on ${edge_host}..." local response - response=$(ssh -o StrictHostKeyChecking=no -o BatchMode=yes \ + response=$(ssh -o StrictHostKeyChecking=accept-new -o BatchMode=yes \ "disinto-register@${edge_host}" \ "list" 2>&1) || { echo "Error: failed to get status" >&2 diff --git a/tools/edge-control/install.sh b/tools/edge-control/install.sh index b525d3e..d206e7b 100755 --- a/tools/edge-control/install.sh +++ b/tools/edge-control/install.sh @@ -230,11 +230,8 @@ cat > "$CADDYFILE" < diff --git a/tools/edge-control/lib/caddy.sh b/tools/edge-control/lib/caddy.sh index 92bc01e..0bfe307 100755 --- a/tools/edge-control/lib/caddy.sh +++ b/tools/edge-control/lib/caddy.sh @@ -85,18 +85,11 @@ remove_route() { return 1 } - # Find the route index that matches our fqdn - local route_index=-1 - local idx=0 - while IFS= read -r host; do - if [ "$host" = "$fqdn" ]; then - route_index=$idx - break - fi - idx=$((idx + 1)) - done < <(echo "$routes_json" | jq -r '.[].match[].host[]' 2>/dev/null) + # Find the route index that matches our fqdn using jq + local route_index + route_index=$(echo "$routes_json" | jq -r "to_entries[] | select(.value.match[]?.host[]? == \"${fqdn}\") | .key" 2>/dev/null | head -1) - if [ "$route_index" -lt 0 ]; then + if [ -z "$route_index" ] || [ "$route_index" = "null" ]; then echo "Warning: route for ${fqdn} not found" >&2 return 0 fi diff --git a/tools/edge-control/register.sh b/tools/edge-control/register.sh index 3bd3c8c..75624ee 100755 --- a/tools/edge-control/register.sh +++ b/tools/edge-control/register.sh @@ -20,6 +20,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Source libraries source "${SCRIPT_DIR}/lib/ports.sh" source "${SCRIPT_DIR}/lib/caddy.sh" +source "${SCRIPT_DIR}/lib/authorized_keys.sh" # Domain suffix DOMAIN_SUFFIX="${DOMAIN_SUFFIX:-disinto.ai}" @@ -77,7 +78,7 @@ do_register() { add_route "$project" "$port" # Rebuild authorized_keys for tunnel user - "${SCRIPT_DIR}/lib/authorized_keys.sh" rebuild_authorized_keys + rebuild_authorized_keys # Reload Caddy reload_caddy @@ -107,7 +108,7 @@ do_deregister() { remove_route "$project" # Rebuild authorized_keys for tunnel user - "${SCRIPT_DIR}/lib/authorized_keys.sh" rebuild_authorized_keys + rebuild_authorized_keys # Reload Caddy reload_caddy