#!/bin/ash set -e # Everything persistent lives under /data (survives restarts and updates). mkdir -p /data/ssh /data/home/bridge /data/crontabs chown bridge:bridge /data/home/bridge /data/crontabs chmod 700 /data/home/bridge # --- tailscaled (real TUN inside this container's netns; host never joins tailnet) tailscaled \ --statedir=/data/tailscale \ --tun=tailscale0 & TAILSD=$! # Wait for the socket before trying to bring the node up. # (tailscaled's default socket is /var/run/tailscale/tailscaled.sock; statedir # only moves the state files, not the socket.) i=0 until [ -e /var/run/tailscale/tailscaled.sock ]; do i=$((i+1)); [ "$i" -gt 30 ] && { echo "tailscaled socket never appeared"; exit 1; } sleep 1 done # Auth key is a file in /share (never shown in the add-on options UI). # --accept-dns=true: MagicDNS for tailnet names; non-tailnet names (internet # and *.local.hass.io) are forwarded to the container's upstream resolver, # which is HAOS DNS. if [ -r /share/ssh-bridge/tailscale_authkey ]; then AUTHKEY="$(cat /share/ssh-bridge/tailscale_authkey)" # shellcheck disable=SC2086 tailscale up \ --authkey="$AUTHKEY" \ --hostname="${tailscale_hostname:-ssh-bridge}" \ --accept-dns=true \ ${tailscale_extra_args} \ --reset unset AUTHKEY else echo "WARN: /share/ssh-bridge/tailscale_authkey missing; tailscale node not registered" fi # --- busybox crond with a persistent crontab spool. # busybox crontab(1) is not setuid, so the unprivileged bridge user cannot # install its own crontab; create it here as root instead. The line is fixed # forever — the script it runs lives in bridge's home and is freely editable. # Alpine's crond spool is /etc/crontabs (in-image, not persistent), so keep # the master copy in /data/crontabs and copy it into place on every boot. cat > /data/crontabs/bridge <<'EOF' * * * * * $HOME/.config/fleet/supervise.sh >/dev/null 2>&1 EOF chown bridge:bridge /data/crontabs/bridge chmod 600 /data/crontabs/bridge mkdir -p /etc/crontabs rm -f /etc/crontabs/crontabs # stray symlink from an earlier revision cp /data/crontabs/bridge /etc/crontabs/bridge chown bridge:bridge /etc/crontabs/bridge chmod 600 /etc/crontabs/bridge crond -b -l 6 -L /data/cron.log # --- sshd host key (generated once, kept in /data; never regenerate — # client hosts pin this fingerprint) if [ ! -f /data/ssh/ssh_host_ed25519_key ]; then ssh-keygen -q -t ed25519 -N "" -f /data/ssh/ssh_host_ed25519_key fi # --- sshd in foreground; supervisor restarts the add-on if it dies exec /usr/sbin/sshd -D -f /etc/ssh/sshd_config -e