Add upgrade safeguards, hardware setup, sign-in options and Taildrop from Omarchy
shellcheck / shellcheck (push) Failing after 19s

Adapted from Omarchy (github.com/omacom/omarchy) for Arch with GNOME:

- A pacman hook stops a full upgrade run without update (pacman -Syu,
  yay -Syu), which would skip the snapshot and update's checks. update
  and install.sh set COREDESKTOP_ALLOW_PACMAN=1, which the hook finds on
  pacman or any process above it; you can set it too.
- When the Arch upgrade stops on files no package owns, update lists
  them and asks to move them to /var/lib/coredesktop/replaced and try
  again, putting back what the retry didn't replace. When packages
  conflict, it runs pacman again so you can choose.
- update and install keep the computer from sleeping until they finish.
- system/hardware.sh (install, and a migration): the Wi-Fi country from
  the time zone, thermald and intel-lpmd on Intel laptops, and Wi-Fi 6
  on Intel BE200/BE211 cards, whose driver gets Wi-Fi 7 wrong.
- configure security-key and configure fingerprint: touch a FIDO2 key
  or a finger instead of typing your password for sudo and polkit,
  falling back to the password. Each shows only when the hardware is
  there. The fingerprint skips to the password with the lid shut.
- webapp: put a website in the app grid as its own app window.
- Taildrop: Files' Scripts > Send with Tailscale, and a user service
  that saves files sent here to Downloads, started when configure
  tailscale joins.
- A NetworkManager dispatcher script pauses a Tailscale exit node while
  you sign in to a captive portal, and resumes it once online.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 12:08:06 -07:00
co-authored by Claude Opus 5.5
parent 5d7db2cdc8
commit 9dc5eb193d
32 changed files with 1809 additions and 9 deletions
+33 -3
View File
@@ -157,6 +157,14 @@ sudo umount /mnt
The installer adds the Vulkan driver for Intel and AMD GPUs, and Intel's video decoding driver, so videos and calls don't decode on the CPU (AMD's comes with Mesa). If there's an NVIDIA GPU and archinstall's proprietary driver wasn't chosen, it installs NVIDIA's driver: the open kernel modules for GTX 16xx / RTX 20xx and newer, or the 580xx legacy driver for older cards back to the GTX 900 series. Reboot afterwards.
### Hardware
These take effect after a reboot:
- **Wi-Fi country.** Wi-Fi uses only the channels and power allowed everywhere until it knows which country it's in. The installer adds the regulatory database (wireless-regdb) and sets the country from your time zone, in /etc/conf.d/wireless-regdom. If you set one there already, it's left alone; to change it, edit that file.
- **Intel laptops** get thermald (Sandy Bridge and newer), which keeps them cool before the firmware has to slow the CPU right down, and intel-lpmd (Alder Lake, Raptor Lake, Meteor Lake, Lunar Lake and Panther Lake), which moves background work onto the low-power cores to save battery.
- **Intel BE200 and BE211 Wi-Fi 7 cards** use Wi-Fi 6: their driver drops to its slowest rate on Wi-Fi 7 with some access points (seen on Dell XPS 14 and 16 laptops). To try Wi-Fi 7, delete /etc/modprobe.d/iwlwifi-disable-eht.conf and reboot.
### System defaults
- SSH connections notice a dropped link within a minute instead of hanging (override per host in ~/.ssh/config).
@@ -164,6 +172,8 @@ The installer adds the Vulkan driver for Intel and AMD GPUs, and Intel's video d
- Shutdown waits at most 10 seconds for a service that won't stop, instead of 90.
- If memory runs out, systemd-oomd closes the app causing it instead of the whole desktop freezing.
- Boot no longer waits for the network.
- A full upgrade run with pacman alone (`sudo pacman -Syu`, or `yay` with no arguments) stops before it changes anything and tells you to run `update`, which takes a snapshot first and does the checks that pacman alone skips (see "Keep your System Up-to-date"). Installing and removing packages work as before. To upgrade with pacman anyway, run `COREDESKTOP_ALLOW_PACMAN=1 sudo pacman -Syu`.
- If you use a Tailscale exit node, it's turned off while you sign in on a network with a sign-in page (hotels, airports, trains), whose page the exit node would otherwise block, and turned back on once you're online.
- Commands run over SSH (`ssh {machine} {command}`) can find tools in ~/.local/bin and mise.
- You log in to this machine over SSH with a key, not a password, so nobody on the same network can try to guess your password. Put your public key in ~/.ssh/authorized_keys on this machine (`ssh-copy-id` does this from the other machine). To allow passwords again, delete /etc/ssh/sshd_config.d/10-coredesktop-keys-only.conf and run `sudo systemctl reload sshd`. Machines installed earlier, where someone has logged in over SSH with a password, keep accepting passwords until you run `bash ~/.local/share/coredesktop/system/sshd.sh`.
- ssh uses Bitwarden's SSH agent while Bitwarden is running it (turn it on in Bitwarden's settings), and GNOME's otherwise. A terminal opened before Bitwarden started uses GNOME's; open a new one.
@@ -174,6 +184,7 @@ The installer adds the Vulkan driver for Intel and AMD GPUs, and Intel's video d
Besides installing software, CoreDesktop changes these settings. They're listed so you know what you're running, and so you can undo them (see "Uninstalling").
- **/etc/pacman.conf**: adds the `[federated]` repository and trusts its signing key (see Pacman above).
- **pacman hook**: /etc/pacman.d/hooks/00-coredesktop-guard.hook runs /usr/local/lib/coredesktop/pacman-guard, which stops full upgrades run without `update` (see System defaults). Delete the hook to turn it off.
- **Mirrors**: reflector rewrites /etc/pacman.d/mirrorlist once a week with fast HTTPS mirrors that synced with Arch in the last 12 hours, using /etc/xdg/reflector/reflector.conf. To choose your own mirrors, delete that file's first (CoreDesktop) line and edit the rest; to stop CoreDesktop changing your mirrors at all, add `reflector` to ~/.config/coredesktop/skip-packages.
- **SSH**: sshd is on, with key login only (/etc/ssh/sshd_config.d/10-coredesktop-keys-only.conf). The SSH client keepalives are in /etc/ssh/ssh_config.d/20-coredesktop-keepalive.conf.
- **Firewall**: ufw is on, with the rules under Firewall above, and ufw-docker's rules in /etc/ufw/after.rules.
@@ -181,12 +192,14 @@ Besides installing software, CoreDesktop changes these settings. They're listed
- **systemd**: a 10-second stop timeout (/etc/systemd/system.conf.d/ and /etc/systemd/user.conf.d/10-coredesktop-timeout.conf), systemd-oomd for apps (/etc/systemd/user/app.slice.d/10-coredesktop-oomd.conf), and NetworkManager-wait-online is masked.
- **/etc/security/pam_env.conf**: a PATH line, so SSH commands find ~/.local/bin and mise.
- **mDNS**: Avahi is on, nss-mdns is added to /etc/nsswitch.conf, and SSH is advertised in /etc/avahi/services/ssh.service.
- **Captive portals**: /etc/NetworkManager/dispatcher.d/90-coredesktop-captive-portal pauses a Tailscale exit node at a sign-in page (see System defaults), and NetworkManager-dispatcher is turned on to run it.
- **Hardware** (see Hardware above): the Wi-Fi country in /etc/conf.d/wireless-regdom, thermald and intel-lpmd on Intel laptops, and /etc/modprobe.d/iwlwifi-disable-eht.conf on Intel BE200 and BE211 cards.
- **Wi-Fi**: if iwd is turned on alongside NetworkManager (archinstall's "Copy ISO network configuration" does that), iwd and systemd-networkd are turned off, so that NetworkManager runs the network from the next restart. Choose your Wi-Fi network once in GNOME's top-right menu after that restart. If you set NetworkManager to use iwd itself (`wifi.backend=iwd`), this leaves iwd alone.
- **Services turned on**: Avahi, Bluetooth, CUPS (printing), fwupd, GDM, NetworkManager, reflector (weekly), sshd, Docker, Tailscale, ufw and systemd-oomd. Your user is added to the docker group.
- **Snapper** (btrfs only): a config for / in /etc/snapper/configs/root.
- **NVIDIA** (only if it installs the driver): /etc/mkinitcpio.conf.d/nvidia.conf and NVIDIA's suspend services.
- **Your home folder**: lines in ~/.bashrc (CoreDesktop's shell setup, ~/.local/bin on PATH, the Bitwarden SSH agent), the commands in ~/.local/bin (update, refresh, sibling, version, configure, audit, report), GNOME extensions and their settings, Claude Code's ~/.claude/settings.json if you had none, a user timer that checks for updates, and a user service that pauses your Core's email if its password stops working (see Configure).
- **configure** adds more, only for what you set up: your Nextcloud files mount and network storage in /etc/fstab (SMB passwords in /etc/coredesktop/smb, SFTP mounts as user services named coredesktop-sftp-*), printers in CUPS, GNOME Online Accounts, passwords in your GNOME keyring, and the backup timer.
- **Your home folder**: lines in ~/.bashrc (CoreDesktop's shell setup, ~/.local/bin on PATH, the Bitwarden SSH agent), the commands in ~/.local/bin (update, refresh, sibling, version, configure, audit, report, webapp), GNOME extensions and their settings, Claude Code's ~/.claude/settings.json if you had none, a user timer that checks for updates, a user service that pauses your Core's email if its password stops working (see Configure), and Taildrop's user service and "Send with Tailscale" in ~/.local/share/nautilus/scripts (see Configure).
- **configure** adds more, only for what you set up: your Nextcloud files mount and network storage in /etc/fstab (SMB passwords in /etc/coredesktop/smb, SFTP mounts as user services named coredesktop-sftp-*), printers in CUPS, GNOME Online Accounts, passwords in your GNOME keyring, the backup timer, and for a security key or fingerprint, lines in /etc/pam.d/sudo and /etc/pam.d/polkit-1 (a copy of /usr/lib/pam.d/polkit-1), with security keys in /etc/u2f_mappings and the lid check in /usr/local/lib/coredesktop/lid-closed.
## Keep your System Up-to-date
@@ -201,9 +214,11 @@ update
The script pulls the latest CoreDesktop, then runs each step in ~/.local/share/coredesktop/updates.d/ in order. Among other things it:
- stops if there's less than 10 GiB free on / (run `UPDATE_FORCE=1 update` to skip the check)
- keeps the computer from going to sleep until it's done, even if you close the lid, since an upgrade cut off part way can leave it unable to start
- snapshots / first, if Snapper is set up (see Snapshots above)
- switches to up-to-date mirrors first if yours is more than a day behind Arch, as it would otherwise miss new packages without saying so
- updates the Arch keyring, then Arch and GNOME, then AUR packages, Flatpaks, the languages you installed with mise, the pipx apps CoreDesktop installs, GNOME extensions and firmware
- if the Arch upgrade stops because files no package owns are where a package now installs its own (left by `pip`, `make install` or an old installer), lists them and asks whether to move them to /var/lib/coredesktop/replaced and try again. If the second try fails too, it puts them back. If two packages conflict and pacman needs you to choose which to keep, it runs pacman again so you can answer
- warns you not to reboot if the initramfs failed to rebuild
- runs any one-time migrations, the way existing machines pick up new CoreDesktop setup
- lists packages that were installed only because something else needed them, and are no longer needed by anything, and asks before removing them. Packages CoreDesktop installs are never on this list. To keep one you use directly off the list, run `sudo pacman -D --asexplicit <package>`
@@ -274,7 +289,7 @@ configure
It covers:
- **Your Federated Core.** Give it your Superpanel's address (e.g. https://superpanel.example.com), your Core email, name and password, and it adds Superpanel to your applications, adds your Nextcloud (calendar, contacts and files) and email to GNOME's Online Accounts, and mounts your Nextcloud files at /mnt/example.com ("example.com" in the Files sidebar), and points Element at your Core's Matrix server. For Nextcloud and the files it creates a Nextcloud app password, which you can revoke in Nextcloud under Settings > Security. You can add more Cores: run `configure core` again and choose "Add a Core". Each gets its own Superpanel, Nextcloud, email and files; Element, Tailscale and backups use your main Core (the first one, unless you choose another). "Remove a Core" takes it off this computer and revokes its app password, and leaves everything on the Core itself as it is. If you change your Core password (e.g. in Superpanel), run `configure core` and choose "Your Core password changed": email keeps your Core password, so it saves the new one there, and it signs in to Nextcloud with it, which turns the app passwords for Nextcloud, files and backups back on (Nextcloud turns them off when your password changes), then checks each of them. To check that a Core still works from this computer, run `configure core` and choose "Test a Core": it signs in to Superpanel, Nextcloud, email, your files, Element's Matrix server and backups the way this computer does, says which work, and offers to fix those that don't (asking for your Core password if a fix needs it, e.g. to make a new app password for one that was revoked), then tests again.
- **Your Core's Tailscale network.** Joins this computer to it through headscale.example.com, so you can reach your other machines on it. Set up your Core first. You sign in through a link it shows you; if this computer is on another Tailscale network, it moves it to your Core's. To leave your Core's network, run `configure tailscale` again.
- **Your Core's Tailscale network.** Joins this computer to it through headscale.example.com, so you can reach your other machines on it. Set up your Core first. You sign in through a link it shows you; if this computer is on another Tailscale network, it moves it to your Core's. To leave your Core's network, run `configure tailscale` again. Once you've joined, you can send files to your other computers on it with Taildrop: select them in Files, right-click and choose Scripts > Send with Tailscale. Files sent to this computer go to your Downloads folder, with a notification.
- **Daily backups of your home folder** to your Nextcloud files, in a .backup-{machine name} folder, with restic. Set up your Core first. 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, and leaves out caches, things that can be reinstalled, and WinBoat's Windows VM (~/winboat). To leave out more, list paths in ~/.config/coredesktop/backup-exclude, one per line. restic reaches Nextcloud directly through rclone with its own Nextcloud app password, so the backup doesn't depend on the /mnt mount. See "Restoring from a backup" below. To turn backups off, run `configure backup` again; it also offers to delete the backups from your Nextcloud files (they go to Nextcloud's trash bin).
- **Tally for Plausible**, if your main Core runs Plausible Analytics: it's pointed at plausible.example.com.
- Signing in to Claude Code, opencode and Hermes Agent and choosing their model providers.
@@ -283,9 +298,24 @@ It covers:
- **Network storage**: shared folders from other machines on your network, mounted in /mnt and added to the Files sidebar. It finds SMB servers (Windows, Samba and NAS boxes, and Macs with File Sharing on) and machines you can ssh to, or you enter an address (`smb://nas.local/files`, `sftp://me@server.local/srv/data`). An SMB share is in /etc/fstab and mounts the first time you open its folder, so a server that's off doesn't hold anything up; its password is kept in /etc/coredesktop/smb, readable only by root. An SFTP folder is mounted by sshfs as you, at login, with the SSH keys in your Bitwarden or GNOME SSH agent, so the server has to accept one of them (it can't ask for a password). Agents in the sandbox can read these folders, and change one only if you start the agent in it. "Remove one" unmounts it and takes it back out.
- **Agent sandbox**, if WinBoat is set up: the sandbox hides WinBoat's settings (~/.winboat) from agents, since they include your Windows password. To let agents read them, e.g. to have one help with WinBoat, run `configure sandbox` and switch it; switch it again to hide them. This only covers the sandboxed agents (opencode, Hermes, Cline), not Claude Code's own sandbox. Your SSH keys, password stores and the rest stay hidden either way.
- **AI servers** on your network, such as Ollama on a Mac. It finds the machines on your network over mDNS and asks each one on the ports LLM servers use (11434 Ollama, 1234 LM Studio, 8080 llama.cpp, 8000 vLLM), since LLM servers don't announce themselves; or you enter a server's address. For the server you choose, it lets the sandboxed agents reach it (that port only), adds it to opencode with its models, offers to make it Hermes' model, and lets the commands Claude Code runs reach it too. Claude Code itself keeps using Anthropic's models. A server has to accept connections from other machines: in Ollama's settings, turn on "Expose Ollama to the network"; in LM Studio, "Serve on Local Network". "Remove a server" takes it back out of all of them.
- **Security key**, if one is plugged in: a FIDO2 key (YubiKey, Nitrokey, SoloKey, ...) to touch instead of typing your password for sudo and the password prompts of GNOME's apps and settings. Without the key, they ask for your password as before. Run it again to add a spare key, or to stop using keys.
- **Fingerprint**, if this computer has a fingerprint reader: the same, with your fingerprint. It enrolls your right index finger, unless you've already enrolled one in Settings > System > Users. The login and lock screens take it too. With the laptop's lid shut, it goes straight to your password. Run it again to stop.
To set up one thing, name it, e.g. `configure hermes`; `configure --list` shows the names.
## Web apps
`webapp` puts a website in GNOME's app grid as an app of its own. It opens in its own window, without tabs or an address bar, and has its own icon in the dock:
```
webapp add "Nextcloud" https://nextcloud.example.com
webapp add "Kanban" https://kanban.example.com https://kanban.example.com/logo.png
webapp list
webapp remove "Nextcloud"
```
The icon is an image's address or file. Without one, it uses the site's own icon if it has one, or a plain icon. Web apps open in your default browser if it's based on Chromium (Helium is), and otherwise in Helium or another Chromium-based browser that's installed.
### When your Core password changes
Your email in Online Accounts keeps your Core password, so after you change it (e.g. in Superpanel), the mail server starts refusing the old one. GNOME tries it again each time your network changes, and Evolution each time it fetches mail, and after a few wrong passwords the mail server blocks this computer for a while.
+5 -1
View File
@@ -32,6 +32,7 @@ is_configured() {
leave_network() {
sudo tailscale logout || return 1
rm -f "$TAILSCALE_CONF"
systemctl --user stop coredesktop-taildrop.service 2> /dev/null
echo "This computer has left your Core's Tailscale network. To join again: configure tailscale"
}
@@ -72,5 +73,8 @@ 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."
# Save files sent here to Downloads (system/taildrop.sh)
systemctl --user restart coredesktop-taildrop.service 2> /dev/null
echo "This computer is on your Core's Tailscale network. To send files to your other"
echo "computers on it, right-click them in Files: Scripts > Send with Tailscale."
}
+107
View File
@@ -0,0 +1,107 @@
#!/bin/bash
# configure reads TITLE and DESCRIPTION
# shellcheck disable=SC2034
TITLE="Security key"
# shellcheck disable=SC2034
DESCRIPTION="Touch a security key instead of typing your password for sudo"
source "$COREDESKTOP/configure.d/lib/pam.sh"
# Root's, so nothing running as you can add a key of its own. One line per
# user: user:key:key...
U2F_MAPPINGS="${U2F_MAPPINGS:-/etc/u2f_mappings}"
# pam_u2f checks keys against the computer's name unless told otherwise, so
# renaming the computer would lock every key out. Use a name that stays.
U2F_ORIGIN="pam://coredesktop"
U2F_LINE="auth sufficient pam_u2f.so cue origin=$U2F_ORIGIN appid=$U2F_ORIGIN authfile=$U2F_MAPPINGS"
# For the tests
HIDRAW="${HIDRAW:-/sys/class/hidraw}"
# A FIDO2 key is a USB HID device whose report descriptor starts its usage page
# 0xF1D0 (bytes 06 d0 f1), which is how libfido2 finds them too
key_plugged_in() {
local descriptor
for descriptor in "$HIDRAW"/*/device/report_descriptor; do
[ -r "$descriptor" ] || continue
od -An -tx1 -v "$descriptor" | tr -d ' \n' | grep -q '06d0f1' && return 0
done
return 1
}
key_registered() {
grep -q "^$USER:" "$U2F_MAPPINGS" 2> /dev/null
}
# Shown when a key is plugged in, or one is set up already
is_installed() {
key_registered || pam_has sudo pam_u2f.so || key_plugged_in
}
is_configured() {
key_registered && pam_has sudo pam_u2f.so
}
register_key() {
local credential
if ! sudo pacman -S --needed --noconfirm libfido2 pam-u2f > /dev/null; then
echo "Couldn't install libfido2 and pam-u2f."
return 1
fi
if [ -z "$(fido2-token -L 2> /dev/null)" ]; then
echo "No security key found. Plug it in (and unlock it, if it needs that), then run: configure security-key"
return 1
fi
echo "Touch your security key when it blinks (enter its PIN first if it asks)."
credential="$(pamu2fcfg -n -o "$U2F_ORIGIN" -i "$U2F_ORIGIN")" || { echo "The key wasn't registered."; return 1; }
credential="${credential#:}"
[ -n "$credential" ] || { echo "The key wasn't registered."; return 1; }
if key_registered; then
sudo sed -i "s|^$USER:.*|&:$credential|" "$U2F_MAPPINGS" || return 1
else
echo "$USER:$credential" | sudo tee -a "$U2F_MAPPINGS" > /dev/null || return 1
fi
sudo chmod 644 "$U2F_MAPPINGS"
}
use_keys() {
local service
for service in "${PAM_SERVICES[@]}"; do
pam_add "$service" pam_u2f.so "$U2F_LINE" || return 1
done
}
stop_using_keys() {
local service
for service in "${PAM_SERVICES[@]}"; do
pam_remove "$service" '[[:space:]]pam_u2f\.so([[:space:]]|$)' || return 1
done
if [ -f "$U2F_MAPPINGS" ]; then
sudo sed -i "/^$USER:/d" "$U2F_MAPPINGS" || return 1
fi
echo "sudo and the password prompts ask for your password only."
}
run_configure() {
local choice
if is_configured; then
echo "sudo and the password prompts take a touch of your security key."
echo
echo " 1) Add another key"
echo " 2) Stop using security keys"
echo " q) Leave it as it is"
echo
read -rp "Choose: " choice
case "$choice" in
1) ;;
2) stop_using_keys; return ;;
*) return 0 ;;
esac
fi
register_key || return 1
use_keys || return 1
echo "Done. sudo and the password prompts now ask you to touch your key. Without it,"
echo "they ask for your password, as before. To add a spare key: configure security-key"
}
+126
View File
@@ -0,0 +1,126 @@
#!/bin/bash
# configure reads TITLE and DESCRIPTION
# shellcheck disable=SC2034
TITLE="Fingerprint"
# shellcheck disable=SC2034
DESCRIPTION="Use your fingerprint instead of typing your password"
source "$COREDESKTOP/configure.d/lib/pam.sh"
# With the lid shut the reader can't be touched, and sudo would wait for it to
# time out. This skips the fingerprint then, straight to the password.
LID_CLOSED="${LID_CLOSED:-/usr/local/lib/coredesktop/lid-closed}"
FPRINT_LINES=(
"auth [success=1 default=ignore] pam_exec.so quiet $LID_CLOSED"
"auth sufficient pam_fprintd.so"
)
# For the tests
USB_DEVICES="${USB_DEVICES:-/sys/bus/usb/devices}"
# Vendors whose USB devices are fingerprint readers (Goodix, Validity,
# Synaptics, AuthenTec, Upek, LighTuning), adapted from Omarchy. Elan and FPC
# readers name themselves instead.
FPRINT_VENDORS=" 27c6 138a 06cb 08ff 1c7a 147e "
# libfprint drives a reader from userspace, so no kernel driver claims it. The
# same vendors' touchpads and cameras have one (usbfs is libusb's own).
has_kernel_driver() {
local interface driver
for interface in "$1"/*:*; do
[ -e "$interface/driver" ] || continue
driver="$(readlink -f "$interface/driver")"
[ "${driver##*/}" = usbfs ] || return 0
done
return 1
}
reader_present() {
local device product vendor
for device in "$USB_DEVICES"/*; do
if [ -r "$device/product" ]; then
product="$(< "$device/product")"
product="${product,,}"
[[ "$product" == *fingerprint* || "$product" == *biometric* \
|| "$product" == *elan:arm-m4* || "$product" == "fpc "* ]] && return 0
fi
if [ -r "$device/idVendor" ]; then
vendor="$(< "$device/idVendor")"
[[ "$FPRINT_VENDORS" == *" $vendor "* ]] && ! has_kernel_driver "$device" && return 0
fi
done
return 1
}
fingers_enrolled() {
fprintd-list "$USER" 2> /dev/null | grep -qE '^[[:space:]]*- #[0-9]+:'
}
# Shown on computers with a reader
is_installed() {
pam_has sudo pam_fprintd.so || reader_present
}
is_configured() {
pam_has sudo pam_fprintd.so && fingers_enrolled
}
install_lid_check() {
sudo install -d -m 755 "$(dirname "$LID_CLOSED")" || return 1
sudo tee "$LID_CLOSED" > /dev/null << 'EOF' || return 1
#!/bin/sh
# CoreDesktop: true when the laptop's lid is shut, so PAM skips the fingerprint
# reader, which can't be touched then (configure.d/71-fingerprint.sh)
for state in /proc/acpi/button/lid/*/state; do
grep -q closed "$state" 2> /dev/null && exit 0
done
exit 1
EOF
sudo chmod 755 "$LID_CLOSED"
}
use_fingerprint() {
local service
install_lid_check || return 1
for service in "${PAM_SERVICES[@]}"; do
pam_add "$service" pam_fprintd.so "${FPRINT_LINES[@]}" || return 1
done
}
stop_using_fingerprint() {
local service
for service in "${PAM_SERVICES[@]}"; do
pam_remove "$service" "[[:space:]](pam_fprintd\.so|${LID_CLOSED//./\\.})([[:space:]]|$)" || return 1
done
echo "sudo and the password prompts ask for your password only. The login and lock"
echo "screens take your fingerprint until you delete it in Settings > System > Users."
}
run_configure() {
local choice
if is_configured; then
echo "sudo and the password prompts take your fingerprint. To add or delete fingers:"
echo "Settings > System > Users > Fingerprint Login."
echo
echo " 1) Stop using your fingerprint for sudo and the password prompts"
echo " q) Leave it as it is"
echo
read -rp "Choose: " choice
[ "$choice" = 1 ] && stop_using_fingerprint
return
fi
if ! sudo pacman -S --needed --noconfirm fprintd > /dev/null; then
echo "Couldn't install fprintd."
return 1
fi
# Enrolled already, in GNOME's Settings, say
if ! fingers_enrolled; then
echo "Touch the fingerprint reader with your right index finger, again and again until"
echo "it says it's done."
fprintd-enroll "$USER" || { echo "Your finger wasn't enrolled."; return 1; }
fi
use_fingerprint || return 1
echo "Done. sudo, the password prompts, and the login and lock screens take your"
echo "fingerprint, and your password as before. To add fingers: Settings > System > Users."
}
+56
View File
@@ -0,0 +1,56 @@
#!/bin/bash
#
# Add and remove an auth line at the top of a PAM service's stack, for signing
# in to sudo and polkit (the password prompts of GNOME's apps and settings)
# with a security key or a fingerprint. Each line is "sufficient": when the key
# or finger isn't there, it falls through to the password, as before.
# For the tests
PAM_DIR="${PAM_DIR:-/etc/pam.d}"
PAM_VENDOR_DIR="${PAM_VENDOR_DIR:-/usr/lib/pam.d}"
# The services to sign in to this way (used by the items that source this)
# shellcheck disable=SC2034
PAM_SERVICES=(sudo polkit-1)
# True if service $1's stack uses module $2 (pam_u2f.so)
pam_has() {
grep -qE "^[^#]*[[:space:]]$2([[:space:]]|$)" "$PAM_DIR/$1" 2> /dev/null
}
# Make sure service $1 has its own file in PAM_DIR. polkit's comes in
# PAM_VENDOR_DIR, and a file in PAM_DIR replaces it.
pam_own_file() {
[ -f "$PAM_DIR/$1" ] && return 0
[ -f "$PAM_VENDOR_DIR/$1" ] || { echo "There's no PAM file for $1."; return 1; }
sudo cp "$PAM_VENDOR_DIR/$1" "$PAM_DIR/$1"
}
# pam_add SERVICE MODULE LINE...: put the lines just before the first auth line
# of SERVICE's stack, unless it already uses MODULE
pam_add() {
local service="$1" module="$2" file
shift 2
file="$PAM_DIR/$service"
pam_has "$service" "$module" && return 0
pam_own_file "$service" || return 1
grep -qE '^[[:space:]]*-?auth[[:space:]]' "$file" || { echo "$file has no auth lines."; return 1; }
# awk writes the new file, then it replaces the old one in one step, so sudo
# never sees a half-written file
PAM_LINES="$(printf '%s\n' "$@")" awk '
!done && /^[[:space:]]*-?auth[[:space:]]/ { print ENVIRON["PAM_LINES"]; done = 1 }
{ print }
' "$file" | sudo tee "$file.coredesktop" > /dev/null \
&& sudo chmod 644 "$file.coredesktop" \
&& sudo mv -f "$file.coredesktop" "$file"
}
# pam_remove SERVICE PATTERN: remove the lines matching PATTERN (an extended
# regular expression) from SERVICE's stack
pam_remove() {
local file="$PAM_DIR/$1"
[ -f "$file" ] && grep -qE "$2" "$file" || return 0
grep -vE "$2" "$file" | sudo tee "$file.coredesktop" > /dev/null \
&& sudo chmod 644 "$file.coredesktop" \
&& sudo mv -f "$file.coredesktop" "$file"
}
+28 -1
View File
@@ -82,6 +82,17 @@ on_exit() {
}
trap on_exit EXIT
# Keep the computer from suspending, from idle or a closed lid, until the
# install exits. tail exits with it, and that ends the inhibitor.
if command -v systemd-inhibit > /dev/null; then
systemd-inhibit --what=sleep:idle --who=CoreDesktop --why="Installing CoreDesktop" --mode=block \
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
fi
# Lets the install's pacman upgrade the system past the guard that stops
# upgrades run without update (system/pacman-guard)
export COREDESKTOP_ALLOW_PACMAN=1
# Ensure git is available before attempting to clone anything
if ! command -v git &> /dev/null; then
echo "Installing git..."
@@ -103,7 +114,7 @@ cd ~/.local/share/coredesktop
# Source utility functions (provides install_packages and other helpers)
source utils.sh
# Install the refresh, update, sibling, version, configure, audit and report scripts to the user's bin
# Install the refresh, update, sibling, version, configure, audit, report and webapp scripts to the user's bin
mkdir -p ~/.local/bin
install_script ~/.local/share/coredesktop/refresh ~/.local/bin/refresh
install_script ~/.local/share/coredesktop/update ~/.local/bin/update
@@ -112,6 +123,7 @@ install_script ~/.local/share/coredesktop/version ~/.local/bin/version
install_script ~/.local/share/coredesktop/configure ~/.local/bin/configure
install_script ~/.local/share/coredesktop/audit ~/.local/bin/audit
install_script ~/.local/share/coredesktop/report ~/.local/bin/report
install_script ~/.local/share/coredesktop/webapp ~/.local/bin/webapp
# Source the package list (defines SYSTEM_UTILS, DEV_TOOLS, DESKTOP, etc. arrays)
if [ ! -f "packages.conf" ]; then
@@ -255,6 +267,10 @@ bash ~/.local/share/coredesktop/system/firewall.sh
echo "Configuring package mirrors..."
bash ~/.local/share/coredesktop/system/mirrors.sh
# Stop full upgrades with pacman alone, which skip update's snapshot and checks
echo "Configuring the pacman upgrade guard..."
bash ~/.local/share/coredesktop/system/pacman-guard.sh
# Snapshot / before each update (btrfs only)
echo "Configuring Snapper..."
bash ~/.local/share/coredesktop/system/snapper.sh
@@ -263,6 +279,10 @@ echo "Installing GPU drivers..."
bash ~/.local/share/coredesktop/system/vulkan.sh
bash ~/.local/share/coredesktop/system/nvidia.sh
# Wi-Fi country, Intel laptops' power daemons, Intel Wi-Fi 7 cards
echo "Setting up for this hardware..."
bash ~/.local/share/coredesktop/system/hardware.sh
# Prompt, zoxide, fzf key bindings, aliases and functions
echo "Configuring the shell..."
bash ~/.local/share/coredesktop/shell/setup.sh
@@ -278,6 +298,13 @@ bash ~/.local/share/coredesktop/system/update-notify.sh
echo "Configuring email password checks..."
bash ~/.local/share/coredesktop/system/email-watch.sh
# Send and receive files on your Core's Tailscale network
echo "Configuring Taildrop..."
bash ~/.local/share/coredesktop/system/taildrop.sh
# Stop using a Tailscale exit node while signing in to a captive portal
bash ~/.local/share/coredesktop/system/captive-portal.sh
# Apply GNOME dconf settings only if the settings file has changed since last run
bash ~/.local/share/coredesktop/gnome/apply-gnome-settings.sh
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
# Set the Wi-Fi country from the time zone, run thermald and intel-lpmd on
# Intel laptops, and use Wi-Fi 6 on Intel BE200/BE211 cards
bash "$HOME/.local/share/coredesktop/system/hardware.sh"
+1 -1
View File
@@ -24,7 +24,7 @@ scenario() {
echo \"Not in the archive yet, removing: \"\$newer
sudo pacman -Rdd --noconfirm \$newer
fi
sudo pacman -Suu --noconfirm"
COREDESKTOP_ALLOW_PACMAN=1 sudo pacman -Suu --noconfirm"
[ "$STATUS" -eq 0 ] || skip "couldn't downgrade to Arch as of $date (see $LAST_LOG)"
vm_reboot
kernel_before="$(vm_value 'uname -r')"
+42
View File
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Purpose : NetworkManager runs this as root when the network's connectivity
# changes (system/captive-portal.sh 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 GNOME's sign-in
# window stays blank. Stop using the exit node until you've signed
# in, then use it again.
# For the tests
PAUSED="${CAPTIVE_PORTAL_STATE:-/run/coredesktop-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 coredesktop "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 coredesktop "Online again: using exit node $node again"
fi
rm -f "$PAUSED"
;;
esac
exit 0
+26
View File
@@ -0,0 +1,26 @@
#!/bin/bash
#
# Purpose : Install the NetworkManager dispatcher script that stops using a
# Tailscale exit node while you sign in to a captive portal
# (system/captive-portal). Run by install.sh and on every update
# (updates.d/19-captive-portal.sh), so changes reach existing
# machines.
set -e
COREDESKTOP="${COREDESKTOP:-$HOME/.local/share/coredesktop}"
source "$COREDESKTOP/utils.sh"
# For the tests
ROOT="${CAPTIVE_PORTAL_ROOT:-}"
SCRIPT="$ROOT/etc/NetworkManager/dispatcher.d/90-coredesktop-captive-portal"
# NetworkManager runs only dispatcher scripts that root owns and only root can
# change
if ! cmp -s "$COREDESKTOP/system/captive-portal" "$SCRIPT"; then
echo "Installing the captive portal helper for Tailscale exit nodes..."
sudo install -D -m 755 "$COREDESKTOP/system/captive-portal" "$SCRIPT"
fi
# NetworkManager starts its dispatcher by its D-Bus name, which enabling it adds
enable_services NetworkManager-dispatcher.service > /dev/null
+112
View File
@@ -0,0 +1,112 @@
#!/bin/bash
#
# Purpose : Set up what particular hardware needs, adapted from Omarchy:
# - Wi-Fi: the regulatory database, and the country from your time
# zone, so Wi-Fi can use the channels and power allowed there
# - Intel laptops: thermald and intel-lpmd, for cooler running and
# longer battery life
# - Intel BE200/BE211 Wi-Fi cards: Wi-Fi 6 instead of Wi-Fi 7, which
# their driver gets wrong
# Each takes effect after a reboot.
set -e
COREDESKTOP="${COREDESKTOP:-$HOME/.local/share/coredesktop}"
source "$COREDESKTOP/utils.sh"
# For the tests: read /sys, /proc, /etc and /usr from under here
ROOT="${HARDWARE_ROOT:-}"
has_wifi() {
compgen -G "$ROOT/sys/class/ieee80211/*" > /dev/null
}
has_battery() {
compgen -G "$ROOT/sys/class/power_supply/BAT*" > /dev/null
}
# A field of the first CPU in /proc/cpuinfo, e.g. vendor_id or model
cpu_field() {
sed -nE "s/^$1[[:space:]]*:[[:space:]]*//p" "$ROOT/proc/cpuinfo" 2> /dev/null | head -n 1
}
intel_cpu() {
[ "$(cpu_field vendor_id)" = GenuineIntel ] && [ "$(cpu_field 'cpu family')" = 6 ]
}
# PCI devices, as vendor:device (8086:272b)
pci_ids() {
local device
for device in "$ROOT"/sys/bus/pci/devices/*; do
[ -r "$device/vendor" ] && [ -r "$device/device" ] || continue
echo "$(sed 's/^0x//' "$device/vendor"):$(sed 's/^0x//' "$device/device")"
done
}
# The two-letter country of the time zone /etc/localtime points at
timezone_country() {
local zone
zone="$(readlink -f "$ROOT/etc/localtime" 2> /dev/null)" || return 1
zone="${zone#*/zoneinfo/}"
[ -n "$zone" ] || return 1
awk -v zone="$zone" '!/^#/ && $3 == zone { print $1; exit }' "$ROOT/usr/share/zoneinfo/zone.tab" 2> /dev/null
}
# Wi-Fi starts in the "world" regulatory domain, the channels and power allowed
# everywhere, until it knows the country. wireless-regdb holds each country's
# rules, and sets the one in /etc/conf.d/wireless-regdom at boot.
setup_wifi_country() {
local conf="$ROOT/etc/conf.d/wireless-regdom" country
has_wifi || return 0
install_packages wireless-regdb
# Set already, by you or before
grep -qE '^[[:space:]]*WIRELESS_REGDOM=' "$conf" 2> /dev/null && return 0
country="$(timezone_country)"
if [[ ! "$country" =~ ^[A-Z]{2}$ ]]; then
echo "Couldn't tell the country from the time zone; set it in /etc/conf.d/wireless-regdom."
return 0
fi
echo "Setting the Wi-Fi country to $country (from the time zone)..."
echo "WIRELESS_REGDOM=\"$country\"" | sudo tee -a "$conf" > /dev/null
}
# thermald keeps Intel laptops from overheating before the firmware has to
# throttle hard. Sandy Bridge (model 42) and newer.
# intel-lpmd moves background work onto the low-power cores of Intel's hybrid
# CPUs: Alder Lake, Raptor Lake, Meteor Lake, Lunar Lake and Panther Lake.
setup_intel_laptop() {
local model
intel_cpu && has_battery || return 0
model="$(cpu_field model)"
[[ "$model" =~ ^[0-9]+$ ]] || return 0
if (( model >= 42 )); then
install_packages thermald
enable_services thermald.service
fi
if [[ " 151 154 170 172 183 186 189 191 204 " == *" $model "* ]]; then
install_packages intel-lpmd
enable_services intel_lpmd.service
fi
}
# Intel's BE200 (8086:272b) and BE211 (8086:e440) Wi-Fi 7 cards: with Wi-Fi 7
# (802.11be) the iwlwifi driver drops to its slowest rate, which makes Wi-Fi
# unusable on some access points (seen on Dell XPS 14 and 16). Wi-Fi 6 runs at
# full speed. Remove the file once Intel fixes the driver.
setup_intel_wifi7() {
local conf="$ROOT/etc/modprobe.d/iwlwifi-disable-eht.conf"
pci_ids | grep -qxE '8086:(272b|e440)' || return 0
[ -f "$conf" ] && return 0
echo "Using Wi-Fi 6 on this Intel Wi-Fi 7 card, whose driver gets Wi-Fi 7 wrong..."
sudo install -d -m 755 "$(dirname "$conf")"
sudo tee "$conf" > /dev/null << 'EOF'
# CoreDesktop (system/hardware.sh): Intel BE200/BE211 cards fall to their
# slowest rate with Wi-Fi 7 (802.11be). Use Wi-Fi 6 until the iwlwifi driver
# is fixed; delete this file to try Wi-Fi 7 again.
options iwlwifi disable_11be=Y
EOF
}
setup_wifi_country
setup_intel_laptop
setup_intel_wifi7
+61
View File
@@ -0,0 +1,61 @@
#!/bin/bash
#
# Purpose : Stop a full system upgrade (pacman -Syu, yay -Syu, ...) that isn't
# run by CoreDesktop's update or install. pacman runs this as root
# before each transaction (system/pacman-guard.sh installs the hook);
# exiting non-zero aborts it.
#
# update skips its snapshot, keyring, mirror and initramfs checks, migrations
# and AUR rebuilds when pacman upgrades the system on its own. update and
# install.sh export COREDESKTOP_ALLOW_PACMAN=1, and so can you to get past this:
# COREDESKTOP_ALLOW_PACMAN=1 sudo pacman -Syu
# For the tests: where to read processes from, and which process is pacman
PROC="${PACMAN_GUARD_PROC:-/proc}"
pacman_pid="${PACMAN_GUARD_PID:-$PPID}"
# pacman's arguments, one per line. pacman runs its hooks itself, so it's the
# parent.
args=()
[ -r "$PROC/$pacman_pid/cmdline" ] && mapfile -d '' -t args < "$PROC/$pacman_pid/cmdline"
sync=0 sysupgrade=0
for arg in "${args[@]:1}"; do
case "$arg" in
--) break ;;
--sync) sync=1 ;;
--sysupgrade) sysupgrade=1 ;;
--*) ;;
-*)
[[ "$arg" == *S* ]] && sync=1
[[ "$arg" == *u* ]] && sysupgrade=1 ;;
esac
done
(( sync && sysupgrade )) || exit 0
# Allowed when pacman or any process that started it has the variable: sudo
# drops it from pacman's environment, but the sudo process itself still has it
pid="$pacman_pid"
while [[ "$pid" =~ ^[0-9]+$ ]] && (( pid > 1 )); do
if tr '\0' '\n' < "$PROC/$pid/environ" 2> /dev/null | grep -qx 'COREDESKTOP_ALLOW_PACMAN=1'; then
exit 0
fi
pid="$(awk '/^PPid:/ { print $2 }' "$PROC/$pid/status" 2> /dev/null)"
done
cat >&2 << 'EOF'
This is a full system upgrade outside CoreDesktop's update, so pacman stopped
before changing anything. Run this instead:
update
update also takes a snapshot first, updates the keyring and mirrors, checks the
new initramfs, runs CoreDesktop's migrations and updates the AUR packages.
To upgrade with pacman alone anyway:
COREDESKTOP_ALLOW_PACMAN=1 sudo pacman -Syu
EOF
exit 1
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Purpose : Install the pacman hook that stops a full system upgrade not run by
# CoreDesktop's update (system/pacman-guard). Run by install.sh and
# on every update (updates.d/11-pacman-guard.sh), so changes to it
# reach existing machines.
set -e
COREDESKTOP="${COREDESKTOP:-$HOME/.local/share/coredesktop}"
# For the tests
ROOT="${PACMAN_GUARD_ROOT:-}"
GUARD="$ROOT/usr/local/lib/coredesktop/pacman-guard"
HOOK="$ROOT/etc/pacman.d/hooks/00-coredesktop-guard.hook"
# The hook runs the copy in /usr/local as root, so it mustn't be one you can
# edit without sudo
if ! cmp -s "$COREDESKTOP/system/pacman-guard" "$GUARD"; then
echo "Installing the pacman upgrade guard..."
sudo install -D -m 755 "$COREDESKTOP/system/pacman-guard" "$GUARD"
fi
HOOK_TEXT="[Trigger]
Operation = Upgrade
Type = Package
Target = *
[Action]
Description = Checking this upgrade is run by CoreDesktop's update...
When = PreTransaction
Exec = /usr/local/lib/coredesktop/pacman-guard
AbortOnFail"
if [ "$(cat "$HOOK" 2> /dev/null)" != "$HOOK_TEXT" ]; then
sudo install -d -m 755 "$(dirname "$HOOK")"
printf '%s\n' "$HOOK_TEXT" | sudo tee "$HOOK" > /dev/null
fi
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
#
# Purpose : Files' right-click Scripts > "Send with Tailscale": send the
# selected files with Taildrop to a computer you choose on your
# Tailscale network. system/taildrop.sh installs it in Nautilus'
# scripts folder. Also works from a terminal:
# send-with-tailscale file...
files=()
if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
mapfile -t files <<< "${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS%$'\n'}"
else
files=("$@")
fi
fail() {
notify-send --app-name=Tailscale --icon=dialog-error "$1" "$2"
exit 1
}
regular=()
for file in "${files[@]}"; do
[ -f "$file" ] && regular+=("$file")
done
(( ${#regular[@]} > 0 )) || fail "Nothing to send" "Taildrop sends files, not folders. Choose files."
# Lines of "address<TAB>name" for the computers that can take files
mapfile -t targets < <(tailscale file cp --targets 2> /dev/null)
(( ${#targets[@]} > 0 )) \
|| fail "No computer to send to" "None of your computers on your Tailscale network is online to take files."
rows=()
for target in "${targets[@]}"; do
IFS=$'\t' read -r address name _ <<< "$target"
rows+=("$name" "$address")
done
address="$(zenity --list --title="Send with Tailscale" --text="Send ${#regular[@]} file(s) to:" \
--column=Computer --column=Address --print-column=2 --hide-column=2 --height=360 "${rows[@]}")" || exit 0
[ -n "$address" ] || exit 0
for (( i = 1; i < ${#rows[@]}; i += 2 )); do
[ "${rows[$i]}" = "$address" ] && name="${rows[$((i - 1))]}"
done
if error="$(tailscale file cp --update-interval=0 -- "${regular[@]}" "$address:" 2>&1)"; then
if (( ${#regular[@]} == 1 )); then
notify-send --app-name=Tailscale --icon=document-send "Sent to $name" "$(basename "${regular[0]}")"
else
notify-send --app-name=Tailscale --icon=document-send "Sent to $name" "${#regular[@]} files"
fi
else
fail "Couldn't send to $name" "$error"
fi
@@ -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/coredesktop/tailscale.conf
[Service]
ExecStart=%h/.local/share/coredesktop/system/taildrop
Restart=on-failure
RestartSec=30
[Install]
WantedBy=graphical-session.target
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
#
# Purpose : Save files sent to this computer with Taildrop (from Files' "Send
# with Tailscale", tailscale file cp, or Tailscale's apps) to your
# Downloads folder, and say so in a notification. Run by
# coredesktop-taildrop.service (system/taildrop.sh).
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
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
#
# Purpose : Send and receive files with Taildrop on your Core's Tailscale
# network: Files' right-click Scripts > "Send with Tailscale"
# (system/send-with-tailscale), and the service that saves files
# sent here to Downloads (system/taildrop). Run by install.sh and on
# every update (updates.d/18-taildrop.sh), so changes reach existing
# machines.
set -e
COREDESKTOP="${COREDESKTOP:-$HOME/.local/share/coredesktop}"
UNITS="$HOME/.config/systemd/user"
SCRIPTS="$HOME/.local/share/nautilus/scripts"
command -v tailscale > /dev/null || exit 0
mkdir -p "$SCRIPTS"
install -m 755 "$COREDESKTOP/system/send-with-tailscale" "$SCRIPTS/Send with Tailscale"
mkdir -p "$UNITS"
cp "$COREDESKTOP/system/systemd/coredesktop-taildrop.service" "$UNITS/"
systemctl --user daemon-reload
systemctl --user enable coredesktop-taildrop.service
# Restart, so it runs the version update just pulled. It doesn't start until
# configure tailscale has joined the network.
systemctl --user restart coredesktop-taildrop.service
+114
View File
@@ -0,0 +1,114 @@
#!/usr/bin/env bats
load test_helper
# system/hardware.sh on a fake machine under $HARDWARE_ROOT, with fake pacman,
# yay, sudo and systemctl
setup() {
common_setup
export COREDESKTOP="$REPO"
export HARDWARE_ROOT="$BATS_TEST_TMPDIR/root"
R="$HARDWARE_ROOT"
mkdir -p "$R/sys/class/ieee80211" "$R/sys/class/power_supply" "$R/sys/bus/pci/devices" \
"$R/proc" "$R/etc/conf.d" "$R/usr/share/zoneinfo/Europe"
printf '# Countries\nUS\t+404251-0740023\tAmerica/New_York\nDE\t+5230+01322\tEurope/Berlin\n' \
> "$R/usr/share/zoneinfo/zone.tab"
touch "$R/usr/share/zoneinfo/Europe/Berlin"
ln -s "$R/usr/share/zoneinfo/Europe/Berlin" "$R/etc/localtime"
printf '#WIRELESS_REGDOM="DE"\n#WIRELESS_REGDOM="US"\n' > "$R/etc/conf.d/wireless-regdom"
cpu AuthenticAMD 25 33
stub pacman 'exit 1'
stub yay
stub sudo '"$@"'
stub systemctl '[ "$1" != is-enabled ]'
}
cpu() {
printf 'processor\t: 0\nvendor_id\t: %s\ncpu family\t: %s\nmodel\t\t: %s\n' "$1" "$2" "$3" > "$R/proc/cpuinfo"
}
wifi() { mkdir -p "$R/sys/class/ieee80211/phy0"; }
battery() { mkdir -p "$R/sys/class/power_supply/BAT0"; }
pci() {
mkdir -p "$R/sys/bus/pci/devices/$1"
echo "0x$2" > "$R/sys/bus/pci/devices/$1/vendor"
echo "0x$3" > "$R/sys/bus/pci/devices/$1/device"
}
@test "hardware.sh sets the Wi-Fi country from the time zone" {
wifi
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None wireless-regdb
grep -qx 'WIRELESS_REGDOM="DE"' "$R/etc/conf.d/wireless-regdom"
}
@test "hardware.sh leaves a Wi-Fi country that's set" {
wifi
echo 'WIRELESS_REGDOM="FR"' >> "$R/etc/conf.d/wireless-regdom"
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
[ "$(grep -c '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom")" -eq 1 ]
}
@test "hardware.sh says so when the time zone has no country" {
wifi
ln -sfn "$R/usr/share/zoneinfo/UTC" "$R/etc/localtime"
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Couldn't tell the country"* ]]
refute grep -q '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom"
}
@test "hardware.sh does nothing for Wi-Fi without it" {
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
not_called yay
refute grep -q '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom"
}
@test "hardware.sh runs thermald and intel-lpmd on a newer Intel laptop" {
battery
cpu GenuineIntel 6 170
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None thermald
called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None intel-lpmd
called systemctl enable thermald.service
called systemctl enable intel_lpmd.service
}
@test "hardware.sh runs only thermald on an older Intel laptop" {
battery
cpu GenuineIntel 6 142
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
called systemctl enable thermald.service
uncalled systemctl enable intel_lpmd.service
}
@test "hardware.sh leaves Intel desktops and AMD laptops alone" {
cpu GenuineIntel 6 170
run bash "$REPO/system/hardware.sh"
not_called systemctl
battery
cpu AuthenticAMD 25 33
run bash "$REPO/system/hardware.sh"
not_called systemctl
}
@test "hardware.sh turns off Wi-Fi 7 on an Intel BE200" {
pci 0000:00:14.3 8086 272b
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
grep -qx 'options iwlwifi disable_11be=Y' "$R/etc/modprobe.d/iwlwifi-disable-eht.conf"
}
@test "hardware.sh leaves other Wi-Fi cards on Wi-Fi 7" {
pci 0000:00:14.3 8086 7e40
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
[ ! -e "$R/etc/modprobe.d/iwlwifi-disable-eht.conf" ]
}
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env bats
load test_helper
# system/pacman-guard reads a fake /proc: process $1's command line and
# environment, and its parent
setup() {
common_setup
export PACMAN_GUARD_PROC="$BATS_TEST_TMPDIR/proc"
export PACMAN_GUARD_PID=300
}
# process PID PARENT "ARGS..." [ENV...]
process() {
local dir="$PACMAN_GUARD_PROC/$1"
mkdir -p "$dir"
# shellcheck disable=SC2086
printf '%s\0' $3 > "$dir/cmdline"
printf 'Name:\tx\nPPid:\t%s\n' "$2" > "$dir/status"
if (( $# > 3 )); then printf '%s\0' "${@:4}"; fi > "$dir/environ"
}
# pacman 300, started by sudo 200, started by a shell 100
processes() {
process 300 200 "$1" PATH=/usr/bin
process 200 100 "sudo $1" "${@:2}"
process 100 1 "bash" HOME=/home/me
}
@test "the guard stops pacman -Syu" {
processes "pacman -Syu"
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 1 ]
[[ "$output" == *"COREDESKTOP_ALLOW_PACMAN=1 sudo pacman -Syu"* ]]
}
@test "the guard stops every spelling of a full upgrade" {
for args in "pacman -Su" "pacman -Syyu --noconfirm" "pacman -S -u" "pacman --sync --sysupgrade" "pacman -Suu"; do
rm -rf "$PACMAN_GUARD_PROC"
processes "$args"
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 1 ]
done
}
@test "the guard lets installs, removals and partial syncs through" {
for args in "pacman -S git" "pacman -Sy git" "pacman -U /tmp/x.pkg.tar.zst" "pacman -Rns git" "pacman -D --asexplicit git" "pacman -S -- -u"; do
rm -rf "$PACMAN_GUARD_PROC"
processes "$args"
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 0 ]
done
}
@test "the guard lets update's upgrade through: sudo still has the variable" {
processes "pacman -Su --noconfirm" COREDESKTOP_ALLOW_PACMAN=1
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 0 ]
}
@test "the guard lets an upgrade through when any ancestor has the variable" {
process 300 200 "pacman -Su" PATH=/usr/bin
process 200 150 "sudo pacman -Su"
process 150 100 "yay -Syu"
process 100 1 "bash" COREDESKTOP_ALLOW_PACMAN=1
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 0 ]
}
@test "the guard isn't fooled by a variable with another value" {
processes "pacman -Syu" COREDESKTOP_ALLOW_PACMAN=0 XCOREDESKTOP_ALLOW_PACMAN=1
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 1 ]
}
@test "pacman-guard.sh installs the guard and its hook once" {
export PACMAN_GUARD_ROOT="$BATS_TEST_TMPDIR/root"
export COREDESKTOP="$REPO"
stub sudo '"$@"'
run bash "$REPO/system/pacman-guard.sh"
[ "$status" -eq 0 ]
cmp "$REPO/system/pacman-guard" "$PACMAN_GUARD_ROOT/usr/local/lib/coredesktop/pacman-guard"
[ -x "$PACMAN_GUARD_ROOT/usr/local/lib/coredesktop/pacman-guard" ]
grep -qx 'Exec = /usr/local/lib/coredesktop/pacman-guard' "$PACMAN_GUARD_ROOT/etc/pacman.d/hooks/00-coredesktop-guard.hook"
grep -qx 'AbortOnFail' "$PACMAN_GUARD_ROOT/etc/pacman.d/hooks/00-coredesktop-guard.hook"
: > "$STUB_LOG"
run bash "$REPO/system/pacman-guard.sh"
[ "$status" -eq 0 ]
not_called sudo
}
+202
View File
@@ -0,0 +1,202 @@
#!/usr/bin/env bats
load test_helper
# configure.d/lib/pam.sh and the security key and fingerprint items, on PAM
# files in the test's own directories, with a fake sudo
setup() {
common_setup
export COREDESKTOP="$REPO"
export PAM_DIR="$BATS_TEST_TMPDIR/pam.d"
export PAM_VENDOR_DIR="$BATS_TEST_TMPDIR/vendor/pam.d"
mkdir -p "$PAM_DIR" "$PAM_VENDOR_DIR"
printf '#%%PAM-1.0\nauth\t\tinclude\t\tsystem-auth\naccount\t\tinclude\t\tsystem-auth\nsession\t\tinclude\t\tsystem-auth\n' \
> "$PAM_DIR/sudo"
printf '#%%PAM-1.0\n\nauth include system-auth\naccount include system-auth\n' \
> "$PAM_VENDOR_DIR/polkit-1"
stub sudo '"$@"'
export USER=me
}
@test "pam_add puts the lines before the first auth line, once" {
source "$REPO/configure.d/lib/pam.sh"
pam_add sudo pam_test.so "auth sufficient pam_test.so a" "auth sufficient pam_other.so"
pam_add sudo pam_test.so "auth sufficient pam_test.so a"
[ "$(sed -n 2p "$PAM_DIR/sudo")" = "auth sufficient pam_test.so a" ]
[ "$(sed -n 3p "$PAM_DIR/sudo")" = "auth sufficient pam_other.so" ]
[[ "$(sed -n 4p "$PAM_DIR/sudo")" == auth*system-auth ]]
[ "$(grep -c pam_test.so "$PAM_DIR/sudo")" -eq 1 ]
}
@test "pam_add copies a vendor PAM file before changing it" {
source "$REPO/configure.d/lib/pam.sh"
pam_add polkit-1 pam_test.so "auth sufficient pam_test.so"
pam_has polkit-1 pam_test.so
refute grep -q pam_test.so "$PAM_VENDOR_DIR/polkit-1"
grep -q '^account include system-auth$' "$PAM_DIR/polkit-1"
}
@test "pam_has ignores commented-out lines" {
source "$REPO/configure.d/lib/pam.sh"
echo "#auth sufficient pam_test.so" >> "$PAM_DIR/sudo"
refute pam_has sudo pam_test.so
}
@test "pam_remove takes out only the matching lines" {
source "$REPO/configure.d/lib/pam.sh"
local before
before="$(cat "$PAM_DIR/sudo")"
pam_add sudo pam_test.so "auth sufficient pam_test.so"
pam_remove sudo 'pam_test\.so'
[ "$(cat "$PAM_DIR/sudo")" = "$before" ]
}
@test "pam_add fails on a PAM file that doesn't exist anywhere" {
source "$REPO/configure.d/lib/pam.sh"
run pam_add nothing pam_test.so "auth sufficient pam_test.so"
[ "$status" -eq 1 ]
}
# --- Security key ------------------------------------------------------------
key_setup() {
export U2F_MAPPINGS="$BATS_TEST_TMPDIR/u2f_mappings"
export HIDRAW="$BATS_TEST_TMPDIR/hidraw"
mkdir -p "$HIDRAW/hidraw0/device"
# A keyboard's report descriptor: usage page 1
printf '\x05\x01\x09\x06\xa1\x01' > "$HIDRAW/hidraw0/device/report_descriptor"
source "$REPO/configure.d/70-security-key.sh"
stub pacman
stub fido2-token 'echo "/dev/hidraw1: vendor=0x1050, product=0x0407 (Yubico YubiKey OTP+FIDO+CCID)"'
stub pamu2fcfg 'echo ":KEY1"'
}
@test "the security key item shows only when a key is plugged in or set up" {
key_setup
refute is_installed
mkdir -p "$HIDRAW/hidraw1/device"
printf '\x06\xd0\xf1\x09\x01\xa1\x01' > "$HIDRAW/hidraw1/device/report_descriptor"
is_installed
}
@test "setting up a security key registers it and adds it to sudo and polkit" {
key_setup
run run_configure
[ "$status" -eq 0 ]
[ "$(cat "$U2F_MAPPINGS")" = "me:KEY1" ]
grep -q "pam_u2f.so cue origin=pam://coredesktop appid=pam://coredesktop authfile=$U2F_MAPPINGS" "$PAM_DIR/sudo"
pam_has polkit-1 pam_u2f.so
is_configured
}
@test "a second key goes on the same line" {
key_setup
echo "other:KEYX" > "$U2F_MAPPINGS"
run run_configure
stub pamu2fcfg 'echo ":KEY2"'
run run_configure <<< 1
[ "$status" -eq 0 ]
[ "$(cat "$U2F_MAPPINGS")" = "$(printf 'other:KEYX\nme:KEY1:KEY2')" ]
[ "$(grep -c pam_u2f.so "$PAM_DIR/sudo")" -eq 1 ]
}
@test "stopping security keys takes them out of PAM and removes your keys" {
key_setup
echo "other:KEYX" > "$U2F_MAPPINGS"
run run_configure
run run_configure <<< 2
[ "$status" -eq 0 ]
refute pam_has sudo pam_u2f.so
refute pam_has polkit-1 pam_u2f.so
[ "$(cat "$U2F_MAPPINGS")" = "other:KEYX" ]
}
@test "setting up a security key fails without one plugged in, changing nothing" {
key_setup
stub fido2-token
run run_configure
[ "$status" -eq 1 ]
[[ "$output" == *"No security key found"* ]]
refute pam_has sudo pam_u2f.so
[ ! -e "$U2F_MAPPINGS" ]
}
# --- Fingerprint -------------------------------------------------------------
fingerprint_setup() {
export USB_DEVICES="$BATS_TEST_TMPDIR/usb"
export LID_CLOSED="$BATS_TEST_TMPDIR/lid-closed"
mkdir -p "$USB_DEVICES"
source "$REPO/configure.d/71-fingerprint.sh"
stub pacman
stub fprintd-list 'if [ -e "$BATS_TEST_TMPDIR/enrolled" ]; then echo "Fingerprints for user me on Goodix:"; echo " - #0: right-index-finger"; else echo "User me has no fingers enrolled for Goodix."; fi'
stub fprintd-enroll 'touch "$BATS_TEST_TMPDIR/enrolled"'
}
# usb_device NAME VENDOR [PRODUCT] [DRIVER]
usb_device() {
local dir="$USB_DEVICES/$1"
mkdir -p "$dir/$1:1.0"
echo "$2" > "$dir/idVendor"
[ -n "$3" ] && echo "$3" > "$dir/product"
if [ -n "$4" ]; then
mkdir -p "$BATS_TEST_TMPDIR/drivers/$4"
ln -s "$BATS_TEST_TMPDIR/drivers/$4" "$dir/$1:1.0/driver"
fi
return 0
}
@test "the fingerprint item finds readers by name or by vendor" {
fingerprint_setup
refute is_installed
usb_device 1-1 046d "USB Keyboard" usbhid
refute is_installed
usb_device 1-2 04f3 "ELAN:ARM-M4"
is_installed
rm -rf "${USB_DEVICES:?}"/*
usb_device 1-3 27c6
is_installed
}
@test "the fingerprint item doesn't take a reader vendor's touchpad for a reader" {
fingerprint_setup
usb_device 1-1 06cb "" usbhid
refute is_installed
# libusb's claim, while fprintd uses the reader
usb_device 1-2 06cb "" usbfs
is_installed
}
@test "setting up the fingerprint enrolls a finger and adds it to sudo and polkit" {
fingerprint_setup
usb_device 1-1 27c6
run run_configure
[ "$status" -eq 0 ]
called fprintd-enroll me
[ -x "$LID_CLOSED" ]
# The lid check comes right before pam_fprintd, so its success=1 skips it
[ "$(grep -A1 "pam_exec.so quiet $LID_CLOSED" "$PAM_DIR/sudo" | tail -n 1 | awk '{ print $3 }')" = pam_fprintd.so ]
pam_has polkit-1 pam_fprintd.so
is_configured
}
@test "setting up the fingerprint doesn't enroll again a finger enrolled in Settings" {
fingerprint_setup
touch "$BATS_TEST_TMPDIR/enrolled"
run run_configure
[ "$status" -eq 0 ]
not_called fprintd-enroll
pam_has sudo pam_fprintd.so
}
@test "stopping the fingerprint takes it and the lid check out of PAM" {
fingerprint_setup
local before
before="$(cat "$PAM_DIR/sudo")"
run run_configure
run run_configure <<< 1
[ "$status" -eq 0 ]
[ "$(cat "$PAM_DIR/sudo")" = "$before" ]
refute grep -q lid-closed "$PAM_DIR/polkit-1"
}
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/env bats
load test_helper
# Taildrop: Files' "Send with Tailscale" script, and the captive portal helper,
# with a fake tailscale
setup() {
common_setup
stub notify-send
echo one > "$BATS_TEST_TMPDIR/one.txt"
echo two > "$BATS_TEST_TMPDIR/two.txt"
mkdir "$BATS_TEST_TMPDIR/folder"
stub tailscale 'if [ "$3" = --targets ]; then printf "100.64.0.2\tlaptop\n100.64.0.3\tdesktop\n"; fi'
stub zenity 'echo 100.64.0.3'
}
@test "Send with Tailscale sends the chosen files to the chosen computer" {
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS="$BATS_TEST_TMPDIR/one.txt"$'\n'"$BATS_TEST_TMPDIR/folder"$'\n'"$BATS_TEST_TMPDIR/two.txt"$'\n' \
run bash "$REPO/system/send-with-tailscale"
[ "$status" -eq 0 ]
called tailscale file cp --update-interval=0 -- "$BATS_TEST_TMPDIR/one.txt" "$BATS_TEST_TMPDIR/two.txt" 100.64.0.3:
grep -q '^notify-send .*Sent to desktop 2 files$' "$STUB_LOG"
}
@test "Send with Tailscale does nothing when the choice is cancelled" {
stub zenity 'exit 1'
run bash "$REPO/system/send-with-tailscale" "$BATS_TEST_TMPDIR/one.txt"
[ "$status" -eq 0 ]
uncalled tailscale file cp --update-interval=0 -- "$BATS_TEST_TMPDIR/one.txt" 100.64.0.3:
}
@test "Send with Tailscale says when no computer can take files" {
stub tailscale
run bash "$REPO/system/send-with-tailscale" "$BATS_TEST_TMPDIR/one.txt"
[ "$status" -eq 1 ]
grep -q '^notify-send .*No computer to send to' "$STUB_LOG"
not_called zenity
}
@test "Send with Tailscale says when sending fails" {
stub tailscale 'if [ "$3" = --targets ]; then printf "100.64.0.3\tdesktop\n"; else echo "no route"; exit 1; fi'
run bash "$REPO/system/send-with-tailscale" "$BATS_TEST_TMPDIR/one.txt"
[ "$status" -eq 1 ]
grep -q "^notify-send .*Couldn't send to desktop no route$" "$STUB_LOG"
}
# --- Captive portal ----------------------------------------------------------
portal_setup() {
export CAPTIVE_PORTAL_STATE="$BATS_TEST_TMPDIR/paused"
export EXIT_NODE="${EXIT_NODE-100.64.0.9/32}"
stub logger
stub tailscale 'if [ "$1" = status ]; then
if [ -n "$EXIT_NODE" ]; then echo "{\"ExitNodeStatus\": {\"TailscaleIPs\": [\"$EXIT_NODE\"]}}"; else echo "{}"; fi
fi'
}
@test "at a captive portal, the exit node is paused, and comes back once online" {
portal_setup
CONNECTIVITY_STATE=PORTAL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
[ "$status" -eq 0 ]
called tailscale set --exit-node=
[ "$(cat "$CAPTIVE_PORTAL_STATE")" = 100.64.0.9 ]
EXIT_NODE="" CONNECTIVITY_STATE=FULL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
[ "$status" -eq 0 ]
called tailscale set --exit-node=100.64.0.9
[ ! -e "$CAPTIVE_PORTAL_STATE" ]
}
@test "a captive portal changes nothing without an exit node" {
EXIT_NODE="" portal_setup
CONNECTIVITY_STATE=PORTAL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
CONNECTIVITY_STATE=FULL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
uncalled tailscale set --exit-node=
[ ! -e "$CAPTIVE_PORTAL_STATE" ]
}
@test "an exit node chosen while at the portal is left alone" {
portal_setup
echo 100.64.0.9 > "$CAPTIVE_PORTAL_STATE"
EXIT_NODE=100.64.0.7/32 CONNECTIVITY_STATE=FULL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
[ "$status" -eq 0 ]
refute grep -q '^tailscale set' "$STUB_LOG"
[ ! -e "$CAPTIVE_PORTAL_STATE" ]
}
@test "the captive portal helper ignores other events" {
portal_setup
CONNECTIVITY_STATE=PORTAL run bash "$REPO/system/captive-portal" wlan0 up
[ "$status" -eq 0 ]
not_called tailscale
}
+6
View File
@@ -53,3 +53,9 @@ not_called() {
uncalled() {
! called "$@"
}
# refute COMMAND...: true if COMMAND fails. Use it instead of "! COMMAND",
# which doesn't fail a test (see uncalled).
refute() {
! "$@"
}
+25 -2
View File
@@ -11,7 +11,7 @@ setup() {
CD="$HOME/.local/share/coredesktop"
mkdir -p "$CD/updates.d" "$HOME/.local/bin"
cp "$REPO/update" "$CD/update"
for script in refresh sibling version configure audit report; do
for script in refresh sibling version configure audit report webapp; do
echo '#!/bin/bash' > "$CD/$script"
done
@@ -25,6 +25,8 @@ setup() {
# Let go of bats' output pipes so the sudo keepalive's leftover sleep
# doesn't keep the test waiting
stub sleep 'exec > /dev/null 2>&1 3>&-; exec /usr/bin/sleep "$@"'
# Not the real one: it would ask logind to keep this computer awake
stub systemd-inhibit
}
# hook NAME BODY: add updates.d/NAME.sh with BODY as its run_update
@@ -51,11 +53,32 @@ ran() {
[[ "$output" == *"Done."* ]]
called git -C "$CD" pull --ff-only
ran a b
for script in update refresh sibling version configure audit report; do
for script in update refresh sibling version configure audit report webapp; do
[ -x "$HOME/.local/bin/$script" ]
done
}
@test "update keeps the computer awake while it runs" {
hook 10-a 'echo a >> "$RAN"'
run "$CD/update"
[ "$status" -eq 0 ]
# In the background, so give it a moment
for _ in 1 2 3 4 5 6 7 8 9 10; do
grep -q '^systemd-inhibit ' "$STUB_LOG" && break
/usr/bin/sleep 0.1
done
grep -q '^systemd-inhibit --what=sleep:idle .* --mode=block tail --pid=[0-9]* -f /dev/null$' "$STUB_LOG"
}
@test "update's hooks may upgrade past the pacman guard" {
hook 10-a 'echo "$COREDESKTOP_ALLOW_PACMAN" >> "$RAN"'
run "$CD/update"
[ "$status" -eq 0 ]
ran 1
}
@test "update pulls only once, before re-running its new copy" {
hook 10-a 'echo a >> "$RAN"'
+93
View File
@@ -321,3 +321,96 @@ LIST
[ "$status" -ne 0 ]
not_called curl
}
# --- unowned_conflicts, move_aside, put_back ---------------------------------
# A pacman -Su log that stopped on conflicting files: one line per path given
conflict_log() {
LOG="$BATS_TEST_TMPDIR/pacman.log"
{
echo ":: Proceed with installation? [Y/n] "
echo "(2/2) checking for file conflicts [######] 100%"
echo "error: failed to commit transaction (conflicting files)"
for line in "$@"; do printf '%s\r\n' "$line"; done
echo "Errors occurred, no packages were upgraded."
} > "$LOG"
}
@test "unowned_conflicts lists the files no package owns" {
source "$REPO/utils.sh"
stub pacman 'exit 1'
conflict_log "python-foo: /usr/lib/python3.13/site-packages/foo/__init__.py exists in filesystem" \
"python-foo: /usr/lib/python3.13/site-packages/foo exists in filesystem" \
"bar: /usr/bin/bar exists in filesystem"
run unowned_conflicts "$LOG"
[ "$status" -eq 0 ]
[ "$output" = "$(printf '%s\n' /usr/bin/bar /usr/lib/python3.13/site-packages/foo \
/usr/lib/python3.13/site-packages/foo/__init__.py)" ]
}
@test "unowned_conflicts gives up when a package owns a conflicting file" {
source "$REPO/utils.sh"
stub pacman 'exit 1'
conflict_log "foo: /usr/bin/foo exists in filesystem" \
"foo: /usr/bin/bar exists in filesystem (owned by bar)"
run unowned_conflicts "$LOG"
[ "$status" -eq 1 ]
[ -z "$output" ]
}
@test "unowned_conflicts gives up when pacman finds an owner now" {
source "$REPO/utils.sh"
stub pacman '[ "$2" = /usr/bin/foo ]'
conflict_log "foo: /usr/bin/foo exists in filesystem"
run unowned_conflicts "$LOG"
[ "$status" -eq 1 ]
}
@test "unowned_conflicts finds nothing in other failures" {
source "$REPO/utils.sh"
stub pacman 'exit 1'
LOG="$BATS_TEST_TMPDIR/pacman.log"
printf 'error: failed to prepare transaction (could not satisfy dependencies)\n' > "$LOG"
run unowned_conflicts "$LOG"
[ "$status" -eq 1 ]
run unowned_conflicts "$BATS_TEST_TMPDIR/missing.log"
[ "$status" -eq 1 ]
}
@test "move_aside moves files and folders under REPLACED_DIR, and put_back returns them" {
source "$REPO/utils.sh"
stub sudo '"$@"'
REPLACED_DIR="$BATS_TEST_TMPDIR/replaced"
local file="$BATS_TEST_TMPDIR/usr/bin/foo" dir="$BATS_TEST_TMPDIR/usr/lib/foo"
mkdir -p "$dir" "$(dirname "$file")"
echo old > "$file"
echo x > "$dir/x"
run move_aside "$file" "$dir"
[ "$status" -eq 0 ]
[ ! -e "$file" ] && [ ! -e "$dir" ]
[ "$(cat "$REPLACED_DIR$file")" = old ]
[ -f "$REPLACED_DIR$dir/x" ]
# The upgrade installed its own foo, but not the folder
echo new > "$file"
run put_back "$file" "$dir"
[ "$status" -eq 0 ]
[ "$(cat "$file")" = new ]
[ -f "$dir/x" ]
[ "$(cat "$REPLACED_DIR$file")" = old ]
}
@test "move_aside keeps what an earlier move left in REPLACED_DIR" {
source "$REPO/utils.sh"
stub sudo '"$@"'
REPLACED_DIR="$BATS_TEST_TMPDIR/replaced"
local file="$BATS_TEST_TMPDIR/usr/bin/foo"
mkdir -p "$(dirname "$file")"
echo first > "$file"
move_aside "$file"
echo second > "$file"
move_aside "$file"
[ "$(cat "$REPLACED_DIR$file")" = second ]
[ "$(cat "$REPLACED_DIR$file.~1~")" = first ]
}
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/env bats
load test_helper
setup() {
common_setup
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_DATA_DIRS="$BATS_TEST_TMPDIR/share"
APPS="$XDG_DATA_HOME/applications"
mkdir -p "$XDG_DATA_DIRS/applications"
printf '[Desktop Entry]\nExec=test-chromium %%U\n' > "$XDG_DATA_DIRS/applications/helium.desktop"
printf '[Desktop Entry]\nExec=/usr/lib/firefox/firefox %%u\n' > "$XDG_DATA_DIRS/applications/firefox.desktop"
stub xdg-settings 'echo "${DEFAULT_BROWSER:-helium.desktop}"'
export WEBAPP_BROWSERS="test-chromium"
stub test-chromium
stub xdg-open
stub update-desktop-database
stub gtk-update-icon-cache
# No icon to be had
stub curl 'exit 22'
}
@test "webapp add makes a launcher that opens the site as an app" {
run bash "$REPO/webapp" add "Nextcloud" https://nextcloud.example.com/apps/files
[ "$status" -eq 0 ]
local file="$APPS/webapp-nextcloud.desktop"
grep -qx 'Name=Nextcloud' "$file"
grep -qx "Exec=\"$HOME/.local/bin/webapp\" open \"https://nextcloud.example.com/apps/files\"" "$file"
grep -qx 'StartupWMClass=chrome-nextcloud.example.com__apps_files-Default' "$file"
grep -qx 'Icon=applications-internet' "$file"
}
@test "webapp add quotes a URL's special characters for the launcher" {
run bash "$REPO/webapp" add "Search" 'https://example.com/?q=a%20b&x=$y'
[ "$status" -eq 0 ]
grep -qxF 'Exec="'"$HOME"'/.local/bin/webapp" open "https://example.com/?q=a%%20b&x=\\$y"' "$APPS/webapp-search.desktop"
}
@test "webapp add refuses addresses that aren't http(s)" {
for url in "javascript:alert(1)" "file:///etc/passwd" "example.com" "https://a b"; do
run bash "$REPO/webapp" add "Bad" "$url"
[ "$status" -eq 1 ]
done
[ ! -e "$APPS/webapp-bad.desktop" ]
}
@test "webapp add takes an icon from a file" {
# A 1x1 PNG
base64 -d > "$BATS_TEST_TMPDIR/icon.png" <<< \
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNgYGD4DwABBAEAwS2OUAAAAABJRU5ErkJggg==
run bash "$REPO/webapp" add "My App" https://app.example.com "$BATS_TEST_TMPDIR/icon.png"
[ "$status" -eq 0 ]
local icon="$XDG_DATA_HOME/icons/hicolor/256x256/apps/webapp-my-app.png"
[ -f "$icon" ]
grep -qx "Icon=$icon" "$APPS/webapp-my-app.desktop"
}
@test "webapp list and remove handle only web apps" {
bash "$REPO/webapp" add "Nextcloud" https://nextcloud.example.com
printf '[Desktop Entry]\nName=Other\n' > "$APPS/webapp-other.desktop"
run bash "$REPO/webapp" list
[[ "$output" == "Nextcloud"*"https://nextcloud.example.com" ]]
run bash "$REPO/webapp" remove Other
[ "$status" -eq 1 ]
[ -f "$APPS/webapp-other.desktop" ]
run bash "$REPO/webapp" remove Nextcloud
[ "$status" -eq 0 ]
[ ! -e "$APPS/webapp-nextcloud.desktop" ]
}
@test "webapp open uses the default browser when it's Chromium-based" {
run bash "$REPO/webapp" open https://example.com
[ "$status" -eq 0 ]
called test-chromium --app=https://example.com
}
@test "webapp open falls back to an installed Chromium-based browser" {
DEFAULT_BROWSER=firefox.desktop run bash "$REPO/webapp" open https://example.com
[ "$status" -eq 0 ]
called test-chromium --app=https://example.com
}
@test "webapp open uses the browser when there's no Chromium-based one" {
rm "$STUB_BIN/test-chromium"
DEFAULT_BROWSER=firefox.desktop run bash "$REPO/webapp" open https://example.com
[ "$status" -eq 0 ]
called xdg-open https://example.com
}
+13
View File
@@ -44,6 +44,10 @@ clean_log() {
s/\x1b[()][0-9A-Za-z]//g; s/\x1b[=>]//g; s/\r+$//; s/.*\r//' "$1"
}
# Lets this update's pacman and yay upgrade the system past the guard that
# stops upgrades run without update (system/pacman-guard)
export COREDESKTOP_ALLOW_PACMAN=1
# Set by updates.d/99-reboot-check.sh when this update needs a reboot
REBOOT_NEEDED="$HOME/.local/state/coredesktop/reboot-needed"
@@ -124,6 +128,7 @@ install_script "$COREDESKTOP/version" ~/.local/bin/version
install_script "$COREDESKTOP/configure" ~/.local/bin/configure
install_script "$COREDESKTOP/audit" ~/.local/bin/audit
install_script "$COREDESKTOP/report" ~/.local/bin/report
install_script "$COREDESKTOP/webapp" ~/.local/bin/webapp
if [[ -z "$UPDATE_REEXECED" ]]; then
export UPDATE_REEXECED=1
@@ -147,6 +152,14 @@ while kill -0 $$ 2>/dev/null; do sudo -n -v; sleep 60; done > /dev/null 2>&1 &
SUDO_KEEPALIVE_PID=$!
trap 'kill "$SUDO_KEEPALIVE_PID" 2>/dev/null' EXIT
# Keep the computer from suspending, from idle or a closed lid, until update
# exits: a pacman upgrade cut off part way can leave it unbootable. tail exits
# with update, and that ends the inhibitor.
if command -v systemd-inhibit > /dev/null; then
systemd-inhibit --what=sleep:idle --who=CoreDesktop --why="Updating CoreDesktop" --mode=block \
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
fi
rm -f "$REBOOT_NEEDED"
FAILED=()
[[ -n "$UPDATE_PULL_FAILED" ]] && FAILED+=("git pull")
+55 -1
View File
@@ -34,7 +34,61 @@ sudo pacman -Sy --needed --noconfirm archlinux-keyring || STATUS=1
echo "Updating Arch..."
mkdir -p "$(dirname "$PACMAN_UPDATE_LOG")"
: > "$PACMAN_UPDATE_LOG"
sudo script -qefc "pacman -Su --noconfirm" "$PACMAN_UPDATE_LOG" || STATUS=1
# Run pacman -Su with the options given, adding its output to the log
upgrade() {
sudo script -qaefc "pacman -Su $*" "$PACMAN_UPDATE_LOG"
}
# Ask a question on the terminal, if there is one; the default is yes
ask_yes() {
local answer
{ : < /dev/tty; } 2> /dev/null || return 1
read -rp "$1 [Y/n] " answer < /dev/tty || return 1
[[ "$answer" != [nN]* ]]
}
# Two things stop an upgrade that a second try gets past. Either way, pacman
# changed nothing the first time.
retry_upgrade() {
local files=()
# A package that replaces or conflicts with an installed one: pacman asks
# whether to remove that one, and --noconfirm answers no. Which to keep is
# yours to decide (pacman says which above), so ask again without it.
if grep -q 'unresolvable package conflicts detected' "$PACMAN_UPDATE_LOG"; then
if ! { : < /dev/tty; } 2> /dev/null; then
echo "Packages conflict, and pacman needs you to choose. Run update in a terminal."
return 1
fi
echo -e "\e[33mPackages conflict, and pacman needs you to choose. Asking again:\e[0m"
upgrade
return
fi
# Files no package owns where a package now installs its own (left by pip,
# make install or an earlier installer): pacman won't install over them. Move
# them aside and try again, and put back any it didn't replace.
mapfile -t files < <(unowned_conflicts "$PACMAN_UPDATE_LOG")
(( ${#files[@]} > 0 )) || return 1
echo -e "\e[33mThe upgrade stopped because these files are in the way. No package owns them,\e[0m"
echo -e "\e[33mand a package now installs its own:\e[0m"
printf ' %s\n' "${files[@]}"
if ! ask_yes "Move them to $REPLACED_DIR and upgrade again?"; then
echo "Left them. Move or delete them, then run update again."
return 1
fi
move_aside "${files[@]}" || { put_back "${files[@]}"; return 1; }
if upgrade --noconfirm; then
echo "Upgraded. What was there before is in $REPLACED_DIR, if you need any of it."
return 0
fi
echo "Putting back what the upgrade didn't replace:"
put_back "${files[@]}"
return 1
}
upgrade --noconfirm || retry_upgrade || STATUS=1
if initramfs_build_failed; then
echo -e "\e[31mRebuilding the initramfs failed. Don't reboot until it's fixed - see the output above or $PACMAN_UPDATE_LOG.\e[0m"
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
COREDESKTOP="$HOME/.local/share/coredesktop"
# Stop full upgrades that skip update (system/pacman-guard)
run_update() {
bash "$COREDESKTOP/system/pacman-guard.sh"
}
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
COREDESKTOP="$HOME/.local/share/coredesktop"
# Send with Tailscale in Files, and save files sent here to Downloads
run_update() {
bash "$COREDESKTOP/system/taildrop.sh"
}
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
COREDESKTOP="$HOME/.local/share/coredesktop"
# Pause a Tailscale exit node while signing in to a captive portal
run_update() {
bash "$COREDESKTOP/system/captive-portal.sh"
}
+49
View File
@@ -205,6 +205,55 @@ initramfs_build_failed() {
(( succeeded == 0 || succeeded < built ))
}
# Where unowned_conflicts' files are moved, under their full paths, so they
# can be put back. Outside the directories they came from: a copy left in
# /etc/sddm.conf.d or /usr/lib/systemd/system-sleep would still be live.
REPLACED_DIR="${REPLACED_DIR:-/var/lib/coredesktop/replaced}"
# Print the files and directories pacman refused to install over, one per line,
# when the upgrade in log $1 stopped on conflicting files that no package owns
# (left by pip, make install or an earlier installer). Prints nothing, and
# fails, when any conflicting path is owned by a package: moving the rest
# wouldn't let the upgrade through.
unowned_conflicts() {
local log="$1" lines=() line path paths=()
[ -f "$log" ] || return 1
grep -q 'failed to commit transaction (conflicting files)' "$log" || return 1
mapfile -t lines < <(tr -d '\r' < "$log" | grep -E '^[^ :]+: /.* exists in filesystem( \(owned by [^)]*\))?$')
(( ${#lines[@]} > 0 )) || return 1
for line in "${lines[@]}"; do
[[ "$line" == *"(owned by "* ]] && return 1
path="${line#*: }"
path="${path% exists in filesystem}"
# Checked again: pacman's message may be from before something changed
pacman -Qo "$path" &> /dev/null && return 1
paths+=("$path")
done
printf '%s\n' "${paths[@]}" | sort -u
}
# Move each path given to the same path under REPLACED_DIR, keeping any copy
# already there (numbered backups)
move_aside() {
local path
for path in "$@"; do
sudo mkdir -p "$REPLACED_DIR$(dirname "$path")" || return 1
sudo mv -T --backup=numbered "$path" "$REPLACED_DIR$path" || return 1
echo " $path -> $REPLACED_DIR$path"
done
}
# Put back each path given that move_aside moved and nothing has replaced
# since. -L too: -e is false for a dangling symlink.
put_back() {
local path
for path in "$@"; do
if [[ ! -e "$path" && ! -L "$path" ]] && [[ -e "$REPLACED_DIR$path" || -L "$REPLACED_DIR$path" ]]; then
sudo mv -T "$REPLACED_DIR$path" "$path" && echo " $path"
fi
done
}
# pacman downloads from the first mirror in this list (system/mirrors.sh keeps
# it fresh). Overridable for the tests.
MIRRORLIST="${MIRRORLIST:-/etc/pacman.d/mirrorlist}"
Executable
+179
View File
@@ -0,0 +1,179 @@
#!/bin/bash
#
# Purpose : Put a website in GNOME's app grid as an app of its own: it opens
# in its own window, without the browser's tabs and address bar, and
# has its own icon in the dock. Adapted from Omarchy.
APPS="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
ICONS="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor/256x256/apps"
# Chromium-based browsers, which can open a site as an app (--app)
APP_BROWSERS="${WEBAPP_BROWSERS:-helium-browser chromium google-chrome-stable brave vivaldi-stable microsoft-edge-stable}"
usage() {
cat << EOF
Usage: webapp add <name> <url> [icon] Add a web app; icon is an image's URL or file
webapp remove <name> Remove a web app
webapp list List your web apps
webapp open <url> Open a site as an app
webapp add "Nextcloud" https://nextcloud.example.com
EOF
}
# "My App" -> my-app
slug() {
printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//'
}
desktop_file() {
echo "$APPS/webapp-$(slug "$1").desktop"
}
# The browser command to open apps with: your default browser if it's
# Chromium-based, or else the first such browser installed
app_browser() {
local default dir command
default="$(xdg-settings get default-web-browser 2> /dev/null)"
if [ -n "$default" ]; then
for dir in "${XDG_DATA_HOME:-$HOME/.local/share}" ${XDG_DATA_DIRS//:/ } /usr/local/share /usr/share; do
[ -f "$dir/applications/$default" ] || continue
command="$(sed -nE 's/^Exec=([^ ]+).*/\1/p' "$dir/applications/$default" | head -n 1)"
break
done
if [[ " $APP_BROWSERS " == *" ${command##*/} "* ]] && command -v "$command" > /dev/null; then
echo "$command"
return 0
fi
fi
for command in $APP_BROWSERS; do
command -v "$command" > /dev/null && { echo "$command"; return 0; }
done
return 1
}
# Chromium names an app's window after the site's host and path. Naming it in
# the launcher's StartupWMClass lets GNOME put the window under the launcher.
window_class() {
local address host path
address="${1#*://}"
address="${address%%[?#]*}"
host="${address%%/*}"
path="${address:${#host}}"
host="${host##*@}"
host="${host%%:*}"
printf 'chrome-%s_%s-Default\n' "${host,,}" "${path:-/}" | sed 's|/|_|g'
}
# Quote $1 as one argument of a desktop entry's Exec: in double quotes, with
# \ " ` $ backslashed, then % doubled and every \ doubled again, since Exec is
# itself an escaped string
exec_arg() {
local arg="$1"
arg="${arg//\\/\\\\}"
arg="${arg//\"/\\\"}"
arg="${arg//\`/\\\`}"
arg="${arg//\$/\\\$}"
arg="${arg//%/%%}"
arg="${arg//\\/\\\\}"
printf '"%s"' "$arg"
}
# Only http(s): a browser's --app runs javascript: and file: URLs as pages
check_url() {
[[ "$1" =~ ^https?://[^[:space:]]+$ ]] || { echo "The address must start with https:// (or http://): $1" >&2; return 1; }
}
# Save the app's icon as $2 from an image's URL or file $1, or else from the
# site's apple-touch-icon. Prints the Icon= value to use.
fetch_icon() {
local source="$1" name="$2" url="$3" origin tmp
mkdir -p "$ICONS"
tmp="$(mktemp)"
if [ -n "$source" ] && [ -f "$source" ]; then
cp "$source" "$tmp"
elif [ -n "$source" ]; then
curl -fsSL --max-time 15 -o "$tmp" "$source" 2> /dev/null
else
origin="$(sed -E 's#^(https?://[^/]+).*#\1#' <<< "$url")"
curl -fsSL --max-time 15 -o "$tmp" "$origin/apple-touch-icon.png" 2> /dev/null
fi
if [ -s "$tmp" ] && [[ "$(file -b --mime-type "$tmp")" == image/* ]]; then
mv -f "$tmp" "$ICONS/$name.png"
gtk-update-icon-cache -q "${ICONS%/256x256/apps}" 2> /dev/null
echo "$ICONS/$name.png"
else
rm -f "$tmp"
[ -n "$source" ] && echo "Couldn't get an image from $source; using a plain icon." >&2
echo "applications-internet"
fi
}
add() {
local name="$1" url="$2" icon_source="$3" file icon
if [ -z "$name" ] || [ -z "$url" ]; then
usage >&2
return 2
fi
[ -n "$(slug "$name")" ] || { echo "Give the app a name with letters or numbers in it." >&2; return 1; }
[[ "$name" != *$'\n'* ]] || { echo "The name must be on one line." >&2; return 1; }
check_url "$url" || return 1
app_browser > /dev/null || echo "Note: web apps open in a Chromium-based browser such as Helium, and none is installed. Until one is, this opens in your browser." >&2
file="$(desktop_file "$name")"
icon="$(fetch_icon "$icon_source" "webapp-$(slug "$name")" "$url")"
mkdir -p "$APPS"
# webapp open finds the browser each time, so changing browsers doesn't
# break the launcher
cat > "$file" << EOF
[Desktop Entry]
Type=Application
Name=$name
Comment=$url
Exec=$(exec_arg "$HOME/.local/bin/webapp") open $(exec_arg "$url")
Icon=$icon
StartupWMClass=$(window_class "$url")
Categories=Network;
X-CoreDesktop-WebApp=true
EOF
update-desktop-database -q "$APPS" 2> /dev/null
echo "Added $name to your apps."
}
remove() {
local file
[ -n "$1" ] || { usage >&2; return 2; }
file="$(desktop_file "$1")"
if ! grep -qs '^X-CoreDesktop-WebApp=true' "$file"; then
echo "No web app named $1. These are: webapp list" >&2
return 1
fi
rm -f "$file" "$ICONS/webapp-$(slug "$1").png"
update-desktop-database -q "$APPS" 2> /dev/null
echo "Removed $1."
}
list() {
local file
for file in "$APPS"/webapp-*.desktop; do
grep -qs '^X-CoreDesktop-WebApp=true' "$file" || continue
printf '%-24s %s\n' "$(sed -n 's/^Name=//p' "$file")" "$(sed -n 's/^Comment=//p' "$file")"
done
}
open_app() {
local browser
check_url "$1" || return 1
if browser="$(app_browser)"; then
exec "$browser" --app="$1"
fi
exec xdg-open "$1"
}
case "$1" in
add) shift; add "$@" ;;
remove|rm) shift; remove "$@" ;;
list|ls) list ;;
open) shift; open_app "$@" ;;
-h|--help) usage ;;
*) usage >&2; exit 2 ;;
esac