Update samba add-on to use Bashio #735 (#750)

* Update samba add-on to use Bashio #735

* Updated info log entry for allowed hosts

* Shellcheck update

* Remove old configpath

* Fix for ALLOW_HOSTS issue

* Code optimization using bashio commands. Removing debug line.

* Error Log update and removal of legacy code

* 🚑 Fixes bashio nok exit call

Signed-off-by: Franck Nijhof <frenck@addons.community>
This commit is contained in:
Zapfmeister
2019-10-08 00:19:53 +02:00
committed by Franck Nijhof
parent d161254709
commit 4ae58927ce
3 changed files with 24 additions and 24 deletions

View File

@@ -1,5 +1,8 @@
# Changelog
## 8.2
- Update from bash to bashio
## 8.1
- Update Samba to version 4.8.8

View File

@@ -1,6 +1,6 @@
{
"name": "Samba share",
"version": "8.1",
"version": "8.2",
"slug": "samba",
"description": "Expose Hass.io folders with SMB/CIFS",
"url": "https://home-assistant.io/addons/samba/",

View File

@@ -1,37 +1,34 @@
#!/bin/bash
#!/usr/bin/env bashio
set -e
CONFIG_PATH=/data/options.json
WORKGROUP=$(jq --raw-output '.workgroup' $CONFIG_PATH)
INTERFACE=$(jq --raw-output '.interface // empty' $CONFIG_PATH)
ALLOW_HOSTS=$(jq --raw-output '.allow_hosts | join(" ")' $CONFIG_PATH)
USERNAME=$(jq --raw-output '.username // empty' $CONFIG_PATH)
PASSWORD=$(jq --raw-output '.password // empty' $CONFIG_PATH)
WORKGROUP=$(bashio::config 'workgroup')
INTERFACE=$(bashio::config 'interface')
ALLOW_HOSTS=$(bashio::config "allow_hosts | join(\" \")")
USERNAME=$(bashio::config 'username')
PASSWORD=$(bashio::config 'password')
WAIT_PIDS=()
NAME=
# Check Login data
if [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then
echo "[ERROR] No valid login data inside options!"
exit 1
if ! bashio::config.has_value 'username' || ! bashio::config.has_value 'password'; then
bashio::exit.nok "No valid login data inside options!"
fi
# Read hostname from API
if ! NAME="$(curl -s -f -H "X-Hassio-Key: ${HASSIO_TOKEN}" http://hassio/info | jq --raw-output '.data.hostname')"; then
echo "[WARN] Can't read hostname, use default!"
# Read hostname from API or setting default "hassio"
NAME=$(bashio::info.hostname)
if bashio::var.is_empty "${NAME}"; then
bashio::log.warn "Can't read hostname, using default."
NAME="hassio"
else
echo "[INFO] Read hostname: ${NAME}"
fi
bashio::log.info "Hostname: ${NAME}"
# Setup config
sed -i "s|%%WORKGROUP%%|$WORKGROUP|g" /etc/smb.conf
sed -i "s|%%NAME%%|$NAME|g" /etc/smb.conf
sed -i "s|%%INTERFACE%%|$INTERFACE|g" /etc/smb.conf
sed -i "s|%%ALLOW_HOSTS%%|$ALLOW_HOSTS|g" /etc/smb.conf
sed -i "s|%%USERNAME%%|$USERNAME|g" /etc/smb.conf
sed -i "s|%%WORKGROUP%%|${WORKGROUP}|g" /etc/smb.conf
sed -i "s|%%NAME%%|${NAME}|g" /etc/smb.conf
sed -i "s|%%INTERFACE%%|${INTERFACE}|g" /etc/smb.conf
sed -i "s|%%USERNAME%%|${USERNAME}|g" /etc/smb.conf
sed -i "s#%%ALLOW_HOSTS%%#${ALLOW_HOSTS}#g" /etc/smb.conf
# Init users
addgroup "${USERNAME}"
@@ -48,10 +45,10 @@ WAIT_PIDS+=($!)
# Register stop
function stop_samba() {
echo "Kill Processes..."
bashio::log.info "Kill Processes..."
kill -15 "${WAIT_PIDS[@]}"
wait "${WAIT_PIDS[@]}"
echo "Done."
bashio::log.info "Done."
}
trap "stop_samba" SIGTERM SIGHUP