-
Notifications
You must be signed in to change notification settings - Fork 95
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
Open
ananthb
wants to merge
7
commits into
hassio-addons:main
Choose a base branch
from
ananthb:taildrive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74ea8f1
feat: Taildrive shares
ananthb 4c8d153
Several fixes (#1)
lmagyar 1ba2b49
Fix Taildrive breaking startup (#2)
lmagyar 3442f51
fix DOCS links
lmagyar f6772e1
add export LOG_FD to each script (taildrive)
lmagyar a30e43c
improve error handling based on bunny's suggestions
lmagyar 77084a1
fix typos in taildrive
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,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 | ||
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.