Add upgrade safeguards, hardware setup, sign-in options and Taildrop from Omarchy
shellcheck / shellcheck (push) Failing after 19s
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:
@@ -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."
|
||||
}
|
||||
|
||||
Executable
+107
@@ -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"
|
||||
}
|
||||
Executable
+126
@@ -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."
|
||||
}
|
||||
Executable
+56
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user