| 1 | #!/bin/bash |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | set -eux -o pipefail |
| 7 | |
| 8 | |
| 9 | if [[ -f /sbin/openrc-run ]]; then |
| 10 | exit 0 |
| 11 | fi |
| 12 | |
| 13 | |
| 14 | command -v systemctl >/dev/null 2>&1 || exit 0 |
| 15 | command -v resolvectl >/dev/null 2>&1 || exit 0 |
| 16 | |
| 17 | |
| 18 | enable_mdns_conf_path=/etc/systemd/resolved.conf.d/00-lima-enable-mdns.conf |
| 19 | enable_mdns_conf_content="[Resolve] |
| 20 | MulticastDNS=yes |
| 21 | " |
| 22 | |
| 23 | if [ "$(echo "${enable_mdns_conf_content}" | sha256sum)" != "$(sha256sum <"${enable_mdns_conf_path}" 2>/dev/null)" ]; then |
| 24 | mkdir -p "$(dirname "${enable_mdns_conf_path}")" |
| 25 | echo "${enable_mdns_conf_content}" >"${enable_mdns_conf_path}" |
| 26 | systemctl daemon-reload |
| 27 | systemctl restart systemd-resolved.service |
| 28 | fi |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | for iface in $(resolvectl status | sed -n -E 's/^Link +[0-9]+ \(([^)]+)\)/\1/p'); do |
| 34 | |
| 35 | resolvectl mdns "${iface}" yes |
| 36 | done |