Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 128 additions & 5 deletions bin/omarchy-setup-security-fingerprint
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,88 @@ EOF
fi
}

# A property of fprintd's default reader, such as its name or scan-type ("press"
# for a sensor that takes separate touches, "swipe" for one that reads a moving
# finger). Empty when fprintd can't be asked.
fingerprint_reader() {
local device
device=$(busctl --system call net.reactivated.Fprint /net/reactivated/Fprint/Manager \
net.reactivated.Fprint.Manager GetDefaultDevice 2>/dev/null) || return 0
device=${device#o \"}
device=${device%\"}
busctl --system get-property net.reactivated.Fprint "$device" net.reactivated.Fprint.Device "$1" 2>/dev/null |
sed -n 's/^s "\(.*\)"$/\1/p'
}

# fprintd's own lines that carry nothing for the owner; anything else it
# prints that isn't a result, such as why a claim or start failed, is shown.
fprintd_chatter() {
[[ $1 == "Using device "* || $1 == "Enrolling "*" finger." || $1 == "Listing enrolled fingers:" ||
$1 == " - #"* || $1 == "Verify started!" || $1 == "Verifying: "* ]]
}

# fprintd-enroll's results as instructions, AGAIN asking for more. Stages are
# steps, as one can take several touches. With DUPLICATE_CHECK=1 the first stage
# is fprintd's duplicate check, not an enrollment step, and isn't shown.
enroll_progress() {
local again=$1 duplicate_check=${2:-0} line stages=0 steps=0
while IFS= read -r line; do
if [[ $line != "Enroll result: "* ]]; then
fprintd_chatter "$line" || echo " $line"
continue
fi
case ${line#Enroll result: } in
enroll-stage-passed)
if (( ++stages > duplicate_check )); then
echo " ✓ Step $(( ++steps )) done. $again"
fi
;;
enroll-retry-scan) echo " That one didn't read. $again" ;;
enroll-swipe-too-short) echo " Too short. $again" ;;
enroll-finger-not-centered) echo " Not centered: use the middle of the sensor. $again" ;;
enroll-remove-and-retry) echo " Lift your finger off the sensor, then: $again" ;;
enroll-too-fast) echo " Too fast. $again" ;;
enroll-completed) echo " ✓ Enrolled." ;;
enroll-duplicate) echo " ✗ That finger is already enrolled." ;;
enroll-data-full) echo " ✗ The reader has no room for another fingerprint." ;;
enroll-disconnected) echo " ✗ The reader was disconnected." ;;
enroll-failed | enroll-unknown-error)
echo " ✗ Enrollment stopped. If you stopped before it said Enrolled, run this again and keep going." ;;
*) echo " ${line#Enroll result: }" ;;
esac
done
}

# fprintd-verify's results the same way.
# fprintd-verify suffixes each result with " (done)" or " (not done)"; a
# result that isn't done is a retry, whatever its name.
verify_progress() {
local again=$1 line
while IFS= read -r line; do
if [[ $line != "Verify result: "* ]]; then
fprintd_chatter "$line" || echo " $line"
continue
fi
line=${line#Verify result: }
if [[ $line == *" (not done)" ]]; then
case ${line% (*} in
verify-swipe-too-short) echo " Too short. $again" ;;
verify-finger-not-centered) echo " Not centered: use the middle of the sensor. $again" ;;
verify-remove-and-retry) echo " Lift your finger off the sensor, then: $again" ;;
verify-too-fast) echo " Too fast. $again" ;;
*) echo " That one didn't read. $again" ;;
esac
continue
fi
case ${line% (*)} in
verify-match) echo " ✓ Matched." ;;
verify-no-match) echo " ✗ No match." ;;
verify-disconnected) echo " ✗ The reader was disconnected." ;;
*) echo " ✗ The check stopped (${line% (*)})." ;;
esac
done
}

echo -e "\e[32mSetting up fingerprint scanner for authentication.\n\e[0m"

# Bail before installing anything if there's no reader to talk to.
Expand All @@ -74,15 +156,55 @@ if omarchy-pkg-missing libfprint-git fprintd usbutils; then
fi

# 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"
# Authenticate sudo first, and say so: with fingerprint sudo already set up it
# asks for a touch of its own, which must not pass for the first sample.
if ! sudo -n true 2>/dev/null; then
echo -e "\nFirst, confirm it's you. Setup needs administrator rights to enroll."
if ! sudo -v; then
echo -e "\e[31mSetup needs administrator rights to enroll a fingerprint.\e[0m"
exit 1
fi
fi

echo -e "\e[32m\nLet's set up your right index finger as the first fingerprint.\e[0m"
# A press sensor needs a touch for each sample; a swipe sensor a moving finger.
# When fprintd can't say which, the prompts name neither.
case $(fingerprint_reader scan-type) in
press)
start="Touch the sensor." again="Keep lifting your finger and touching the sensor."
echo -e "Touch the sensor, lift your finger and touch it again, and keep going until it says Enrolled. A step can take a few touches.\n"
;;
swipe)
start="Swipe your finger across the sensor." again="Swipe it again."
echo -e "Keep moving the finger around on sensor until it says Enrolled.\n"
;;
*)
start="Touch or swipe the sensor." again="Touch or swipe it again."
echo -e "Touch or swipe the sensor, and keep going until it says Enrolled. A step can take a few tries.\n"
;;
esac

if sudo fprintd-enroll "$USER"; then
# fprintd runs a duplicate check before enrolling on a reader that identifies,
# which D-Bus doesn't say. Touch ID does, and its check needs no touch while
# nothing is enrolled; any other reader's first stage counts, touched or not.
# The name is the driver's full_name in libfprint/drivers/aurora/aurora.c, which
# omarchy-pkgs adds to libfprint-git in pkgbuilds/libfprint-git/aurora-apple-sep.patch.
# If it changes there, Touch ID shows one step early.
duplicate_check=0
if [[ $(fingerprint_reader name) == "Apple secure enclave fingerprint sensor" ]]; then
duplicate_check=1
fi
# The filters only print; the exit status is fprintd's.
sudo fprintd-enroll "$USER" | enroll_progress "$again" "$duplicate_check"
enroll_status=${PIPESTATUS[0]}
if (( enroll_status == 0 )); 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 "\nNow let's verify that it's working correctly. $start\n"
fprintd-verify | verify_progress "$again"
verify_status=${PIPESTATUS[0]}
if (( verify_status == 0 )); then
# PAM comes last, once a print is enrolled and verified. Detection only
# proves a reader is there, not that libfprint can drive it — an Elan MOC
# sensor outside the elanmoc table gets this far and then fails to enroll.
Expand All @@ -98,6 +220,7 @@ if sudo fprintd-enroll "$USER"; then
echo "You can use your fingerprint for sudo, polkit, and lock screen (Super + Ctrl + L)."
else
echo -e "\e[31m\nVerification failed. You may want to try enrolling again.\e[0m"
exit 1
fi
else
echo -e "\e[31m\nEnrollment failed. Please try again.\e[0m"
Expand Down
Loading
Loading