samba: 9.4.0 (Alpine 3.13 + tempio) (#2023)

* Upgrade Alpine Linux to 3.13

* Rewrite Samba configuration using tempio

* Update changelog and bump version to 9.4.0
This commit is contained in:
Franck Nijhof
2021-05-20 23:02:40 +02:00
committed by GitHub
parent 669782f13c
commit 25241ac15b
6 changed files with 117 additions and 131 deletions

View File

@@ -1,5 +1,10 @@
# Changelog # Changelog
## 9.4.0
- Upgrade Alpine Linux to 3.13
- Rewrite configuration generation code
## 9.3.1 ## 9.3.1
- Update options schema for passwords - Update options schema for passwords

View File

@@ -1,9 +1,9 @@
{ {
"build_from": { "build_from": {
"aarch64": "homeassistant/aarch64-base:3.12", "aarch64": "ghcr.io/home-assistant/aarch64-base:3.13",
"amd64": "homeassistant/amd64-base:3.12", "amd64": "ghcr.io/home-assistant/amd64-base:3.13",
"armhf": "homeassistant/armhf-base:3.12", "armhf": "ghcr.io/home-assistant/armhf-base:3.13",
"armv7": "homeassistant/armv7-base:3.12", "armv7": "ghcr.io/home-assistant/armv7-base:3.13",
"i386": "homeassistant/i386-base:3.12" "i386": "ghcr.io/home-assistant/i386-base:3.13"
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "Samba share", "name": "Samba share",
"version": "9.3.1", "version": "9.4.0",
"slug": "samba", "slug": "samba",
"description": "Expose Home Assistant folders with SMB/CIFS", "description": "Expose Home Assistant folders with SMB/CIFS",
"url": "https://github.com/home-assistant/hassio-addons/tree/master/samba", "url": "https://github.com/home-assistant/hassio-addons/tree/master/samba",
@@ -8,7 +8,14 @@
"startup": "services", "startup": "services",
"init": false, "init": false,
"host_network": true, "host_network": true,
"map": ["config:rw", "ssl:rw", "addons:rw", "share:rw", "backup:rw", "media:rw"], "map": [
"config:rw",
"ssl:rw",
"addons:rw",
"share:rw",
"backup:rw",
"media:rw"
],
"options": { "options": {
"workgroup": "WORKGROUP", "workgroup": "WORKGROUP",
"username": "homeassistant", "username": "homeassistant",

View File

@@ -2,64 +2,34 @@
# ============================================================================== # ==============================================================================
# Prepare the Samba service for running # Prepare the Samba service for running
# ============================================================================== # ==============================================================================
readonly CONF="/etc/samba/smb.conf"
declare allow_hosts
declare compatibility_mode
declare delete_veto_files
declare name
declare password declare password
declare username declare username
declare veto_files export HOSTNAME
# Check Login data # Check Login data
if ! bashio::config.has_value 'username' || ! bashio::config.has_value 'password'; then if ! bashio::config.has_value 'username' || ! bashio::config.has_value 'password'; then
bashio::exit.nok "Setting a username and password is required!" bashio::exit.nok "Setting a username and password is required!"
fi 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" # Read hostname from API or setting default "hassio"
name=$(bashio::info.hostname) HOSTNAME=$(bashio::info.hostname)
if bashio::var.is_empty "${name}"; then if bashio::var.is_empty "${HOSTNAME}"; then
bashio::log.warning "Can't read hostname, using default." bashio::log.warning "Can't read hostname, using default."
name="hassio" HOSTNAME="hassio"
fi fi
bashio::log.info "Hostname: ${name}" bashio::log.info "Hostname: ${HOSTNAME}"
sed -i "s|%%NAME%%|${name}|g" "${CONF}"
# Allowed hosts # Generate Samba configuration.
allow_hosts=$(bashio::config "allow_hosts | join(\" \")") tempio \
sed -i "s#%%ALLOW_HOSTS%%#${allow_hosts}#g" "${CONF}" -conf /data/options.json \
-template /usr/share/tempio/smb.gtpl \
# Compatibility mode, enables the use of the legacy SMB1 protocol -out /etc/samba/smb.conf
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 # Init user
username=$(bashio::config 'username') username=$(bashio::config 'username')
password=$(bashio::config 'password') password=$(bashio::config 'password')
addgroup "${username}" addgroup "${username}"
adduser -D -H -G "${username}" -s /bin/false "${username}" adduser -D -H -G "${username}" -s /bin/false "${username}"
sed -i "s|%%USERNAME%%|${username}|g" "${CONF}"
# shellcheck disable=SC1117 # shellcheck disable=SC1117
echo -e "${password}\n${password}" \ echo -e "${password}\n${password}" \
| smbpasswd -a -s -c "${CONF}" "${username}" | smbpasswd -a -s -c "/etc/samba/smb.conf" "${username}"

View File

@@ -1,83 +0,0 @@
[global]
netbios name = %%NAME%%
workgroup = %%WORKGROUP%%
server string = Samba Home Assistant
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%%
[media]
browseable = yes
writeable = yes
path = /media
valid users = %%USERNAME%%
force user = root
force group = root
veto files = %%VETO_FILES%%
delete veto files = %%DELETE_VETO_FILES%%

View File

@@ -0,0 +1,87 @@
[global]
netbios name = {{ env "HOSTNAME" }}
workgroup = {{ .workgroup }}
server string = Samba Home Assistant
security = user
ntlm auth = yes
load printers = no
disable spoolss = yes
log level = 2
bind interfaces only = yes
interfaces = {{ .interface }}
hosts allow = {{ .allow_hosts | join " " }}
{{ if .compatibility_mode }}
client min protocol = NT1
server min protocol = NT1
{{ end }}
[config]
browseable = yes
writeable = yes
path = /config
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" }}
[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" }}
[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" }}
[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" }}
[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" }}
[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" }}