Skip to content
4 changes: 4 additions & 0 deletions samba/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 12.6.2

- Add Windows automatic discovery support with WSDD

## 12.6.1

- Support spaces in configurable username
Expand Down
2 changes: 1 addition & 1 deletion samba/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ENV LANG C.UTF-8

# Setup base
RUN \
apk add --no-cache samba \
apk add --no-cache samba wsdd \
&& mkdir -p /var/lib/samba \
&& touch \
/etc/samba/lmhosts \
Expand Down
2 changes: 1 addition & 1 deletion samba/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: 12.6.1
version: 12.6.2
slug: samba
name: Samba share
description: Expose Home Assistant folders with SMB/CIFS
Expand Down
1 change: 1 addition & 0 deletions samba/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/wsdd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

25 changes: 25 additions & 0 deletions samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Keep the addon running when the optional wsdd service fails
# ==============================================================================
# shellcheck disable=SC2155
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
readonly service="wsdd"

bashio::log.info \
"Service ${service} exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
bashio::log.warning \
"Optional service ${service} failed; continuing without Windows discovery."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and this case s6 will simply restart the service again. If we want it to remain stopped we need to exit the finish script with exit code 125 (permanent failure). And I'd make use of that here, since that is what the warning suggests is what we want to happen.

fi
36 changes: 36 additions & 0 deletions samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Start wsdd service
# ==============================================================================
declare hostname
declare workgroup
declare interface_enabled
declare -a interfaces=()

# Match Samba's advertised server name.
hostname=$(bashio::info.hostname)
if bashio::var.is_empty "${hostname}"; then
bashio::log.warning "Can't read hostname, using default."
hostname="hassio"
fi
workgroup=$(bashio::config 'workgroup')

for interface in $(bashio::network.interfaces); do
interface_enabled=$(bashio::network.enabled "${interface}")
if bashio::var.true "${interface_enabled}"; then
interfaces+=("-i" "${interface}")
fi
done

if [ ${#interfaces[@]} -eq 0 ]; then
bashio::log.warning 'WSDD disabled: no supported interfaces found to bind on.'
exec tail -f /dev/null
fi

bashio::log.info \
"Starting the WSDD daemon on interfaces: $(printf '%s ' "${interfaces[@]}")" \
"for ${workgroup}/${hostname}"

exec wsdd "${interfaces[@]}" -n "${hostname}" -w "${workgroup}"
1 change: 1 addition & 0 deletions samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Loading