diff --git a/PLAN.md b/PLAN.md index ff07316..422d62c 100644 --- a/PLAN.md +++ b/PLAN.md @@ -53,19 +53,13 @@ Since `4a4a3bd`, to look at: and its later checks from `d5925fa` (what root runs is root's alone) and `53c6c8b` (the install path). Hiding the connector's settings from 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 containers: only if the connector ever installs Docker -Arch or GNOME only, nothing to port: `e14a345` and `ba4dc17` (login screen -logo), `1e2581d` (kernel modules), `d456e31` (initramfs), `5d7db2c` (reboot -after update: Pop!_OS' own updates handle this). +Arch or GNOME only, nothing to port: from `9dc5eb1`, the pacman guard, unowned +files and `hardware.sh` (System76 does its own); `e14a345` and `ba4dc17` +(login screen logo), `1e2581d` (kernel modules), `d456e31` (initramfs), +`5d7db2c` (reboot after update: Pop!_OS' own updates handle this). ## Pop!_OS-specific diff --git a/README.md b/README.md index e9bff0d..dfc8795 100644 --- a/README.md +++ b/README.md @@ -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. - **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. -- **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 :`, 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). - 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. @@ -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 - The backup's app password and passphrase: your keyring, attributes `federated-connector backup` - 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 - Federated Connector itself: `~/.local/share/federated-connector/connector`, with `configure` and `update` linked in `~/.local/bin` - 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`. - 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. -- `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`. diff --git a/TEST.md b/TEST.md index 0a2d4db..8223916 100644 --- a/TEST.md +++ b/TEST.md @@ -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` shows the other machines +- [ ] A file sent from another computer (`tailscale file cp f :`) + 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 diff --git a/configure.d/15-tailscale.sh b/configure.d/15-tailscale.sh index 09dc7a1..c581677 100644 --- a/configure.d/15-tailscale.sh +++ b/configure.d/15-tailscale.sh @@ -10,6 +10,11 @@ CORE_CONF="$CONF_DIR/core.conf" TAILSCALE_CONF="$CONF_DIR/tailscale.conf" [ -f "$CORE_CONF" ] && source "$CORE_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 # 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 } -# 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 ... :" +} + +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() { - [ -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 @@ -47,11 +85,18 @@ is_configured() { leave_network() { sudo tailscale logout || return 1 rm -f "$TAILSCALE_CONF" + remove_extras echo "This computer has left your Core's Tailscale network. To join again: configure tailscale" } run_configure() { 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 echo "This computer is on $TAILSCALE_DOMAIN's Tailscale network (headscale.$TAILSCALE_DOMAIN)." echo @@ -90,4 +135,5 @@ run_configure() { mkdir -p "$(dirname "$TAILSCALE_CONF")" printf 'TAILSCALE_DOMAIN=%q\n' "$CORE_DOMAIN" > "$TAILSCALE_CONF" echo "This computer is on your Core's Tailscale network." + install_extras } diff --git a/install.sh b/install.sh index 94817f0..4217f2e 100755 --- a/install.sh +++ b/install.sh @@ -190,7 +190,7 @@ put_on_path() { } # 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() { local unit changed=0 for unit in "$CONNECTOR"/system/systemd/*; do @@ -199,15 +199,28 @@ refresh_units() { cp "$unit" "$UNITS/" && changed=1 done [ $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 - systemctl --user restart federated-connector-email-watch.service 2> /dev/null - fi + for unit in federated-connector-email-watch.service federated-connector-taildrop.service; do + if systemctl --user is-active -q "$unit" 2> /dev/null; then + systemctl --user restart "$unit" 2> /dev/null + fi + done 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() { local update=0 installed latest log [ "$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" [ -n "$log" ] && exec > >(tee -a "$log") 2>&1 diff --git a/smoketest/README.md b/smoketest/README.md index 3af828d..eae3737 100644 --- a/smoketest/README.md +++ b/smoketest/README.md @@ -38,6 +38,7 @@ Each run writes its logs to `smoketest/results/