#!/bin/bash
# Called after jarvis-tunnel starts to patch brain.html with current HTTPS URL
sleep 10
URL=$(grep -o 'https://[a-z0-9-]*\.trycloudflare\.com' /var/log/jarvis-tunnel.log | tail -1)
if [ -n "$URL" ]; then
  sed -i "s|const PROXY = '.*'|const PROXY = '$URL'|" /opt/jarvis-canvas/brain.html
  echo "$(date): Updated PROXY to $URL" >> /var/log/jarvis-tunnel.log
fi
