#!/bin/bash
# find the fingerprint reader and change its power level to autosuspend
find_manuf=STMicroelectronics
find_prod="Biometric Coprocessor"
for devdir in /sys/class/usbmon/usbmon*/device/usb*/*; do
[[ -r $devdir/manufacturer ]] || continue
manuf=$(<$devdir/manufacturer)
[[ $manuf = $find_manuf ]] || continue;
prod=$(<$devdir/product)
[[ $prod = $find_prod ]] || continue;
# if we get here then we have the right device!
plevel_file=$devdir/power/level
old_level=$(<$plevel_file);
# if it is already set properly then exit silently:
[[ $old_level = auto ]] && exit 0
# if we successfully change it then exit silently:
echo auto >$plevel_file && exit 0
echo "Failed to set the fingerprint reader's power level to 'auto'."
exit 1
done
# if we make it through the for loop without exiting, the search failed
echo "Could not find the $find_manuf $find_prod (fingerprint reader)"
exit 1