diff --git a/circlean_fs/root_partition/etc/udev/rules.d/10-usb.rules b/circlean_fs/root_partition/etc/udev/rules.d/10-usb.rules index bbe5128..5480269 100644 --- a/circlean_fs/root_partition/etc/udev/rules.d/10-usb.rules +++ b/circlean_fs/root_partition/etc/udev/rules.d/10-usb.rules @@ -1,3 +1,3 @@ # The purpose of this rules file is to ensure that the top left usb port and its partitions have a symlink to /dev/source_key[num], and the other ports to /dev/dest_key[num] -KERNEL=="sd*", KERNELS=="1-1.2", SUBSYSTEMS=="usb", SYMLINK+="source_key%n" -KERNEL=="sd*", KERNELS=="1-1.[3-5]", SUBSYSTEMS=="usb", SYMLINK+="dest_key%n" +KERNEL=="sd*", KERNELS=="1-1.[1-5]", SUBSYSTEMS=="usb", PROGRAM="/usr/local/bin/identifyusbport.sh %p %k add", SYMLINK+="%c%n" +ACTION=="remove", KERNELS=="1-1.[1-5]", SUBSYSTEMS=="usb", PROGRAM="/usr/local/bin/identifyusbport.sh %p %k remove" diff --git a/circlean_fs/root_partition/usr/local/bin/identifyusbport.sh b/circlean_fs/root_partition/usr/local/bin/identifyusbport.sh new file mode 100644 index 0000000..18fbefe --- /dev/null +++ b/circlean_fs/root_partition/usr/local/bin/identifyusbport.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +DEBUG_FILE=/dev/shm/identifyusbport.txt +ACTION="connected" +DEVPATH="$1" +USBPORT="$2" + +function FoundSource(){ + echo "upper left connected, source_key '${USBPORT}' ${ACTION}" >> ${DEBUG_FILE} + echo source_key +} + +echo -e "\nStart" >> ${DEBUG_FILE} +echo "Parameter 1: $1" >> ${DEBUG_FILE} +echo "Parameter 2: $2" >> ${DEBUG_FILE} +echo "Parameter 3: $3" >> ${DEBUG_FILE} + +if (echo "$3" | grep -q "remove") ; then + if (echo "$2" | grep -v -q "1-1.") ; then + echo "ignore unknown remove $2" >> ${DEBUG_FILE} + exit 0 + fi + if (echo "$2" | grep -q ":") ; then + echo "ignore remove subpath $2" >> ${DEBUG_FILE} + exit 0 + fi + ACTION="disconnected" + DEVPATH="${2}/" +fi + +MODEL=$(cat /proc/device-tree/model | tr -d '\000') +echo Device model: ${MODEL} >> ${DEBUG_FILE} +echo Devpath: ${DEVPATH} >> ${DEBUG_FILE} + +if (echo "$MODEL" | grep -q "Raspberry Pi 3 Model B Plus") ; then + echo "found Raspberry Pi 3 B+ with special assignment" >> ${DEBUG_FILE} + if (echo "${DEVPATH}" | grep -q "1-1.1.2/") ; then + FoundSource + exit 0 + fi +elif (echo "$MODEL" | grep -q "Raspberry Pi 4 Model B") ; then + echo "found Raspberry Pi 4 B with special assignment" >> ${DEBUG_FILE} + if (echo "${DEVPATH}" | grep -q "1-1.3/") ; then + FoundSource + exit 0 + fi +else + echo "unsing default mapping" >> ${DEBUG_FILE} + if (echo "${DEVPATH}" | egrep -q "1-1.1/|1-1.2/") ; then + FoundSource + exit 0 + fi +fi +echo "dest_key $2 $ACTION" >> ${DEBUG_FILE} +echo dest_key +