#!/bin/bash

# Script to advertise the local device via mDNS for an HTTPS service.
# This allows other clients on the network to discover this device
# using its mDNS hostname (e.g., your-hostname.local) on the specified port.

# Update: Advertise HTTPS service on port 443 (default)
SERVICE_NAME="Auracast HTTPS Service"   # You can customize this name
SERVICE_TYPE="_https._tcp"              # Standard type for HTTPS services
SERVICE_PORT="443"                      # Port must match your HTTPS server (default 443)

echo "Starting mDNS advertisement..."
echo "Command: avahi-publish-service -v \"$SERVICE_NAME\" \"$SERVICE_TYPE\" \"$SERVICE_PORT\""

avahi-publish-service -v "$SERVICE_NAME" "$SERVICE_TYPE" "$SERVICE_PORT"
EXIT_STATUS=$?

# This part will be reached if avahi-publish-service exits.
if [ $EXIT_STATUS -eq 0 ]; then
    echo "mDNS advertisement command finished with status 0."
    echo "This might indicate an issue connecting to the avahi-daemon or a configuration problem."
    echo "Please check for any messages above from avahi-publish-service itself."
else
    echo "mDNS advertisement command exited with status $EXIT_STATUS."
    echo "This might be due to an error, or if you pressed Ctrl+C (which typically results in a non-zero status from signal termination)."
fi
