AOSPAlliance / device-flasher

Android Factory Image Flasher for Linux, macOS and Windows
https://review.calyxos.org/q/project:AOSPAlliance%252Fdevice-flasher
Other
25 stars 7 forks source link

on GNU/Linux, only prompt for sudo if the required udev rules are missing #12

Open eighthave opened 3 years ago

eighthave commented 3 years ago

Since sudo is only needed to install udev rules, this should first check whether the required udev rules are installed. The user could have already done it manually, or they could have installed the distro's package that includes these rules. Here's a sketch of how to check:

 ~ $ lsusb|grep Google
Bus 002 Device 087: ID 18d1:4ee2 Google Inc. Nexus Device (debug)
 ~ $ grep -rF PRODUCT=18d1/4ee2 /sys/devices 2> /dev/null
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1/uevent:PRODUCT=18d1/4ee2/228
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1/2-2.1:1.0/uevent:PRODUCT=18d1/4ee2/228
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1/2-2.1:1.1/uevent:PRODUCT=18d1/4ee2/228
 ~ $ udevadm info --query all --path /sys/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1/
P: /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1
N: bus/usb/002/087
L: 0
S: libmtp-2-2.1
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1
E: DEVNAME=/dev/bus/usb/002/087
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=18d1/4ee2/228
E: TYPE=0/0/0
E: BUSNUM=002
E: DEVNUM=087
E: MAJOR=189
E: MINOR=214
E: SUBSYSTEM=usb
E: USEC_INITIALIZED=403267347302
E: ID_VENDOR=asus
E: ID_VENDOR_ENC=asus
E: ID_VENDOR_ID=18d1
E: ID_MODEL=Nexus_7
E: ID_MODEL_ENC=Nexus\x207
E: ID_MODEL_ID=4ee2
E: ID_REVISION=0228
E: ID_SERIAL=asus_Nexus_7_05995813
E: ID_SERIAL_SHORT=05995813
E: ID_BUS=usb
E: ID_USB_INTERFACES=:ffff00:ff4201:
E: ID_VENDOR_FROM_DATABASE=Google Inc.
E: GPHOTO2_DRIVER=PTP
E: ID_GPHOTO2=1
E: ID_MEDIA_PLAYER=1
E: ID_MODEL_FROM_DATABASE=Nexus Device (debug)
E: adb_user=yes
E: ID_MTP_DEVICE=1
E: ID_PATH=pci-0000:00:14.0-usb-0:2.1
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1
E: ID_FOR_SEAT=usb-pci-0000_00_14_0-usb-0_2_1
E: COLORD_DEVICE=1
E: COLORD_KIND=camera
E: DEVLINKS=/dev/libmtp-2-2.1
E: TAGS=:seat:uaccess:
eighthave commented 3 years ago

This is an easier format to parse:

 ~ $ udevadm info --query property --path /sys/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1 
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2.1
DEVNAME=/dev/bus/usb/002/087
DEVTYPE=usb_device
DRIVER=usb
PRODUCT=18d1/4ee2/228
TYPE=0/0/0
BUSNUM=002
DEVNUM=087
MAJOR=189
MINOR=214
SUBSYSTEM=usb
USEC_INITIALIZED=403267347302
ID_VENDOR=asus
ID_VENDOR_ENC=asus
ID_VENDOR_ID=18d1
ID_MODEL=Nexus_7
ID_MODEL_ENC=Nexus\x207
ID_MODEL_ID=4ee2
ID_REVISION=0228
ID_SERIAL=asus_Nexus_7_05995813
ID_SERIAL_SHORT=05995813
ID_BUS=usb
ID_USB_INTERFACES=:ffff00:ff4201:
ID_VENDOR_FROM_DATABASE=Google Inc.
GPHOTO2_DRIVER=PTP
ID_GPHOTO2=1
ID_MEDIA_PLAYER=1
ID_MODEL_FROM_DATABASE=Nexus Device (debug)
adb_user=yes
ID_MTP_DEVICE=1
ID_PATH=pci-0000:00:14.0-usb-0:2.1
ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1
ID_FOR_SEAT=usb-pci-0000_00_14_0-usb-0_2_1
COLORD_DEVICE=1
COLORD_KIND=camera
DEVLINKS=/dev/libmtp-2-2.1
TAGS=:seat:uaccess: