commit 3c660b4fc7c2bacd9c6e490bb44b8b926488b51e
parent 20926fa6f82749607b63b7a860cb2a79b86311c4
Author: Johannes Schauer Marin Rodrigues <josch@mister-muffin.de>
Date: Thu, 18 Jan 2024 07:46:03 +0100
reform2-keyboard-fw/flash.sh: cater for udev older than 250 (Ubuntu 22.04)
Diffstat:
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/reform2-keyboard-fw/flash.sh b/reform2-keyboard-fw/flash.sh
@@ -12,6 +12,17 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1
fi
+get_property() {
+ path="$1"
+ property="$2"
+ if [ "$(udevadm --version)" -lt 250 ]; then
+ # no udevadm --property before version 250
+ udevadm info --query=property "$path" | sed -ne "s/^$property=//p"
+ else
+ udevadm info --query=property --property="$property" --value "$path"
+ fi
+}
+
find_usb_device() {
result=
for p in /sys/bus/usb/devices/*; do
@@ -19,7 +30,7 @@ find_usb_device() {
[ "$(cat "$p/idVendor")" = "$1" ] || continue
[ -e "$p/idProduct" ] || continue
[ "$(cat "$p/idProduct")" = "$2" ] || continue
- [ "$(udevadm info --query=property --property=ID_MODEL --value "$p")" = "$3" ] || continue
+ [ "$(get_property "$p" "ID_MODEL")" = "$3" ] || continue
if [ -n "$result" ]; then
echo "found more than one device matching $1 $2 $3" >&2
exit 1
@@ -46,8 +57,8 @@ path_keyboard=$(find_usb_device 03eb 2042 Reform_Keyboard)
busnum_keyboard=
devnum_keyboard=
if [ -n "$path_keyboard" ] && [ -e "$path_keyboard" ]; then
- busnum_keyboard="$(udevadm info --query=property --property=BUSNUM --value "$path_keyboard")"
- devnum_keyboard="$(udevadm info --query=property --property=DEVNUM --value "$path_keyboard")"
+ busnum_keyboard="$(get_property "$path_keyboard" "BUSNUM")"
+ devnum_keyboard="$(get_property "$path_keyboard" "DEVNUM")"
echo " 1. Find out your keyboard firmware version in the 'System Status' by pressing" >&2
echo " the circle key followed by the S key. The keyboard firmware version is on" >&2
echo " on the last line in a date-based format YYYYMMDD. Then either:"
@@ -86,8 +97,8 @@ if [ -z "$path" ] || [ ! -e "$path" ]; then
exit 1
fi
-busnum="$(udevadm info --query=property --property=BUSNUM --value "$path")"
-devnum="$(udevadm info --query=property --property=DEVNUM --value "$path")"
+busnum="$(get_property "$path" "BUSNUM")"
+devnum="$(get_property "$path" "DEVNUM")"
# do some extra checks if we saw the usb device as a keyboard before
if [ -n "$path_keyboard" ] && [ -e "$path_keyboard" ]; then