-
Notifications
You must be signed in to change notification settings - Fork 129
Add support for Taildrive #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
daa9201
feat: Taildrive shares
ananthb 8774247
Several fixes (#1)
lmagyar 23755a4
Fix Taildrive breaking startup (#2)
lmagyar 5047ed6
add export LOG_FD to each script (taildrive)
lmagyar 3e5c2ce
improve error handling based on bunny's suggestions
lmagyar cb5f670
fix typos in taildrive
lmagyar ae9425f
minor fix in docs
lmagyar 42ab144
Bugfix for Taildrive (prevent logging anything when no share is confi…
lmagyar 9f3b35c
rename add-on to app
lmagyar 2783c82
fix log messages (taildrive) suggested by copilot
lmagyar 241b102
fix taildrive map config
lmagyar 7c9d0d6
make the linter happy
lmagyar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
| export LOG_FD | ||
| # ============================================================================== | ||
| # Home Assistant Community App: 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 app 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 app 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 feature is not available, but directories are configured" \ | ||
| "for sharing. Please check your Tailscale plan and ACL settings." | ||
| 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 | ||
|
|
||
| # If a directory is configured but not shared, share it. | ||
| # Note: do not quote configured_share_names in the for loop, | ||
| # as we want to iterate over words (lines), this is not an array | ||
| 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 app, unshare it. | ||
| # Note: do not quote active_share_names in the for loop, | ||
| # as we want to iterate over words (lines), this is not an array | ||
| 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 unshare of '${share_name}' (not managed by this app)" | ||
| fi | ||
| fi | ||
| done | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| oneshot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /etc/s6-overlay/s6-rc.d/taildrive/run |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.