-
Notifications
You must be signed in to change notification settings - Fork 131
Add support for Taildrive #509
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f61f4a4
feat: Taildrive shares
ananthb 5655e1c
Several fixes (#1)
lmagyar 1093f40
Fix Taildrive breaking startup (#2)
lmagyar c88aa94
fix DOCS links
lmagyar 84adcbc
add export LOG_FD to each script (taildrive)
lmagyar 04d0139
improve error handling based on bunny's suggestions
lmagyar 48a72ef
fix typos in taildrive
lmagyar 306d0ac
minor fix in docs
lmagyar aa49f2c
Bugfix for Taildrive (prevent logging anything when no share is confi…
lmagyar 0268854
rename add-on to app
lmagyar bbc25a0
fix log messages (taildrive) suggested by copilot
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
Some comments aren't visible on the classic Files Changed page.
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,74 @@ | ||
| #!/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 | ||
|
lmagyar marked this conversation as resolved.
|
||
|
|
||
| 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 | ||
|
|
||
|
lmagyar marked this conversation as resolved.
|
||
| ln -s "/homeassistant" "/config" | ||
|
lmagyar marked this conversation as resolved.
|
||
|
|
||
|
lmagyar marked this conversation as resolved.
|
||
| # 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.