diff --git a/samba/CHANGELOG.md b/samba/CHANGELOG.md new file mode 100755 index 0000000..63dbca4 --- /dev/null +++ b/samba/CHANGELOG.md @@ -0,0 +1,35 @@ +# Changelog + +## 9.2.0 + +- Pin base image version +- Rewrite add-on onto S6 Overlay +- Use default configuration location +- Add support for running in compatibility mode (SMB1/NT1) +- Add dummy files to reduce number of errors/warnings in log output + +## 9.1.0 + +- Allow IPv6 link-local hosts by default, consistent with IPv4 + +## 9.0.0 + +- New option `veto_files` to limit writing of specified files to the share + +## 8.3.0 + +- Fixes a bug in warning log message, causing start failure +- Minor code cleanups + +## 8.2.0 + +- Update from bash to bashio + +## 8.1.0 + +- Update Samba to version 4.8.8 + +## 8.0.0 + +- Fix access to /backup + diff --git a/samba/DOCS.md b/samba/DOCS.md new file mode 100755 index 0000000..4f7af69 --- /dev/null +++ b/samba/DOCS.md @@ -0,0 +1,102 @@ +# Home Assistant Add-on: Samba share + +## Installation + +Follow these steps to get the add-on installed on your system: + +1. Navigate in your Home Assistant frontend to **Supervisor** -> **Add-on Store**. +2. Find the "Samba share" add-on and click it. +3. Click on the "INSTALL" button. + +## How to use + +1. In the configuration section, set a username and password. +2. Save the configuration. +3. Start the add-on. +4. Check the add-on log output to see the result. + +## Configuration + +Add-on configuration: + +```yaml +workgroup: WORKGROUP +port1: 445 +port2: 139 +username: homeassistant +password: YOUR_PASSWORD +interface: '' +allow_hosts: + - 10.0.0.0/8 + - 172.16.0.0/12 + - 192.168.0.0/16 + - fe80::/10 +veto_files: + - "._*" + - ".DS_Store" + - Thumbs.db +compatibility_mode: false +``` + +### Option: `workgroup` (required) + +Change WORKGROUP to reflect your network needs. + +### Option: `port1` (required) + +Change PORT1 to reflect your network needs. + +### Option: `port2` (required) + +Change PORT2 to reflect your network needs. + +### Option: `username` (required) + +The username you would like to use to authenticate with the Samba server. + +### Option: `password` (required) + +The password that goes with the username configured for authentication. + +### Option: `interface` (required) + +The network interface Samba should listen on for incoming connections. +This option should only be used in advanced cases. In general, setting this +option is not needed. + +### Option: `allow_hosts` (required) + +List of hosts/networks allowed to access the shared folders. + +### Option: `veto_files` (optional) + +List of files that are neither visible nor accessible. Useful to stop clients +from littering the share with temporary hidden files +(e.g., macOS `.DS_Store` or Windows `Thumbs.db` files) + +### Option: `compatibility_mode` + +Setting this option to `true` will enable old legacy Samba protocols +on the Samba add-on. This might solve issues with some clients that cannot +handle the newer protocols, however, it lowers security. Only use this +when you absolutely need it and understand the possible consequences. + +Defaults to `false`. + +## Support + +Got questions? + +You have several options to get them answered: + +- The [Home Assistant Discord Chat Server][discord]. +- The Home Assistant [Community Forum][forum]. +- Join the [Reddit subreddit][reddit] in [/r/homeassistant][reddit] + +In case you've found a bug, please [open an issue on our GitHub][issue]. + +[discord]: https://discord.gg/c5DvZ4e +[forum]: https://community.home-assistant.io +[issue]: https://github.com/home-assistant/hassio-addons/issues +[reddit]: https://reddit.com/r/homeassistant +[repository]: https://github.com/hassio-addons/repository diff --git a/samba/Dockerfile b/samba/Dockerfile new file mode 100755 index 0000000..5dede8a --- /dev/null +++ b/samba/Dockerfile @@ -0,0 +1,21 @@ +ARG BUILD_FROM +FROM $BUILD_FROM + +# Add env +ENV LANG C.UTF-8 + +# Setup base +RUN \ + apk add --no-cache \ + samba-common-tools \ + samba-server \ + \ + && mkdir -p /var/lib/samba \ + && touch \ + /etc/samba/lmhosts \ + /var/lib/samba/account_policy.tdb \ + /var/lib/samba/registry.tdb \ + /var/lib/samba/winbindd_idmap.tdb + +# Copy data +COPY rootfs / diff --git a/samba/README.md b/samba/README.md new file mode 100755 index 0000000..d9b07ba --- /dev/null +++ b/samba/README.md @@ -0,0 +1,16 @@ +# Home Assistant Add-on: Samba share + +Share your configuration over the network using Windows file sharing. + +![Supports aarch64 Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield] ![Supports i386 Architecture][i386-shield] + +## About + +This Add-on allows you to enable file sharing across different operating systems over a network. +It lets you access your config files with Windows and macOS devices. + +[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg +[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg +[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg +[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg +[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg diff --git a/samba/azure-pipelines.yml b/samba/azure-pipelines.yml new file mode 100755 index 0000000..c00234a --- /dev/null +++ b/samba/azure-pipelines.yml @@ -0,0 +1,24 @@ +# https://dev.azure.com/home-assistant + +trigger: + branches: + include: + - master + paths: + include: + - samba/* +pr: none +resources: + repositories: + - repository: azure + type: github + name: "home-assistant/ci-azure" + endpoint: "home-assistant" + +variables: + - group: docker + +jobs: + - template: templates/azp-job-addon.yaml@azure + parameters: + addon: "samba" diff --git a/samba/build.json b/samba/build.json new file mode 100755 index 0000000..460c6cd --- /dev/null +++ b/samba/build.json @@ -0,0 +1,9 @@ +{ + "build_from": { + "aarch64": "homeassistant/aarch64-base:3.11", + "amd64": "homeassistant/amd64-base:3.11", + "armhf": "homeassistant/armhf-base:3.11", + "armv7": "homeassistant/armv7-base:3.11", + "i386": "homeassistant/i386-base:3.11" + } +} diff --git a/samba/config.json b/samba/config.json new file mode 100755 index 0000000..4589e21 --- /dev/null +++ b/samba/config.json @@ -0,0 +1,41 @@ +{ + "name": "Samba share", + "version": "9.2.0", + "slug": "samba", + "description": "Expose Home Assistant folders with SMB/CIFS", + "url": "https://github.com/home-assistant/hassio-addons/tree/master/samba", + "arch": ["armhf", "armv7", "aarch64", "amd64", "i386"], + "startup": "services", + "boot": "auto", + "init": false, + "host_network": true, + "map": ["config:rw", "ssl:rw", "addons:rw", "share:rw", "backup:rw"], + "options": { + "workgroup": "WORKGROUP", + "port1": "445", + "port2": "139", + "username": "homeassistant", + "password": null, + "interface": "", + "allow_hosts": [ + "10.0.0.0/8", + "172.16.0.0/12", + "192.168.0.0/16", + "fe80::/10" + ], + "veto_files": ["._*", ".DS_Store", "Thumbs.db", "icon?", ".Trashes"], + "compatibility_mode": false + }, + "schema": { + "workgroup": "str", + "port1": "str", + "port2": "str", + "username": "str", + "password": "str", + "interface": "str", + "allow_hosts": ["str"], + "veto_files": ["str"], + "compatibility_mode": "bool" + }, + "image_": "homeassistant/{arch}-addon-samba" +} diff --git a/samba/icon.png b/samba/icon.png new file mode 100755 index 0000000..852981b Binary files /dev/null and b/samba/icon.png differ diff --git a/samba/logo.png b/samba/logo.png new file mode 100755 index 0000000..1c82ba8 Binary files /dev/null and b/samba/logo.png differ diff --git a/samba/rootfs/etc/cont-init.d/samba.sh b/samba/rootfs/etc/cont-init.d/samba.sh new file mode 100755 index 0000000..732b4b6 --- /dev/null +++ b/samba/rootfs/etc/cont-init.d/samba.sh @@ -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}" diff --git a/samba/rootfs/etc/samba/smb.conf b/samba/rootfs/etc/samba/smb.conf new file mode 100755 index 0000000..d5440b3 --- /dev/null +++ b/samba/rootfs/etc/samba/smb.conf @@ -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%% diff --git a/samba/rootfs/etc/services.d/nmbd/finish b/samba/rootfs/etc/services.d/nmbd/finish new file mode 100755 index 0000000..a29ced9 --- /dev/null +++ b/samba/rootfs/etc/services.d/nmbd/finish @@ -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 diff --git a/samba/rootfs/etc/services.d/nmbd/run b/samba/rootfs/etc/services.d/nmbd/run new file mode 100755 index 0000000..f1d53ea --- /dev/null +++ b/samba/rootfs/etc/services.d/nmbd/run @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# ============================================================================== +# Start nmbd service +# ============================================================================== +exec nmbd \ + --foreground \ + --log-stdout \ + --no-process-group diff --git a/samba/rootfs/etc/services.d/smbd/finish b/samba/rootfs/etc/services.d/smbd/finish new file mode 100755 index 0000000..a29ced9 --- /dev/null +++ b/samba/rootfs/etc/services.d/smbd/finish @@ -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 diff --git a/samba/rootfs/etc/services.d/smbd/run b/samba/rootfs/etc/services.d/smbd/run new file mode 100755 index 0000000..6fcffa2 --- /dev/null +++ b/samba/rootfs/etc/services.d/smbd/run @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# ============================================================================== +# Start smbd service +# ============================================================================== +exec smbd \ + --foreground \ + --log-stdout \ + --no-process-group