samba add-on with option to set the ports
This commit is contained in:
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Prepare the Samba service for running
|
||||
# ==============================================================================
|
||||
readonly CONF="/etc/samba/smb.conf"
|
||||
declare port1
|
||||
declare port2
|
||||
declare allow_hosts
|
||||
declare compatibility_mode
|
||||
declare delete_veto_files
|
||||
declare name
|
||||
declare password
|
||||
declare username
|
||||
declare veto_files
|
||||
|
||||
# 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
|
||||
|
||||
# Workgroup and interface
|
||||
sed -i "s|%%WORKGROUP%%|$(bashio::config 'workgroup')|g" "${CONF}"
|
||||
sed -i "s|%%INTERFACE%%|$(bashio::config 'interface')|g" "${CONF}"
|
||||
|
||||
# Veto files
|
||||
veto_files=""
|
||||
delete_veto_files="no"
|
||||
if bashio::config.has_value 'veto_files'; then
|
||||
veto_files=$(bashio::config "veto_files | join(\"/\")")
|
||||
veto_files="/${veto_files}/"
|
||||
delete_veto_files="yes"
|
||||
fi
|
||||
sed -i "s|%%VETO_FILES%%|${veto_files}|g" "${CONF}"
|
||||
sed -i "s|%%DELETE_VETO_FILES%%|${delete_veto_files}|g" "${CONF}"
|
||||
|
||||
# Read hostname from API or setting default "hassio"
|
||||
name=$(bashio::info.hostname)
|
||||
if bashio::var.is_empty "${name}"; then
|
||||
bashio::log.warning "Can't read hostname, using default."
|
||||
name="hassio"
|
||||
fi
|
||||
bashio::log.info "Hostname: ${name}"
|
||||
sed -i "s|%%NAME%%|${name}|g" "${CONF}"
|
||||
|
||||
# ports
|
||||
port1=$(bashio::config 'port1')
|
||||
port2=$(bashio::config 'port2')
|
||||
sed -i "s|%%PORT1%%|${port1}|g" "${CONF}"
|
||||
sed -i "s|%%PORT2%%|${port2}|g" "${CONF}"
|
||||
|
||||
# Allowed hosts
|
||||
allow_hosts=$(bashio::config "allow_hosts | join(\" \")")
|
||||
sed -i "s#%%ALLOW_HOSTS%%#${allow_hosts}#g" "${CONF}"
|
||||
|
||||
# Compatibility mode, enables the use of the legacy SMB1 protocol
|
||||
compatibility_mode=""
|
||||
if bashio::config.true "compatibility_mode"; then
|
||||
compatibility_mode+=" client min protocol = NT1\n"
|
||||
compatibility_mode+=" server min protocol = NT1\n"
|
||||
fi
|
||||
sed -i "s#%%COMPATIBILITY_MODE%%#${compatibility_mode}#g" "${CONF}"
|
||||
|
||||
# Init user
|
||||
username=$(bashio::config 'username')
|
||||
password=$(bashio::config 'password')
|
||||
|
||||
addgroup "${username}"
|
||||
adduser -D -H -G "${username}" -s /bin/false "${username}"
|
||||
|
||||
sed -i "s|%%USERNAME%%|${username}|g" "${CONF}"
|
||||
# shellcheck disable=SC1117
|
||||
echo -e "${password}\n${password}" \
|
||||
| smbpasswd -a -s -c "${CONF}" "${username}"
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
[global]
|
||||
netbios name = %%NAME%%
|
||||
workgroup = %%WORKGROUP%%
|
||||
server string = Samba Home Assistant
|
||||
|
||||
smb ports = %%PORT1%% %%PORT2%%
|
||||
|
||||
security = user
|
||||
ntlm auth = yes
|
||||
|
||||
load printers = no
|
||||
disable spoolss = yes
|
||||
|
||||
log level = 2
|
||||
|
||||
bind interfaces only = yes
|
||||
interfaces = %%INTERFACE%%
|
||||
hosts allow = %%ALLOW_HOSTS%%
|
||||
|
||||
%%COMPATIBILITY_MODE%%
|
||||
[config]
|
||||
browseable = yes
|
||||
writeable = yes
|
||||
path = /config
|
||||
|
||||
valid users = %%USERNAME%%
|
||||
force user = root
|
||||
force group = root
|
||||
veto files = %%VETO_FILES%%
|
||||
delete veto files = %%DELETE_VETO_FILES%%
|
||||
|
||||
[addons]
|
||||
browseable = yes
|
||||
writeable = yes
|
||||
path = /addons
|
||||
|
||||
valid users = %%USERNAME%%
|
||||
force user = root
|
||||
force group = root
|
||||
veto files = %%VETO_FILES%%
|
||||
delete veto files = %%DELETE_VETO_FILES%%
|
||||
|
||||
[ssl]
|
||||
browseable = yes
|
||||
writeable = yes
|
||||
path = /ssl
|
||||
|
||||
valid users = %%USERNAME%%
|
||||
force user = root
|
||||
force group = root
|
||||
veto files = %%VETO_FILES%%
|
||||
delete veto files = %%DELETE_VETO_FILES%%
|
||||
|
||||
[share]
|
||||
browseable = yes
|
||||
writeable = yes
|
||||
path = /share
|
||||
|
||||
valid users = %%USERNAME%%
|
||||
force user = root
|
||||
force group = root
|
||||
veto files = %%VETO_FILES%%
|
||||
delete veto files = %%DELETE_VETO_FILES%%
|
||||
|
||||
[backup]
|
||||
browseable = yes
|
||||
writeable = yes
|
||||
path = /backup
|
||||
|
||||
valid users = %%USERNAME%%
|
||||
force user = root
|
||||
force group = root
|
||||
veto files = %%VETO_FILES%%
|
||||
delete veto files = %%DELETE_VETO_FILES%%
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/execlineb -S1
|
||||
# ==============================================================================
|
||||
# Take down the S6 supervision tree based on service exit code
|
||||
# ==============================================================================
|
||||
if { s6-test ${1} -ne 0 }
|
||||
if { s6-test ${1} -ne 256 }
|
||||
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Start nmbd service
|
||||
# ==============================================================================
|
||||
exec nmbd \
|
||||
--foreground \
|
||||
--log-stdout \
|
||||
--no-process-group
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/execlineb -S1
|
||||
# ==============================================================================
|
||||
# Take down the S6 supervision tree based on service exit code
|
||||
# ==============================================================================
|
||||
if { s6-test ${1} -ne 0 }
|
||||
if { s6-test ${1} -ne 256 }
|
||||
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Start smbd service
|
||||
# ==============================================================================
|
||||
exec smbd \
|
||||
--foreground \
|
||||
--log-stdout \
|
||||
--no-process-group
|
||||
Reference in New Issue
Block a user