40 lines
1.2 KiB
Shell
Executable file
40 lines
1.2 KiB
Shell
Executable file
#!/bin/sh
|
|
# entrypoint.sh — mdns-reflector container entrypoint
|
|
#
|
|
# Runs as root to set up VLAN subinterfaces (if VLAN_IDS is set),
|
|
# then drops privileges to 'mdns' user for the repeater process.
|
|
#
|
|
# For RouterOS: VLAN_IDS="10 20 30" bridges those VLANs.
|
|
# Without VLAN_IDS: bridges all visible non-loopback interfaces.
|
|
|
|
set -e
|
|
|
|
# Auto-detect the container's main interface (the one with the default route)
|
|
MAIN_IFACE=$(ip -o route show default | awk '{print $5}')
|
|
if [ -z "$MAIN_IFACE" ]; then
|
|
MAIN_IFACE=$(ip -o link show up | awk -F': ' '!/lo/{print $2}' | cut -d@ -f1 | head -1)
|
|
fi
|
|
|
|
if [ -n "$VLAN_IDS" ]; then
|
|
echo "[entrypoint] Creating VLAN subinterfaces on $MAIN_IFACE..."
|
|
IFACES=""
|
|
for vid in $VLAN_IDS; do
|
|
iface="${MAIN_IFACE}.${vid}"
|
|
ip link add link "$MAIN_IFACE" name "$iface" type vlan id "$vid"
|
|
ip link set "$iface" up
|
|
IFACES="$IFACES $iface"
|
|
done
|
|
set -- $IFACES
|
|
elif [ -n "$MAIN_IFACE" ]; then
|
|
set -- $(ip -o link show up | awk -F': ' '!/lo/{print $2}' | cut -d@ -f1)
|
|
fi
|
|
|
|
if [ $# -eq 0 ]; then
|
|
echo "ERROR: No interfaces found."
|
|
exit 1
|
|
fi
|
|
|
|
echo "[entrypoint] Starting mdns-repeater on: $*"
|
|
|
|
# Drop privileges before running the repeater
|
|
exec su-exec mdns /usr/local/bin/mdns-repeater "$@"
|