Taildrop to Downloads, exit nodes past captive portals, stay awake
Ports the rest of CoreDesktop's 9dc5eb1 that applies to Pop!_OS. - configure tailscale turns on federated-connector-taildrop.service, which saves files sent here with Taildrop to Downloads and says so in a notification. COSMIC Files has no Scripts menu, so CoreDesktop's "Send with Tailscale" isn't ported; send with tailscale file cp. Leaving the network turns it off. - It also installs a NetworkManager dispatcher script that stops using a Tailscale exit node while you sign in to a captive portal, and uses it again once online. Pop!_OS checks connectivity (20-connectivity-pop), so NetworkManager sees the portal. - A computer joined before this shows Tailscale as to do, and configure tailscale adds both without signing in again. update restarts the Taildrop service on the new version, as it does the email watcher. - install.sh keeps the computer from sleeping until an install or update finishes. The pacman guard, unowned files and hardware.sh are Arch only. Smoketest: 75-taildrop-portal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,19 +53,13 @@ Since `4a4a3bd`, to look at:
|
|||||||
and its later checks from `d5925fa` (what root runs is root's alone) and
|
and its later checks from `d5925fa` (what root runs is root's alone) and
|
||||||
`53c6c8b` (the install path). Hiding the connector's settings from
|
`53c6c8b` (the install path). Hiding the connector's settings from
|
||||||
agents is done.
|
agents is done.
|
||||||
- [ ] `9dc5eb1` Upgrade safeguards, hardware setup, sign-in options and Taildrop.
|
|
||||||
Sign-in options (security key, fingerprint) are done.
|
|
||||||
To port: Taildrop's service that saves files sent here to Downloads (COSMIC Files
|
|
||||||
has no Scripts menu for sending), keeping the computer awake during
|
|
||||||
`update`, and the captive portal script that pauses a Tailscale exit
|
|
||||||
node. Arch only: the pacman guard, unowned files, `hardware.sh`
|
|
||||||
(System76 does its own).
|
|
||||||
- [ ] `ffbaf71` Keep other machines on the network from reaching Docker
|
- [ ] `ffbaf71` Keep other machines on the network from reaching Docker
|
||||||
containers: only if the connector ever installs Docker
|
containers: only if the connector ever installs Docker
|
||||||
|
|
||||||
Arch or GNOME only, nothing to port: `e14a345` and `ba4dc17` (login screen
|
Arch or GNOME only, nothing to port: from `9dc5eb1`, the pacman guard, unowned
|
||||||
logo), `1e2581d` (kernel modules), `d456e31` (initramfs), `5d7db2c` (reboot
|
files and `hardware.sh` (System76 does its own); `e14a345` and `ba4dc17`
|
||||||
after update: Pop!_OS' own updates handle this).
|
(login screen logo), `1e2581d` (kernel modules), `d456e31` (initramfs),
|
||||||
|
`5d7db2c` (reboot after update: Pop!_OS' own updates handle this).
|
||||||
|
|
||||||
## Pop!_OS-specific
|
## Pop!_OS-specific
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ Each item installs what it needs the first time you set it up, after asking.
|
|||||||
- **Test a Core**: it checks Superpanel, calendars and contacts, email, your files, Element and backups the way this computer uses them, says which work, and offers to fix those that don't. If a fix needs it, for example a new app password for one that was revoked, it asks for your Core password. Then it tests again.
|
- **Test a Core**: it checks Superpanel, calendars and contacts, email, your files, Element and backups the way this computer uses them, says which work, and offers to fix those that don't. If a fix needs it, for example a new app password for one that was revoked, it asks for your Core password. Then it tests again.
|
||||||
- **Your Core password changed**: email gets the new password, and signing in to Nextcloud with it turns the app passwords for calendars, contacts, files and backups back on (Nextcloud turns them off when your password changes). Then it checks each of them.
|
- **Your Core password changed**: email gets the new password, and signing in to Nextcloud with it turns the app passwords for calendars, contacts, files and backups back on (Nextcloud turns them off when your password changes). Then it checks each of them.
|
||||||
- **Remove a Core**: it removes the accounts, the mount and Superpanel, and revokes the app password. Everything on the Core itself stays as it is.
|
- **Remove a Core**: it removes the accounts, the mount and Superpanel, and revokes the app password. Everything on the Core itself stays as it is.
|
||||||
- **Tailscale**: joins this computer to your Core's Tailscale network through headscale.example.com. If Tailscale isn't installed, it installs it from Tailscale's own apt repository. You can use `tailscale` without sudo afterwards. To leave the network, run `configure tailscale` again.
|
- **Tailscale**: joins this computer to your Core's Tailscale network through headscale.example.com. If Tailscale isn't installed, it installs it from Tailscale's own apt repository. You can use `tailscale` without sudo afterwards. Files your other computers send here with Taildrop (`tailscale file cp <file> <computer>:`, or Tailscale's apps) are saved to Downloads, with a notification. On a network with a sign-in page (hotels, airports, trains), a Tailscale exit node would keep the page from loading, so a NetworkManager script stops using it until you've signed in, then uses it again (`/etc/NetworkManager/dispatcher.d/90-federated-connector-captive-portal`). To leave the network, run `configure tailscale` again.
|
||||||
- **Backup**: backs up your home folder daily to your Nextcloud files, in a `.backup-{computer name}` folder, with restic (from Ubuntu's packages).
|
- **Backup**: backs up your home folder daily to your Nextcloud files, in a `.backup-{computer name}` folder, with restic (from Ubuntu's packages).
|
||||||
- The backup is encrypted with a passphrase that `configure` shows you once. Save it somewhere other than this computer, such as Bitwarden.
|
- The backup is encrypted with a passphrase that `configure` shows you once. Save it somewhere other than this computer, such as Bitwarden.
|
||||||
- It keeps 7 daily, 4 weekly and 6 monthly backups. It leaves out caches, things that can be reinstalled, and Flatpak apps' caches. To leave out more, list paths in `~/.config/federated-connector/backup-exclude`, one per line.
|
- It keeps 7 daily, 4 weekly and 6 monthly backups. It leaves out caches, things that can be reinstalled, and Flatpak apps' caches. To leave out more, list paths in `~/.config/federated-connector/backup-exclude`, one per line.
|
||||||
@@ -150,7 +150,7 @@ To allow more, put a file in the same format as `sandbox/config/base.json` in `~
|
|||||||
- Accounts: GNOME Online Accounts (`~/.config/goa-1.0/accounts.conf`), with their passwords in your keyring
|
- Accounts: GNOME Online Accounts (`~/.config/goa-1.0/accounts.conf`), with their passwords in your keyring
|
||||||
- The backup's app password and passphrase: your keyring, attributes `federated-connector backup`
|
- The backup's app password and passphrase: your keyring, attributes `federated-connector backup`
|
||||||
- Your files' app password: `~/.davfs2/secrets`
|
- Your files' app password: `~/.davfs2/secrets`
|
||||||
- Services: `~/.config/systemd/user/federated-connector-{backup.service,backup.timer,email-watch.service,sftp-*.service}`
|
- Services: `~/.config/systemd/user/federated-connector-{backup.service,backup.timer,email-watch.service,taildrop.service,sftp-*.service}`
|
||||||
- The Files sidebar: `~/.config/cosmic/com.system76.CosmicFiles/v1/favorites`, and `~/.config/gtk-3.0/bookmarks` for GTK apps
|
- The Files sidebar: `~/.config/cosmic/com.system76.CosmicFiles/v1/favorites`, and `~/.config/gtk-3.0/bookmarks` for GTK apps
|
||||||
- Federated Connector itself: `~/.local/share/federated-connector/connector`, with `configure` and `update` linked in `~/.local/bin`
|
- Federated Connector itself: `~/.local/share/federated-connector/connector`, with `configure` and `update` linked in `~/.local/bin`
|
||||||
- Downloaded tools: `~/.local/share/federated-connector` (`node`, `srt`)
|
- Downloaded tools: `~/.local/share/federated-connector` (`node`, `srt`)
|
||||||
@@ -185,4 +185,5 @@ Each file in `configure.d/` is one item. It sets `TITLE` and `DESCRIPTION` and d
|
|||||||
- Languages come from mise's apt repository, and nothing is installed with it up front. CoreDesktop's `update` upgrades them; here, run `mise upgrade`.
|
- Languages come from mise's apt repository, and nothing is installed with it up front. CoreDesktop's `update` upgrades them; here, run `mise upgrade`.
|
||||||
- The agents are installed by `configure agents`, and srt runs on its own Node.js. On Ubuntu, bubblewrap may need an AppArmor profile.
|
- The agents are installed by `configure agents`, and srt runs on its own Node.js. On Ubuntu, bubblewrap may need an AppArmor profile.
|
||||||
- A fingerprint works for sudo and polkit, but not the login and lock screens: COSMIC's greeter signs in through `common-auth`, which this leaves alone. CoreDesktop's works on GNOME's login and lock screens too.
|
- A fingerprint works for sudo and polkit, but not the login and lock screens: COSMIC's greeter signs in through `common-auth`, which this leaves alone. CoreDesktop's works on GNOME's login and lock screens too.
|
||||||
- `update` updates only Federated Connector; Pop!_OS updates the rest.
|
- `update` updates only Federated Connector; Pop!_OS updates the rest. Like CoreDesktop's, it keeps the computer awake until it's done.
|
||||||
|
- Taildrop receives files, but COSMIC Files has no Scripts menu for CoreDesktop's "Send with Tailscale"; send with `tailscale file cp`.
|
||||||
|
|||||||
@@ -75,6 +75,12 @@ Once it's packaged for Pop!_OS (see [PLAN.md](PLAN.md)):
|
|||||||
|
|
||||||
- [ ] `configure tailscale` joins the Core's headscale, and `tailscale status`
|
- [ ] `configure tailscale` joins the Core's headscale, and `tailscale status`
|
||||||
shows the other machines
|
shows the other machines
|
||||||
|
- [ ] A file sent from another computer (`tailscale file cp f <this computer>:`)
|
||||||
|
lands in Downloads, with a notification whose Show opens the folder
|
||||||
|
- [ ] With an exit node on, joining a network with a sign-in page loads the
|
||||||
|
page, and once signed in the exit node is used again
|
||||||
|
- [ ] On a computer joined before this, `configure` shows Tailscale as to do,
|
||||||
|
and `configure tailscale` adds Taildrop without signing in again
|
||||||
|
|
||||||
### Backups
|
### Backups
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ CORE_CONF="$CONF_DIR/core.conf"
|
|||||||
TAILSCALE_CONF="$CONF_DIR/tailscale.conf"
|
TAILSCALE_CONF="$CONF_DIR/tailscale.conf"
|
||||||
[ -f "$CORE_CONF" ] && source "$CORE_CONF"
|
[ -f "$CORE_CONF" ] && source "$CORE_CONF"
|
||||||
[ -f "$TAILSCALE_CONF" ] && source "$TAILSCALE_CONF"
|
[ -f "$TAILSCALE_CONF" ] && source "$TAILSCALE_CONF"
|
||||||
|
UNITS="$HOME/.config/systemd/user"
|
||||||
|
TAILDROP_UNIT="federated-connector-taildrop.service"
|
||||||
|
# NetworkManager runs only dispatcher scripts that root owns and only root can
|
||||||
|
# change. For the tests: DISPATCHER_DIR.
|
||||||
|
CAPTIVE_PORTAL="${DISPATCHER_DIR:-/etc/NetworkManager/dispatcher.d}/90-federated-connector-captive-portal"
|
||||||
|
|
||||||
# Tailscale's own installer adds its apt repository (pkgs.tailscale.com), so
|
# Tailscale's own installer adds its apt repository (pkgs.tailscale.com), so
|
||||||
# Pop!_OS' updates keep it up to date. It's downloaded, then run, rather than
|
# Pop!_OS' updates keep it up to date. It's downloaded, then run, rather than
|
||||||
@@ -37,9 +42,42 @@ joined() {
|
|||||||
&& tailscale status --json 2> /dev/null | jq -e '.BackendState == "Running"' > /dev/null
|
&& tailscale status --json 2> /dev/null | jq -e '.BackendState == "Running"' > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Done when on the main Core's network
|
# What goes with being on the network: the service that saves files sent here
|
||||||
|
# with Taildrop to Downloads (system/taildrop), and the NetworkManager script
|
||||||
|
# that stops using an exit node while you sign in to a captive portal
|
||||||
|
# (system/captive-portal). True when both are installed and up to date.
|
||||||
|
extras_ok() {
|
||||||
|
cmp -s "$CONNECTOR/system/systemd/$TAILDROP_UNIT" "$UNITS/$TAILDROP_UNIT" \
|
||||||
|
&& systemctl --user is-enabled -q "$TAILDROP_UNIT" 2> /dev/null \
|
||||||
|
&& cmp -s "$CONNECTOR/system/captive-portal" "$CAPTIVE_PORTAL"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_extras() {
|
||||||
|
mkdir -p "$UNITS" && cp "$CONNECTOR/system/systemd/$TAILDROP_UNIT" "$UNITS/" || return 1
|
||||||
|
systemctl --user daemon-reload
|
||||||
|
systemctl --user enable "$TAILDROP_UNIT" 2> /dev/null || return 1
|
||||||
|
systemctl --user restart "$TAILDROP_UNIT" 2> /dev/null
|
||||||
|
if ! cmp -s "$CONNECTOR/system/captive-portal" "$CAPTIVE_PORTAL"; then
|
||||||
|
sudo install -D -m 755 -o root -g root "$CONNECTOR/system/captive-portal" "$CAPTIVE_PORTAL" || return 1
|
||||||
|
fi
|
||||||
|
echo "Files sent to this computer with Taildrop are saved to Downloads. To send files to"
|
||||||
|
echo "your other computers on the network: tailscale file cp <file>... <computer>:"
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_extras() {
|
||||||
|
systemctl --user disable --now "$TAILDROP_UNIT" 2> /dev/null
|
||||||
|
rm -f "$UNITS/$TAILDROP_UNIT"
|
||||||
|
systemctl --user daemon-reload
|
||||||
|
# The captive portal script stays: without an exit node it does nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
# Done when on the main Core's network, with what goes with it
|
||||||
is_configured() {
|
is_configured() {
|
||||||
[ -n "$CORE_DOMAIN" ] && [ "$TAILSCALE_DOMAIN" = "$CORE_DOMAIN" ] && joined
|
[ -n "$CORE_DOMAIN" ] && [ "$TAILSCALE_DOMAIN" = "$CORE_DOMAIN" ] && joined && extras_ok
|
||||||
|
}
|
||||||
|
|
||||||
|
is_configured_but_extras() {
|
||||||
|
[ -n "$CORE_DOMAIN" ] && [ "$TAILSCALE_DOMAIN" = "$CORE_DOMAIN" ] && joined &> /dev/null && ! extras_ok
|
||||||
}
|
}
|
||||||
|
|
||||||
# Log out rather than only go down, so this computer's key is expired on
|
# Log out rather than only go down, so this computer's key is expired on
|
||||||
@@ -47,11 +85,18 @@ is_configured() {
|
|||||||
leave_network() {
|
leave_network() {
|
||||||
sudo tailscale logout || return 1
|
sudo tailscale logout || return 1
|
||||||
rm -f "$TAILSCALE_CONF"
|
rm -f "$TAILSCALE_CONF"
|
||||||
|
remove_extras
|
||||||
echo "This computer has left your Core's Tailscale network. To join again: configure tailscale"
|
echo "This computer has left your Core's Tailscale network. To join again: configure tailscale"
|
||||||
}
|
}
|
||||||
|
|
||||||
run_configure() {
|
run_configure() {
|
||||||
local choice
|
local choice
|
||||||
|
# On the network, from before Taildrop and the captive portal script: add
|
||||||
|
# them without signing in again
|
||||||
|
if is_configured_but_extras; then
|
||||||
|
install_extras
|
||||||
|
return
|
||||||
|
fi
|
||||||
if joined &> /dev/null; then
|
if joined &> /dev/null; then
|
||||||
echo "This computer is on $TAILSCALE_DOMAIN's Tailscale network (headscale.$TAILSCALE_DOMAIN)."
|
echo "This computer is on $TAILSCALE_DOMAIN's Tailscale network (headscale.$TAILSCALE_DOMAIN)."
|
||||||
echo
|
echo
|
||||||
@@ -90,4 +135,5 @@ run_configure() {
|
|||||||
mkdir -p "$(dirname "$TAILSCALE_CONF")"
|
mkdir -p "$(dirname "$TAILSCALE_CONF")"
|
||||||
printf 'TAILSCALE_DOMAIN=%q\n' "$CORE_DOMAIN" > "$TAILSCALE_CONF"
|
printf 'TAILSCALE_DOMAIN=%q\n' "$CORE_DOMAIN" > "$TAILSCALE_CONF"
|
||||||
echo "This computer is on your Core's Tailscale network."
|
echo "This computer is on your Core's Tailscale network."
|
||||||
|
install_extras
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-3
@@ -190,7 +190,7 @@ put_on_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# The services configure set up run from copies of system/systemd's units;
|
# The services configure set up run from copies of system/systemd's units;
|
||||||
# bring those up to date, and restart the email watcher on the new version
|
# bring those up to date, and restart the ones running on the new version
|
||||||
refresh_units() {
|
refresh_units() {
|
||||||
local unit changed=0
|
local unit changed=0
|
||||||
for unit in "$CONNECTOR"/system/systemd/*; do
|
for unit in "$CONNECTOR"/system/systemd/*; do
|
||||||
@@ -199,15 +199,28 @@ refresh_units() {
|
|||||||
cp "$unit" "$UNITS/" && changed=1
|
cp "$unit" "$UNITS/" && changed=1
|
||||||
done
|
done
|
||||||
[ $changed -eq 1 ] && systemctl --user daemon-reload 2> /dev/null
|
[ $changed -eq 1 ] && systemctl --user daemon-reload 2> /dev/null
|
||||||
if systemctl --user is-active -q federated-connector-email-watch.service 2> /dev/null; then
|
for unit in federated-connector-email-watch.service federated-connector-taildrop.service; do
|
||||||
systemctl --user restart federated-connector-email-watch.service 2> /dev/null
|
if systemctl --user is-active -q "$unit" 2> /dev/null; then
|
||||||
|
systemctl --user restart "$unit" 2> /dev/null
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Keep the computer from suspending, from idle or a closed lid, until this
|
||||||
|
# exits, so an install isn't left half done. tail exits with it, and that ends
|
||||||
|
# the inhibitor.
|
||||||
|
stay_awake() {
|
||||||
|
command -v systemd-inhibit > /dev/null || return 0
|
||||||
|
systemd-inhibit --what=sleep:idle --who="Federated Connector" --mode=block \
|
||||||
|
--why="$([ "$1" -eq 1 ] && echo Updating || echo Installing) Federated Connector" \
|
||||||
|
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local update=0 installed latest log
|
local update=0 installed latest log
|
||||||
[ "$1" = --update ] && update=1
|
[ "$1" = --update ] && update=1
|
||||||
|
stay_awake $update
|
||||||
|
|
||||||
mkdir -p "$LOG_DIR" && log="$LOG_DIR/$([ $update -eq 1 ] && echo update || echo install)-$(date +%Y-%m-%d-%H%M%S).log"
|
mkdir -p "$LOG_DIR" && log="$LOG_DIR/$([ $update -eq 1 ] && echo update || echo install)-$(date +%Y-%m-%d-%H%M%S).log"
|
||||||
[ -n "$log" ] && exec > >(tee -a "$log") 2>&1
|
[ -n "$log" ] && exec > >(tee -a "$log") 2>&1
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ Each run writes its logs to `smoketest/results/<time>/`, one per scenario, and p
|
|||||||
| `55-hermes-homeserver` | Hermes' gateway reaches only a Matrix server you've allowed: a server in Hermes' settings is to do until `configure hermes` allows it, a wildcard or escape codes never count, and `configure agents` carries over the server an old drop-in allowed. `edit_json` fills an empty file from its default. |
|
| `55-hermes-homeserver` | Hermes' gateway reaches only a Matrix server you've allowed: a server in Hermes' settings is to do until `configure hermes` allows it, a wildcard or escape codes never count, and `configure agents` carries over the server an old drop-in allowed. `edit_json` fills an empty file from its default. |
|
||||||
| `60-packages` *(all)* | davfs2 installs with `mount.davfs` setuid, and `davfs2_ready` fixes one installed without. sshfs' `fusermount3` and smbclient are where `configure storage` expects them, and so is GTK's CUPS print backend. mise installs from its apt repository and a new bash has it. |
|
| `60-packages` *(all)* | davfs2 installs with `mount.davfs` setuid, and `davfs2_ready` fixes one installed without. sshfs' `fusermount3` and smbclient are where `configure storage` expects them, and so is GTK's CUPS print backend. mise installs from its apt repository and a new bash has it. |
|
||||||
| `70-sign-in` | `configure security-key` and `configure fingerprint` on copies of Ubuntu's sudo and polkit stacks, which start with `@include common-auth`: the line goes just before it, polkit gets its own copy and the vendor's is left alone, adding twice adds once, and stopping puts sudo back as it was. A FIDO2 key is found by its HID descriptor, a reader by its vendor (unless a driver claims it, like a touchpad) or its name. |
|
| `70-sign-in` | `configure security-key` and `configure fingerprint` on copies of Ubuntu's sudo and polkit stacks, which start with `@include common-auth`: the line goes just before it, polkit gets its own copy and the vendor's is left alone, adding twice adds once, and stopping puts sudo back as it was. A FIDO2 key is found by its HID descriptor, a reader by its vendor (unless a driver claims it, like a touchpad) or its name. |
|
||||||
|
| `75-taildrop-portal` | With a stand-in `tailscale`: `system/captive-portal` stops using an exit node behind a sign-in page and uses it again once online, unless you've picked another one. `system/taildrop` receives into Downloads and names the files in its notification. `configure tailscale` installs the Taildrop service and the dispatcher script, sees an old script as to do, and leaving removes the service. |
|
||||||
|
|
||||||
## What still needs Pop!_OS
|
## What still needs Pop!_OS
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
# 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"
|
||||||
|
}
|
||||||
Executable
+42
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Purpose : NetworkManager runs this as root when the network's connectivity
|
||||||
|
# changes (configure tailscale installs it in dispatcher.d).
|
||||||
|
# On a network with a sign-in page (a captive portal: hotels,
|
||||||
|
# airports, trains), a Tailscale exit node sends the sign-in page
|
||||||
|
# into a tunnel the network is still blocking, so the sign-in page
|
||||||
|
# never loads. Stop using the exit node until you've signed
|
||||||
|
# in, then use it again.
|
||||||
|
|
||||||
|
# For the tests
|
||||||
|
PAUSED="${CAPTIVE_PORTAL_STATE:-/run/federated-connector-exit-node-paused}"
|
||||||
|
|
||||||
|
[ "$2" = connectivity-change ] || exit 0
|
||||||
|
command -v tailscale > /dev/null || exit 0
|
||||||
|
|
||||||
|
case "$CONNECTIVITY_STATE" in
|
||||||
|
PORTAL)
|
||||||
|
[ -e "$PAUSED" ] && exit 0
|
||||||
|
# The exit node's Tailscale address, without its /32
|
||||||
|
node="$(tailscale status --json 2> /dev/null | jq -r '.ExitNodeStatus.TailscaleIPs[0] // empty')"
|
||||||
|
node="${node%/*}"
|
||||||
|
[ -n "$node" ] || exit 0
|
||||||
|
echo "$node" > "$PAUSED"
|
||||||
|
if tailscale set --exit-node=; then
|
||||||
|
logger -t federated-connector "Signing in to a captive portal: stopped using exit node $node until online"
|
||||||
|
else
|
||||||
|
rm -f "$PAUSED"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
FULL)
|
||||||
|
[ -s "$PAUSED" ] || exit 0
|
||||||
|
node="$(< "$PAUSED")"
|
||||||
|
# Leave it if you picked another exit node meanwhile
|
||||||
|
if [ -z "$(tailscale status --json 2> /dev/null | jq -r '.ExitNodeStatus // empty')" ]; then
|
||||||
|
tailscale set --exit-node="$node" \
|
||||||
|
&& logger -t federated-connector "Online again: using exit node $node again"
|
||||||
|
fi
|
||||||
|
rm -f "$PAUSED"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Save files sent with Taildrop to Downloads
|
||||||
|
PartOf=graphical-session.target
|
||||||
|
After=graphical-session.target
|
||||||
|
# Only once this computer has joined your Core's Tailscale network
|
||||||
|
# (configure tailscale starts it then)
|
||||||
|
ConditionPathExists=%h/.config/federated-connector/tailscale.conf
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=%h/.local/share/federated-connector/connector/system/taildrop
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=30
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=graphical-session.target
|
||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Purpose : Save files sent to this computer with Taildrop (tailscale file cp,
|
||||||
|
# or Tailscale's apps) to your Downloads folder, and say so in a
|
||||||
|
# notification. Run by federated-connector-taildrop.service, which
|
||||||
|
# configure tailscale turns on.
|
||||||
|
|
||||||
|
dir="$(xdg-user-dir DOWNLOAD 2> /dev/null)"
|
||||||
|
[ -n "$dir" ] && [ "$dir" != "$HOME" ] || dir="$HOME/Downloads"
|
||||||
|
|
||||||
|
# The files tailscale file get --verbose reports writing, one per line
|
||||||
|
received() {
|
||||||
|
sed -nE 's/.*wrote .* as (.*) \([0-9]+ bytes\).*/\1/p' <<< "$1" | xargs -r -d '\n' -n 1 basename
|
||||||
|
}
|
||||||
|
|
||||||
|
notify() {
|
||||||
|
local names=() title body action
|
||||||
|
mapfile -t names < <(received "$1")
|
||||||
|
if (( ${#names[@]} == 1 )); then
|
||||||
|
title="Received ${names[0]}"
|
||||||
|
elif (( ${#names[@]} > 1 )); then
|
||||||
|
title="Received ${#names[@]} files"
|
||||||
|
body="$(printf '%s\n' "${names[@]}")"
|
||||||
|
else
|
||||||
|
title="Received files"
|
||||||
|
fi
|
||||||
|
action="$(notify-send --app-name=Tailscale --icon=folder-download --action=open="Show" \
|
||||||
|
"$title" "${body:-In $(basename "$dir")}")"
|
||||||
|
[ "$action" = open ] && xdg-open "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
mkdir -p "$dir"
|
||||||
|
# Waits for files, saves them, and returns. It fails at once when Tailscale
|
||||||
|
# isn't running or this computer is off the network; wait, then try again.
|
||||||
|
if output="$(tailscale file get --wait --conflict=rename --verbose "$dir" 2>&1)"; then
|
||||||
|
notify "$output" &
|
||||||
|
else
|
||||||
|
sleep 60
|
||||||
|
fi
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user