✨ Initial add-on code
This commit is contained in:
38
zerotier/rootfs/etc/cont-init.d/10-identity.sh
Normal file
38
zerotier/rootfs/etc/cont-init.d/10-identity.sh
Normal 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}"
|
||||
10
zerotier/rootfs/etc/cont-init.d/20-api.sh
Normal file
10
zerotier/rootfs/etc/cont-init.d/20-api.sh
Normal 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
|
||||
17
zerotier/rootfs/etc/cont-init.d/21-network.sh
Normal file
17
zerotier/rootfs/etc/cont-init.d/21-network.sh
Normal 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"
|
||||
9
zerotier/rootfs/etc/services.d/zerotier/finish
Normal file
9
zerotier/rootfs/etc/services.d/zerotier/finish
Normal 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
|
||||
15
zerotier/rootfs/etc/services.d/zerotier/run
Normal file
15
zerotier/rootfs/etc/services.d/zerotier/run
Normal 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[@]}"
|
||||
Reference in New Issue
Block a user