Initial add-on code

This commit is contained in:
Franck Nijhof
2019-03-26 00:11:54 +01:00
Unverified
parent e82e7d5379
commit 8f65d52ba4
12 changed files with 498 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: ZeroTier One
# Generates an identiy in case it does not exists yet
# ==============================================================================
readonly private='/ssl/zerotier/identity.secret'
readonly public='/ssl/zerotier/identity.public'
declare node
# Generate identity if it does not exist
if ! bashio::fs.file_exists "${private}" \
|| ! bashio::fs.file_exists "${public}";
then
bashio::log.info "Generating identity files..."
if bashio::fs.file_exists "${private}"; then
rm -f "${private}" \
|| bashio::exit.nok "Failed to delete old private identify file"
fi
if bashio::fs.file_exists "${public}"; then
rm -f "${public}" \
|| bashio::exit.nok "Failed to delete old private identify file"
fi
if ! bashio::fs.directory_exists '/ssl/zerotier'; then
mkdir /ssl/zerotier \
|| bashio::exit.nok "Failed to create identity folder"
fi
zerotier-idtool generate "${private}" "${public}"
fi
ln -s "${private}" /var/lib/zerotier-one/identity.secret
ln -s "${public}" /var/lib/zerotier-one/identity.public
node=$(cut -d ':' -f1 < "${private}")
bashio::log.info "ZeroTier node address: ${node}"

View File

@@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: ZeroTier One
# Sets the auth token for the local JSON API
# ==============================================================================
declare token
if bashio::config.has_value 'api_auth_token'; then
token=$(bashio::config 'api_auth_token')
echo "${token}" > /data/authtoken.secret
fi

View File

@@ -0,0 +1,17 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: ZeroTier One
# Creates ZeroTier One configuration in case it is non-existing
# ==============================================================================
readonly network=$(bashio::config 'network_id')
# Ensure network folder exists
mkdir -p "/var/lib/zerotier-one/networks.d" \
|| bashio::exit.nok "Could not create networks folder"
# Ensure the file exists. An empty file will cause automatic join.
touch "/data/network.${network}.conf"
ln -s \
"/data/network.${network}.conf" \
"/var/lib/zerotier-one/networks.d/${network}.conf" \
|| bashio::exit.nok "Could not create network file"

View File

@@ -0,0 +1,9 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Community Hass.io Add-ons: ZeroTier One
# Take down the S6 supervision tree when ZeroTier fails
# ==============================================================================
if -n { s6-test $# -ne 0 }
if -n { s6-test ${1} -eq 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,15 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: ZeroTier One
# Runs ZeroTier One
# ==============================================================================
declare -a options
bashio::log.info "Starting ZeroTier One..."
# Note sure what this does.
options+=(-U)
options+=("-p$(bashio::config 'port')")
# Run the ZeroTier One
exec zerotier-one "${options[@]}"