39 lines
912 B
Bash
Executable File
39 lines
912 B
Bash
Executable File
#!/bin/bash
|
|
|
|
|
|
#
|
|
# Find the GID of the group responsible for the serial devices
|
|
#
|
|
|
|
|
|
USB_GID=$(stat -c %g /dev/ttyS0)
|
|
|
|
|
|
#
|
|
# Find available serial devices and create appropriate flags
|
|
#
|
|
|
|
|
|
DEVICE_FLAGS=
|
|
|
|
# Taken from https://unix.stackexchange.com/a/144735 and modified slightly
|
|
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
|
|
DEVICE_FLAGS=${DEVICE_FLAGS}\ $(
|
|
syspath="${sysdevpath%/dev}"
|
|
devname="$(udevadm info -q name -p $syspath)"
|
|
[[ "$devname" == "bus/"* ]] && exit
|
|
eval "$(udevadm info -q property --export -p $syspath)"
|
|
[[ -z "$ID_SERIAL" ]] && exit
|
|
[[ "$devname" != "ttyUSB"* && "$devname" != "ttyACM"* ]] && exit
|
|
echo --device=/dev/$devname
|
|
)
|
|
done
|
|
|
|
|
|
#
|
|
# Run command in docker container
|
|
#
|
|
|
|
|
|
docker build . && docker run ${DEVICE_FLAGS} --rm --user $(id -u):${USB_GID} -v $PWD:/project -w /project -it $(docker build . -q) idf.py $@
|