Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revisionBoth sides next revision
docs:guide-user:base-system:hotplug [2024/08/23 09:37] – Do not parse the output of ls oliv3rdocs:guide-user:base-system:hotplug [2024/08/23 10:25] – Avoid duplication/duplicate execution oliv3r
Line 199: Line 199:
 An other script to create a symlink instead of renaming the device. An other script to create a symlink instead of renaming the device.
  
-<code ash>+<code bash>
 cat << "EOF" > /etc/hotplug.d/usb/20-cp210x cat << "EOF" > /etc/hotplug.d/usb/20-cp210x
 CP210_PRODID='10c4/ea60/100' CP210_PRODID='10c4/ea60/100'
Line 206: Line 206:
 set -eu set -eu
  
-if [ "${PRODUCT:-}" = "${CP210_PRODID}" ]; then+if [ "${DEVTYPE:-}" = 'usb_interface' ] && \ 
 +   [ "${PRODUCT:-}" = "${CP210_PRODID}" ]; then
  if [ "${ACTION:-}" = 'bind' ]; then  if [ "${ACTION:-}" = 'bind' ]; then
 + if [ -L "/dev/${SYMLINK}" ]; then
 + logger -t hotplug "Symlink '/dev/${SYMLINK}' already exists"
 + exit 0
 + fi
 +
  DEVICE_NAME="$(find /sys${DEVPATH:-} -maxdepth 1 -type d -iname 'ttyUSB*' -exec basename {} \;)"  DEVICE_NAME="$(find /sys${DEVPATH:-} -maxdepth 1 -type d -iname 'ttyUSB*' -exec basename {} \;)"
  if [ -z "${DEVICE_NAME}" ]; then  if [ -z "${DEVICE_NAME}" ]; then
Line 213: Line 219:
  exit 0  exit 0
  fi  fi
 +
  logger -t hotplug "Device name of cp210 is '${DEVICE_NAME}'"  logger -t hotplug "Device name of cp210 is '${DEVICE_NAME}'"
  ln -s "/dev/${DEVICE_NAME}" "/dev/${SYMLINK}"  ln -s "/dev/${DEVICE_NAME}" "/dev/${SYMLINK}"
  logger -t hotplug "Symlink from '/dev/${DEVICE_NAME}' to '/dev/${SYMLINK}' created"  logger -t hotplug "Symlink from '/dev/${DEVICE_NAME}' to '/dev/${SYMLINK}' created"
  fi  fi
-fi + 
-  +
-if [ "${PRODUCT:-}" = "${CP210_PRODID}" ]; then+
  if [ "${ACTION:-}" = 'unbind' ]; then  if [ "${ACTION:-}" = 'unbind' ]; then
  rm "/dev/${SYMLINK}"  rm "/dev/${SYMLINK}"
  • Last modified: 2024/12/19 04:42
  • by pythonic