# shellcheck shell=bash # Scenarios set what the runner and items read # shellcheck disable=SC2034 DESCRIPTION="Taildrop saves files to Downloads; an exit node pauses for a captive portal" TIER=quick scenario() { local bin="$HOME/.local/bin" calls="$HOME/tailscale-calls" status_json="$HOME/tailscale.json" local portal="$CONNECTOR/system/captive-portal" state="$HOME/exit-node-paused" sent="$HOME/sent" pid i mkdir -p "$bin" # A stand-in tailscale: `status --json` prints $status_json, and every call # is recorded cat > "$bin/tailscale" << EOF #!/bin/bash echo "\$*" >> "$calls" case "\$1 \$2" in "status --json") cat "$status_json" ;; "file get") # The first call receives two files; later ones wait, as with nothing sent if [ ! -e "$HOME/received-once" ]; then touch "$HOME/received-once" echo "wrote /home/pop/Downloads/a.txt as /home/pop/Downloads/a.txt (12 bytes)" echo "wrote /home/pop/Downloads/b b.pdf as /home/pop/Downloads/b b (1).pdf (3400 bytes)" else sleep 30 fi ;; esac EOF chmod +x "$bin/tailscale" printf '#!/bin/bash\nprintf "%%s\\n" "$@" > %q\n' "$sent" > "$bin/notify-send" chmod +x "$bin/notify-send" step "system/captive-portal" echo '{"ExitNodeStatus": {"TailscaleIPs": ["100.64.0.9/32"]}}' > "$status_json" : > "$calls" CAPTIVE_PORTAL_STATE="$state" CONNECTIVITY_STATE=PORTAL "$portal" wlan0 up check_not "it does nothing but on a connectivity change" grep -q "^set" "$calls" CAPTIVE_PORTAL_STATE="$state" CONNECTIVITY_STATE=PORTAL "$portal" wlan0 connectivity-change check "behind a portal, it stops using the exit node" grep -qx "set --exit-node=" "$calls" check_eq "and remembers it" 100.64.0.9 "$(cat "$state")" echo '{"ExitNodeStatus": null}' > "$status_json" : > "$calls" CAPTIVE_PORTAL_STATE="$state" CONNECTIVITY_STATE=FULL "$portal" wlan0 connectivity-change check "online again, it uses it again" grep -qx "set --exit-node=100.64.0.9" "$calls" check_not "and forgets it" test -e "$state" echo 100.64.0.9 > "$state" echo '{"ExitNodeStatus": {"TailscaleIPs": ["100.64.0.7/32"]}}' > "$status_json" : > "$calls" CAPTIVE_PORTAL_STATE="$state" CONNECTIVITY_STATE=FULL "$portal" wlan0 connectivity-change check_not "but not if you've picked another one meanwhile" grep -q "^set" "$calls" echo '{"ExitNodeStatus": null}' > "$status_json" : > "$calls" CAPTIVE_PORTAL_STATE="$state" CONNECTIVITY_STATE=PORTAL "$portal" wlan0 connectivity-change check_not "without an exit node, a portal changes nothing" grep -q "^set" "$calls" step "system/taildrop" : > "$calls" "$CONNECTOR/system/taildrop" & pid=$! for i in $(seq 50); do [ -s "$sent" ] && break; sleep 0.1; done pkill -P "$pid" 2> /dev/null; kill "$pid" 2> /dev/null check "it receives into Downloads" grep -q "file get --wait --conflict=rename --verbose $HOME/Downloads" "$calls" check "Downloads is there" test -d "$HOME/Downloads" check "the notification counts the files" grep -qx "Received 2 files" "$sent" check "and names them" grep -qx "b b (1).pdf" "$sent" step "configure tailscale's Taildrop and captive portal" export DISPATCHER_DIR="$HOME/dispatcher.d" source "$CONNECTOR/configure.d/15-tailscale.sh" # No systemd user manager or root here systemctl() { case "$*" in *is-enabled*) [ -e "$UNITS/enabled" ] ;; *enable*) touch "$UNITS/enabled" ;; esac; } sudo() { if [ "$1" = install ]; then install -D -m 755 "${@: -2:1}" "${@: -1}"; else "$@"; fi; } check_not "not set up yet" extras_ok check "install_extras" install_extras check "the service is installed" cmp -s "$CONNECTOR/system/systemd/$TAILDROP_UNIT" "$UNITS/$TAILDROP_UNIT" check "the captive portal script is" test -x "$CAPTIVE_PORTAL" check "extras_ok" extras_ok echo "# older" >> "$CAPTIVE_PORTAL" check_not "an older captive portal script isn't" extras_ok remove_extras check_not "remove_extras removes the service" test -e "$UNITS/$TAILDROP_UNIT" unset -f systemctl sudo unset DISPATCHER_DIR rm -rf "$bin/tailscale" "$bin/notify-send" "$calls" "$status_json" "$sent" "$HOME/received-once" \ "$HOME/dispatcher.d" "$HOME/Downloads" "$state" }