-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Windows automatic discovery support with WSDD #4491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
3627d20
4929faf
1f73c66
fc9cd1a
91c42c0
851c85b
edd535d
4f0baec
1d27cfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/usr/bin/with-contenv bash | ||
| # vim: ft=bash | ||
| # shellcheck shell=bash | ||
|
|
||
| # Populate the provided array variable with enabled network interfaces. | ||
| get_enabled_interfaces() { | ||
| local -n _out_interfaces=$1 | ||
| local interface | ||
| local interface_enabled | ||
|
|
||
| _out_interfaces=() | ||
| for interface in $(bashio::network.interfaces); do | ||
| interface_enabled=$(bashio::network.enabled "${interface}") | ||
| if bashio::var.true "${interface_enabled}"; then | ||
| _out_interfaces+=("${interface}") | ||
| fi | ||
| done | ||
| } |
| 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 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/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 && "${exit_code_signal}" -eq 15 ]]; then | ||
| if [[ "${exit_code_container}" -eq 0 ]]; then | ||
| echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode | ||
| fi | ||
| exec /run/s6/basedir/bin/halt | ||
| elif [[ "${exit_code_service}" -eq 256 ]]; then | ||
| bashio::log.warning \ | ||
| "Optional service ${service} exited by signal ${exit_code_signal}; continuing without Windows discovery." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this... |
||
| elif [[ "${exit_code_service}" -ne 0 ]]; then | ||
| bashio::log.warning \ | ||
| "Optional service ${service} failed; continuing without Windows discovery." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/command/with-contenv bashio | ||
| # vim: ft=bash | ||
| # shellcheck shell=bash | ||
| # ============================================================================== | ||
| # Start wsdd service | ||
| # ============================================================================== | ||
| declare hostname | ||
| declare workgroup | ||
| declare -a wsdd_interfaces=() | ||
| declare -a interfaces=() | ||
|
|
||
| # shellcheck disable=SC1091 # Sourced from container filesystem path at runtime. | ||
| source /etc/s6-overlay/s6-rc.d/init-smbd/network-interfaces.sh | ||
|
|
||
| # 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') | ||
|
|
||
| get_enabled_interfaces interfaces | ||
|
|
||
| if [ ${#interfaces[@]} -eq 0 ]; then | ||
| bashio::log.warning 'WSDD disabled: no supported interfaces found to bind on.' | ||
| exec tail -f /dev/null | ||
madbrain76 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| # wsdd expects each interface to be preceded by "-i". | ||
| for interface in "${interfaces[@]}"; do | ||
| wsdd_interfaces+=("-i" "${interface}") | ||
| done | ||
|
|
||
| bashio::log.info \ | ||
| "Starting the WSDD daemon on interfaces: $(printf '%s ' "${interfaces[@]}")" \ | ||
| "for ${workgroup}/${hostname}" | ||
|
|
||
| exec wsdd "${wsdd_interfaces[@]}" -n "${hostname}" -w "${workgroup}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| longrun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part feels a bit overengineered to me, but I am fine with it. I mostly meant we should not shutdown the container on regular failure, but what coderabbit suggested was a bit more elaborate 😅