add samba with old data

This commit is contained in:
ai-dev
2025-10-10 16:11:46 +02:00
parent e96148e311
commit d6a16358ff
25 changed files with 696 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Prepare the Samba service for running
# ==============================================================================
declare password
declare username
declare -a interfaces=()
export HOSTNAME
# Check Login data
if ! bashio::config.has_value 'username' || ! bashio::config.has_value 'password'; then
bashio::exit.nok "Setting a username and password is required!"
fi
bashio::config.require "enabled_shares" "Samba is a tool for sharing folders. Starting it without sharing any folders defeats the purpose."
# Read hostname from API or setting default "hassio"
HOSTNAME=$(bashio::info.hostname)
if bashio::var.is_empty "${HOSTNAME}"; then
bashio::log.warning "Can't read hostname, using default."
HOSTNAME="hassio"
fi
bashio::log.info "Hostname: ${HOSTNAME}"
# Get supported interfaces
for interface in $(bashio::network.interfaces); do
interface_enabled=$(bashio::network.enabled "${interface}")
if bashio::var.true "${interface_enabled}"; then
interfaces+=("${interface}")
fi
done
if [ ${#interfaces[@]} -eq 0 ]; then
bashio::exit.nok 'No supported interfaces found to bind on.'
fi
bashio::log.info "Interfaces: $(printf '%s ' "${interfaces[@]}")"
# Generate Samba configuration.
jq ".interfaces = $(jq -c -n '$ARGS.positional' --args -- "${interfaces[@]}") |
.enabled_shares.[] |= ascii_downcase" /data/options.json \
| tempio \
-template /usr/share/tempio/smb.gtpl \
-out /etc/samba/smb.conf
# Init user
username=$(bashio::config 'username')
password=$(bashio::config 'password')
addgroup "${username}"
adduser -D -H -G "${username}" -s /bin/false "${username}"
(echo "$password"; echo "$password") \
| smbpasswd -a -s -c "/etc/samba/smb.conf" "${username}"

View File

@@ -0,0 +1 @@
oneshot

View File

@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-smbd/run

View File

@@ -0,0 +1,27 @@
#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Take down the S6 supervision tree when nmbd 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="nmbd"
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
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
exec /run/s6/basedir/bin/halt
fi

View File

@@ -0,0 +1,10 @@
#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Start nmbd service
# ==============================================================================
exec nmbd \
--foreground \
--debug-stdout \
--no-process-group

View File

@@ -0,0 +1 @@
longrun

View File

@@ -0,0 +1,27 @@
#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Take down the S6 supervision tree when smbd 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="smbd"
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
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
exec /run/s6/basedir/bin/halt
fi

View File

@@ -0,0 +1,10 @@
#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Start smbd service
# ==============================================================================
exec smbd \
--foreground \
--debug-stdout \
--no-process-group

View File

@@ -0,0 +1 @@
longrun

View File

@@ -0,0 +1,136 @@
[global]
netbios name = {{ env "HOSTNAME" }}
workgroup = {{ .workgroup }}
server string = Samba Home Assistant
local master = {{ .local_master | ternary "yes" "no" }}
security = user
ntlm auth = yes
idmap config * : backend = tdb
idmap config * : range = 1000000-2000000
load printers = no
disable spoolss = yes
log level = 1
bind interfaces only = yes
interfaces = lo {{ .interfaces | join " " }}
hosts allow = 127.0.0.1 {{ .allow_hosts | join " " }}
{{ if .compatibility_mode }}
client min protocol = NT1
server min protocol = NT1
{{ end }}
mangled names = no
dos charset = CP850
unix charset = UTF-8
{{ if .apple_compatibility_mode }}
vfs objects = catia fruit streams_xattr
{{ end }}
{{ if (has "config" .enabled_shares) }}
[config]
browseable = yes
writeable = yes
path = /homeassistant
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}
{{ if (has "addons" .enabled_shares) }}
[addons]
browseable = yes
writeable = yes
path = /addons
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}
{{ if (has "addon_configs" .enabled_shares) }}
[addon_configs]
browseable = yes
writeable = yes
path = /addon_configs
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}
{{ if (has "ssl" .enabled_shares) }}
[ssl]
browseable = yes
writeable = yes
path = /ssl
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}
{{ if (has "share" .enabled_shares) }}
[share]
browseable = yes
writeable = yes
path = /share
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}
{{ if (has "backup" .enabled_shares) }}
[backup]
browseable = yes
writeable = yes
path = /backup
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}
{{ if (has "media" .enabled_shares) }}
[media]
browseable = yes
writeable = yes
path = /media
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}
{{ if (has "old_data" .enabled_shares) }}
[old_data]
browseable = yes
writeable = yes
path = /old_data
valid users = {{ .username }}
force user = root
force group = root
veto files = /{{ .veto_files | join "/" }}/
delete veto files = {{ eq (len .veto_files) 0 | ternary "no" "yes" }}
{{ end }}