Skip to content

Commit ad24eb4

Browse files
committed
feat: Taildrive shares
Share homeassistant directories to your Tailnet using Taildrive.
1 parent 045e9cc commit ad24eb4

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed

tailscale/DOCS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,5 @@ SOFTWARE.
437437
[tailscale_info_tags]: https://tailscale.com/kb/1068/tags
438438
[tailscale_info_taildrop]: https://tailscale.com/kb/1106/taildrop
439439
[tailscale_info_userspace_networking]: https://tailscale.com/kb/1112/userspace-networking
440+
[tailscale_info_taildrive]: https://tailscale.com/kb/1369/taildrive
441+
[tailscale_info_taildrop]: https://tailscale.com/kb/1106/taildrop

tailscale/config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ privileged:
2424
devices:
2525
- /dev/net/tun
2626
map:
27+
- homeassistant_config:rw
28+
- addon_config:rw
29+
- ssl:rw
30+
- addons:rw
31+
- backup:rw
2732
- share:rw
33+
- media:rw
34+
- all_addon_configs:rw
2835
ports:
2936
41641/udp: null
3037
schema:
@@ -43,4 +50,6 @@ schema:
4350
tags:
4451
- "match(^tag:[a-zA-Z][a-zA-Z0-9-]*$)?"
4552
taildrop: bool?
53+
taildrive:
54+
- "match(^(?i:(homeassistant_config|addon_config|ssl|addons|backup|share|media))$)"
4655
userspace_networking: bool?

tailscale/rootfs/etc/s6-overlay/s6-rc.d/taildrive/dependencies.d/post-tailscaled

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/command/with-contenv bashio
2+
# shellcheck shell=bash
3+
# ==============================================================================
4+
# Home Assistant Community Add-on: Tailscale
5+
# Exposes Home Assistant directories over Taildrive
6+
# ==============================================================================
7+
8+
# Read configured directories from the add-on configuration.
9+
if ! mapfile -t configured_share_names < <(bashio::config "taildrive"); then
10+
bashio::exit.nok "Error reading configured directories from add-on configuration."
11+
fi
12+
13+
# Read currently shared directories into an array from tailscale drive list.
14+
# The output of which looks like:
15+
# name path as
16+
# ---- ---- --
17+
# config /config config
18+
if ! mapfile -t active_share_names < <(/opt/tailscale drive list | tail -n +3 | awk '{print $1}'); then
19+
bashio::exit.nok "Error reading shared directories from Tailscale."
20+
fi
21+
22+
# If a directory is configured but not shared, share it.
23+
for share_name in "${configured_share_names[@]}"; do
24+
if ! printf '%s\0' "${active_share_names[@]}" | grep -Fxqz -- "${share_name}"; then
25+
# Rewrite homeasstant_config to config
26+
if [[ "${share_name}" == "homeassistant_config" ]]; then
27+
share_name="config"
28+
fi
29+
30+
# Share the directory
31+
/opt/tailscale drive share "${share_name}" "/${share_name}"
32+
fi
33+
done
34+
35+
# If a directory is shared but not configured, unshare it.
36+
for share_name in "${active_share_names[@]}"; do
37+
if ! printf '%s\0' "${configured_share_names[@]}" | grep -Fxqz -- "${share_name}"; then
38+
# Rewrite homeasstant_config to config
39+
if [[ "${share_name}" == "homeassistant_config" ]]; then
40+
share_name="config"
41+
fi
42+
43+
# Unshare the directory
44+
/opt/taildrive drive unshare "${share_name}"
45+
fi
46+
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oneshot
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/taildrive/run

tailscale/translations/en.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ configuration:
8686
This option allows you to enable Taildrop, a file sharing service
8787
that allows you to share files with other Tailscale nodes.
8888
When not set, this option is enabled by default.
89+
taildrive:
90+
name: Taildrive Shares
91+
description: >-
92+
This option allows you to specify which Home Assistant directories you
93+
want to share with other Tailscale nodes using Taildrive.
94+
The listed values are the only allowed values.
8995
userspace_networking:
9096
name: Userspace networking mode
9197
description: >-

0 commit comments

Comments
 (0)