Fix premature script exit caused by USB devices without a product name

This commit is contained in:
David Fundament
2026-07-02 01:06:47 +00:00
committed by Thomas Duckworth
parent ebe9605402
commit 6920aa777e

View File

@@ -9,10 +9,13 @@ set -e
INPUT_DEVICE_IDS=$(find /sys/bus/usb/drivers/usbhid -regex '.*\/[0-9:.-]+' -printf '%f\n' | cut --delimiter ":" --fields 1 | sort --unique)
set +e
for DEVICE_ID in $INPUT_DEVICE_IDS; do
DEVICE_PRETTY_NAME=$(cat /sys/bus/usb/devices/$DEVICE_ID/product)
echo "Disabling USB auto-suspend for device \"$DEVICE_PRETTY_NAME\" (with ID $DEVICE_ID)"
echo "on" >| "/sys/bus/usb/devices/$DEVICE_ID/power/control";
if ! { DEVICE_PRETTY_NAME=$(cat "/sys/bus/usb/devices/${DEVICE_ID}/product"); } 2> /dev/null; then
DEVICE_PRETTY_NAME="Unknown"
fi
DEVICE_INFO_MSG="USB auto-suspend for device \"${DEVICE_PRETTY_NAME}\" (with ID ${DEVICE_ID})"
echo "Disabling ${DEVICE_INFO_MSG}"
if ! (echo "on" >| "/sys/bus/usb/devices/${DEVICE_ID}/power/control") 2> /dev/null; then
echo "Unable to disable ${DEVICE_INFO_MSG}"
fi
done