diff --git a/zerotier/config.json b/zerotier/config.json index a8c3a69..8564ad6 100755 --- a/zerotier/config.json +++ b/zerotier/config.json @@ -23,7 +23,6 @@ "hassio_role": "default", "homeassistant_api": false, "host_network": true, - "apparmor": true, "privileged": [ "NET_ADMIN", "SYS_ADMIN" @@ -36,14 +35,12 @@ "ssl:rw" ], "options": { - "network_id":"", - "port": 9993, + "networks":[], "api_auth_token": "" }, "schema": { + "networks":["match([0-9a-z]{16})"], "api_auth_token": "str", - "log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?", - "network_id":"match([0-9a-z]{16})", - "port": "port" + "log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?" } } diff --git a/zerotier/rootfs/etc/cont-init.d/20-api.sh b/zerotier/rootfs/etc/cont-init.d/20-api.sh deleted file mode 100644 index 6e48a5d..0000000 --- a/zerotier/rootfs/etc/cont-init.d/20-api.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/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 diff --git a/zerotier/rootfs/etc/cont-init.d/21-network.sh b/zerotier/rootfs/etc/cont-init.d/21-network.sh deleted file mode 100644 index c2ac58c..0000000 --- a/zerotier/rootfs/etc/cont-init.d/21-network.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/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" diff --git a/zerotier/rootfs/etc/cont-init.d/10-identity.sh b/zerotier/rootfs/etc/cont-init.d/zerotier.sh similarity index 60% rename from zerotier/rootfs/etc/cont-init.d/10-identity.sh rename to zerotier/rootfs/etc/cont-init.d/zerotier.sh index 343f87b..e16d04c 100644 --- a/zerotier/rootfs/etc/cont-init.d/10-identity.sh +++ b/zerotier/rootfs/etc/cont-init.d/zerotier.sh @@ -5,7 +5,9 @@ # ============================================================================== readonly private='/ssl/zerotier/identity.secret' readonly public='/ssl/zerotier/identity.public' +declare network declare node +declare token # Generate identity if it does not exist if ! bashio::fs.file_exists "${private}" \ @@ -36,3 +38,27 @@ ln -s "${public}" /var/lib/zerotier-one/identity.public node=$(cut -d ':' -f1 < "${private}") bashio::log.info "ZeroTier node address: ${node}" + +# Sets the auth token for the local JSON API +if bashio::config.has_value 'api_auth_token'; then + token=$(bashio::config 'api_auth_token') + echo "${token}" > /data/authtoken.secret +fi + +# Ensure network folder exists +mkdir -p "/var/lib/zerotier-one/networks.d" \ + || bashio::exit.nok "Could not create networks folder" + +# Install user configured/requested packages +if bashio::config.has_value 'networks'; then + for network in $(bashio::config 'networks'); do + bashio::log.info "Configuring network: ${network}" + + # 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" + done +fi