Skip to content

Commit

Permalink
Add support for Taildrop (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Mar 30, 2023
1 parent 0bbafaf commit 0d213e1
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tailscale/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ more severe level, e.g., `debug` also shows `info` messages. By default,
the `log_level` is set to `info`, which is the recommended setting unless
you are troubleshooting.

## Taildrop

This add-on support [Tailscale's Taildrop][taildrop] feature, which allows
you to send files to your Home Assistant instance from other Tailscale
devices.

Received files are stored in the `/share/taildrop` directory.

## Changelog & Releases

This repository keeps a change log using [GitHub's releases][releases]
Expand Down Expand Up @@ -157,3 +165,4 @@ SOFTWARE.
[reddit]: https://reddit.com/r/homeassistant
[releases]: https://github.com/hassio-addons/addon-tailscale/releases
[semver]: https://semver.org/spec/v2.0.0.html
[taildrop]: https://tailscale.com/taildrop/
2 changes: 2 additions & 0 deletions tailscale/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ privileged:
devices:
- /dev/net/tun
host_network: true
map:
- share:rw
schema:
tags: ["match(^tag:[a-zA-Z0-9]-?[a-zA-Z0-9]+$)?"]
log_level: list(trace|debug|info|notice|warning|error|fatal)?
Empty file.
27 changes: 27 additions & 0 deletions tailscale/rootfs/etc/s6-overlay/s6-rc.d/taildrop/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Tailscale
# Take down the S6 supervision tree when Taildrop fails
# ==============================================================================
declare exit_code
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
readonly service="taildrop"

bashio::log.info \
"Service ${service} exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"

if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
exec /run/s6/basedir/bin/halt
fi
20 changes: 20 additions & 0 deletions tailscale/rootfs/etc/s6-overlay/s6-rc.d/taildrop/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Tailscale
# Fetches files send via Taildrop
# ==============================================================================

# Wait for the network to be available and logged in
while ! bashio::fs.socket_exists "/var/run/tailscale/tailscaled.sock" || \
! /opt/tailscale status --json --peers=false --self=false \
| jq --exit-status '.BackendState == "Running"' > /dev/null
do
sleep 2
done

# Ensure the directory exists
mkdir -p /share/taildrop

# Fetch files
exec /opt/tailscale file get --verbose --loop "/share/taildrop"
1 change: 1 addition & 0 deletions tailscale/rootfs/etc/s6-overlay/s6-rc.d/taildrop/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions tailscale/rootfs/etc/s6-overlay/s6-rc.d/tailscaled/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare -a options
bashio::log.info 'Starting Tailscale...'

options+=(--state=/data/tailscaled.state)
options+=(--statedir=/data/state)
# Opt out of client log upload to log.tailscale.io
options+=(--no-logs-no-support)
options+=(--tun=userspace-networking)
Expand Down
Empty file.

0 comments on commit 0d213e1

Please sign in to comment.