diff --git a/samba/CHANGELOG.md b/samba/CHANGELOG.md index 3db6c2fbe..b353e61d4 100644 --- a/samba/CHANGELOG.md +++ b/samba/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 12.11.0 + +- Add service discovery using DNS-SD/mDNS controlled by the `network_discovery` configuration option added in 12.9.0. + ## 12.10.0 - Rename the `addons` and `addon_configs` shares to `local_apps` and `app_configs` to match Home Assistant's app terminology. Existing `enabled_shares` configurations are migrated automatically on start (extending the lower-case normalization added in 12.8.1). diff --git a/samba/DOCS.md b/samba/DOCS.md index 80be4ecb8..ae4c9db60 100644 --- a/samba/DOCS.md +++ b/samba/DOCS.md @@ -130,10 +130,9 @@ Defaults to `true`. ### Option: `network_discovery` -Advertise the host on the network using Web Services Dynamic Discovery, so it -appears automatically under Network in Windows File Explorer. Disable this if -you connect to the shares by hostname or IP address and do not want the host -to announce itself on the network. +Advertise the host on the network using DNS-SD/mDNS and WS-Discovery. Disable +this if you connect to the shares by hostname or IP address and do not want the +host to announce itself on the network. Disabling this has no effect on share availability; only on discovery. diff --git a/samba/Dockerfile b/samba/Dockerfile index c7cd5390d..972be419b 100644 --- a/samba/Dockerfile +++ b/samba/Dockerfile @@ -6,7 +6,7 @@ ENV LANG C.UTF-8 # Setup base RUN \ - apk add --no-cache samba wsdd \ + apk add --no-cache samba wsdd glib \ && mkdir -p /var/lib/samba \ && touch \ /etc/samba/lmhosts \ diff --git a/samba/config.yaml b/samba/config.yaml index e80769372..68e95904e 100644 --- a/samba/config.yaml +++ b/samba/config.yaml @@ -1,5 +1,5 @@ --- -version: 12.10.0 +version: 12.11.0 slug: samba name: Samba share description: Expose Home Assistant folders with SMB/CIFS @@ -9,6 +9,7 @@ arch: - amd64 hassio_api: true host_network: true +host_dbus: true image: homeassistant/{arch}-addon-samba init: false map: diff --git a/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish b/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish index 4fb2dc554..b1e23fe7f 100755 --- a/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish +++ b/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish @@ -14,6 +14,17 @@ bashio::log.info \ "Service ${service} exited with code ${exit_code_service}" \ "(by signal ${exit_code_signal})" +if bashio::config.true 'network_discovery'; then +bashio::log.info "Unregistering smb service in mDNS" +app_hostname=$(hostname) +# Fix object path encoding by replacing "-" with "_2d" +gdbus call --system \ + --dest org.freedesktop.resolve1 \ + --object-path /org/freedesktop/resolve1 \ + --method org.freedesktop.resolve1.Manager.UnregisterService \ + "/org/freedesktop/resolve1/dnssd/${app_hostname//-/_2d}" +fi + if [[ "${exit_code_service}" -eq 256 ]]; then # SIGTERM (15) is how s6-overlay brings the service down during a normal # container shutdown; halt the supervision tree but keep the container exit diff --git a/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/run b/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/run index 219d3d4eb..78b99606c 100755 --- a/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/run +++ b/samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/run @@ -4,6 +4,21 @@ # ============================================================================== # Start smbd service # ============================================================================== +if bashio::config.true 'network_discovery'; then +bashio::log.info "Registering smb service in mDNS" +gdbus call --system \ + --dest org.freedesktop.resolve1 \ + --object-path /org/freedesktop/resolve1 \ + --method org.freedesktop.resolve1.Manager.RegisterService \ + "$(hostname)" \ + "%H" \ + "_smb._tcp" \ + 445 \ + 0 \ + 0 \ + [] +fi + exec smbd \ --foreground \ --debug-stdout \ diff --git a/samba/translations/en.yaml b/samba/translations/en.yaml index 1fa6c1e83..4a063211e 100644 --- a/samba/translations/en.yaml +++ b/samba/translations/en.yaml @@ -46,8 +46,7 @@ configuration: network_discovery: name: Enable network discovery description: >- - Advertise the host with Web Services Dynamic Discovery so it appears - automatically under Network in Windows File Explorer. Disable if you + Advertise the host with DNS-SD/mDNS and WS-Discovery. Disable if you connect by hostname or IP address and do not want the host to announce itself on the network. Shares stay reachable either way. server_signing: