Files
coredesktop/system/hardware.sh
T
davidandClaude Opus 5.5 9dc5eb193d
shellcheck / shellcheck (push) Failing after 19s
Add upgrade safeguards, hardware setup, sign-in options and Taildrop from Omarchy
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>
2026-11-16 12:08:06 -07:00

113 lines
4.1 KiB
Bash
Executable File

#!/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