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
0 commit comments