#!/bin/bash # archypr:summary=Set up fingerprint authentication for sudo, polkit, and lock screen # archypr:requires-sudo=true set -e check_fingerprint_hardware() { # Get fingerprint devices for the user devices=$(fprintd-list "$USER" 2>/dev/null) # Exit if no devices found if [[ -z $devices ]]; then echo -e "\e[31m\nNo fingerprint sensor detected.\e[0m" return 1 fi return 0 } setup_pam_config() { # Configure sudo if ! grep -q pam_fprintd.so /etc/pam.d/sudo; then echo "Configuring sudo for fingerprint authentication..." sudo sed -i '1i auth sufficient pam_fprintd.so' /etc/pam.d/sudo fi # Configure polkit if [[ -f /etc/pam.d/polkit-1 ]] && ! grep -q 'pam_fprintd.so' /etc/pam.d/polkit-1; then echo "Configuring polkit for fingerprint authentication..." sudo sed -i '1i auth sufficient pam_fprintd.so' /etc/pam.d/polkit-1 elif [[ ! -f /etc/pam.d/polkit-1 ]]; then echo "Creating polkit configuration with fingerprint authentication..." sudo tee /etc/pam.d/polkit-1 >/dev/null <<'EOF' auth sufficient pam_fprintd.so auth required pam_unix.so account required pam_unix.so password required pam_unix.so session required pam_unix.so EOF fi } add_hyprlock_fingerprint_icon() { echo "Adding fingerprint icon to hyprlock placeholder text..." sed -i 's/placeholder_text = .*/placeholder_text = Enter Password 󰈷 <\/span>/' ~/.config/hypr/hyprlock.conf sed -i 's/fingerprint:enabled = .*/fingerprint:enabled = true/' ~/.config/hypr/hyprlock.conf } echo -e "\e[32mSetting up fingerprint scanner for authentication.\n\e[0m" # Install required packages echo "Installing required packages..." # libfprint-git provides+conflicts libfprint; pacman -S --noconfirm # defaults the conflict prompt to N and aborts. Pre-remove libfprint # with -Rdd so the install goes silent. -Rdd (not archypr-pkg-drop's # -Rns) is required because fprintd requires libfprint; the dep is # re-satisfied immediately by libfprint-git's provides=libfprint. if archypr-pkg-present libfprint; then sudo pacman -Rdd --noconfirm libfprint fi archypr-kg-add libfprint-git fprintd usbutils if ! check_fingerprint_hardware; then exit 1 fi # Configure PAM setup_pam_config # Add fingerprint icon to hyprlock placeholder text add_hyprlock_fingerprint_icon # Enroll first fingerprint echo -e "\e[32m\nLet's setup your right index finger as the first fingerprint.\e[0m" echo -e "Keep moving the finger around on sensor until the process completes.\n" if sudo fprintd-enroll "$USER"; then echo -e "\e[32m\nFingerprint enrolled successfully!\e[0m" # Verify echo -e "\nNow let's verify that it's working correctly.\n" if fprintd-verify; then echo -e "\e[32m\nPerfect! Fingerprint authentication is now configured.\e[0m" echo "You can use your fingerprint for sudo, polkit, and lock screen (Super + Escape)." else echo -e "\e[31m\nVerification failed. You may want to try enrolling again.\e[0m" fi else echo -e "\e[31m\nEnrollment failed. Please try again.\e[0m" exit 1 fi