Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tailscale/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ stateful_filtering: false
tags:
- tag:example
- tag:homeassistant
taildrive:
addons: false
addon_configs: false
backup: false
config: false
media: false
share: false
ssl: false
taildrop: true
userspace_networking: true
```
Expand Down Expand Up @@ -320,6 +328,15 @@ They need to start with `tag:`.

More information: [Tags][tailscale_info_tags]

### Option: `taildrive`

This option allows you to specify which Home Assistant directories you want to
share with other Tailscale nodes using Taildrive.

Only the listed directories are available.

More information: [Taildrive][tailscale_info_taildrive]

### Option: `taildrop`

This add-on supports [Tailscale's Taildrop][tailscale_info_taildrop] feature,
Expand Down Expand Up @@ -462,5 +479,6 @@ SOFTWARE.
[tailscale_info_site_to_site]: https://tailscale.com/kb/1214/site-to-site
[tailscale_info_subnets]: https://tailscale.com/kb/1019/subnets
[tailscale_info_tags]: https://tailscale.com/kb/1068/tags
[tailscale_info_taildrive]: https://tailscale.com/kb/1369/taildrive
[tailscale_info_taildrop]: https://tailscale.com/kb/1106/taildrop
[tailscale_info_userspace_networking]: https://tailscale.com/kb/1112/userspace-networking
23 changes: 23 additions & 0 deletions tailscale/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ privileged:
devices:
- /dev/net/tun
map:
- addons:rw
- all_addon_configs:rw
- backup:rw
- homeassistant_config:rw
- media:rw
- share:rw
- ssl:rw
ports:
41641/udp: null
options:
taildrive:
addons: false
addon_configs: false
backup: false
config: false
media: false
share: false
ssl: false
schema:
accept_dns: bool?
accept_routes: bool?
Expand All @@ -41,5 +56,13 @@ schema:
stateful_filtering: bool?
tags:
- "match(^tag:[a-zA-Z][a-zA-Z0-9-]*$)?"
taildrive:
addons: bool
addon_configs: bool
backup: bool
config: bool
media: bool
share: bool
ssl: bool
taildrop: bool?
userspace_networking: bool?
68 changes: 68 additions & 0 deletions tailscale/rootfs/etc/s6-overlay/s6-rc.d/taildrive/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
export LOG_FD
# ==============================================================================
# Home Assistant Community Add-on: Tailscale
# Exposes Home Assistant directories over Taildrive
# ==============================================================================

# These are not arrays, but newline separated lists (single strings)
declare all_share_names
declare configured_share_names
declare active_share_names

declare share_name

# Read all possible and configured directories from the add-on configuration.
if ! all_share_names=$(bashio::config 'taildrive' | jq -rc 'keys_unsorted[]') || \
! configured_share_names=$(bashio::config 'taildrive' | jq -rc 'to_entries[] | select(.value) | .key')
then
bashio::exit.nok "Error reading configured Taildrive directories from add-on configuration."
fi

# Check if Taildrive is available
if ! /opt/tailscale status --self=true --peers=false --json \
| jq -rce '.Self.CapMap | has("drive:share")' > /dev/null;
then
# If Taildrive is not available but any share is configured, that is an error
if (( 0 < $(wc -w <<< "${configured_share_names}") )); then
bashio::exit.nok "Tailscale's Taildrive is disabled but directories are configured for sharing"
fi
else
# Read currently shared directories into an array from tailscale drive list.
# The output of which looks like:
# name path as
# ------ ------- ----
# config /config root
if ! active_share_names=$(/opt/tailscale drive list | tail -n +3 | awk '{print $1}'); then
bashio::exit.nok "Error reading shared Taildrive directories from Tailscale."
fi

ln -s "/homeassistant" "/config"

# If a directory is configured but not shared, share it.
for share_name in "${configured_share_names}"; do
if ! grep -Fxq -- "${share_name}" <<< "${active_share_names}"; then
bashio::log.info "Taildrive: sharing /${share_name}"
if ! /opt/tailscale drive share "${share_name}" "/${share_name}"; then
bashio::exit.nok "Failed to share /${share_name}"
fi
else
bashio::log.info "Taildrive: /${share_name} is already shared"
fi
done

# If a directory is shared but not configured, and managed by this add-on, unshare it.
for share_name in "${active_share_names}"; do
if ! grep -Fxq -- "${share_name}" <<< "${configured_share_names}"; then
if grep -Fxq -- "${share_name}" <<< "${all_share_names}"; then
bashio::log.info "Taildrive: unsharing /${share_name}"
if ! /opt/tailscale drive unshare "${share_name}"; then
bashio::exit.nok "Failed to unshare /${share_name}"
fi
else
bashio::log.info "Taildrive: skipping to unshare '${share_name}'"
fi
fi
done
fi
1 change: 1 addition & 0 deletions tailscale/rootfs/etc/s6-overlay/s6-rc.d/taildrive/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions tailscale/rootfs/etc/s6-overlay/s6-rc.d/taildrive/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/taildrive/run
Empty file.
6 changes: 6 additions & 0 deletions tailscale/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ configuration:
description: >-
This option allows you to specify specific ACL tags for this
Tailscale instance. They need to start with `tag:`.
taildrive:
name: Taildrive shares
description: >-
This option allows you to specify which Home Assistant directories you want to
share with other Tailscale nodes using Taildrive.
Only the listed directories are available.
taildrop:
name: Taildrop
description: >-
Expand Down