From c812bd67b780f7b32fe92b45ccc0073a20e4b45d Mon Sep 17 00:00:00 2001 From: Nazar Sopiha Date: Fri, 19 Feb 2021 01:37:18 +0200 Subject: [PATCH 1/3] Add skript skeleton Signed-off-by: Nazar Sopiha --- hwdetect/hwdetect.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 hwdetect/hwdetect.sh diff --git a/hwdetect/hwdetect.sh b/hwdetect/hwdetect.sh new file mode 100755 index 0000000..8c6eb2b --- /dev/null +++ b/hwdetect/hwdetect.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +#prev_state = $(ls /dev*) + +echo "Checking connected HW" + +while true +do + echo "TEST" +sleep 1 +done + From be6fecc91e79d85e03486a0518e180e5c82d0fdb Mon Sep 17 00:00:00 2001 From: Nazar Sopiha Date: Fri, 19 Feb 2021 02:08:25 +0200 Subject: [PATCH 2/3] Detect i2c and flash It is now detecting i2c (not via checking but just via ls command, don't know why function gets an error). Then script goes into an infinite cycle - for further decetions of plugged and unplugged hardware Signed-off-by: Nazar Sopiha --- hwdetect/hwdetect.sh | 60 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/hwdetect/hwdetect.sh b/hwdetect/hwdetect.sh index 8c6eb2b..7c956de 100755 --- a/hwdetect/hwdetect.sh +++ b/hwdetect/hwdetect.sh @@ -1,12 +1,68 @@ #!/bin/bash -#prev_state = $(ls /dev*) +#TODO: Detect plugged and unplugged irt +# + + + + +#somewhy this function gets an error ./hwdetect.sh: line 15: i2c_devices: command not found + +#function plugged_i2c() +#{ +# i2c_devices = $(ls /dev/i2c-*) +# echo "****Connected I2C****" +# for i2c in $i2c_devices +# do +# echo $i2c +# done +#} + +#credits to olegovich22, like his implementation +function plugged_flash_drivers() +{ + flash_devices=$(ls /dev/sd*) + if [ -n "$flash_devices" ] + then + + echo + echo "****Connected Flash drivers****" + + for d in $flash_devices + do + tput setaf 1 + echo -n "Detected flash driver controler on " + echo $d + tput sgr0 + tput setaf 2 + echo $(udevadm info $d | grep -oE "MODEL=.*") + echo $(udevadm info $d | grep -oE "VENDOR=.*") + echo -n $(udevadm info $d | grep -oE "BUS=.*") + tput sgr0 + echo + done + + echo + + fi +} + echo "Checking connected HW" + +echo "****Connected I2C****" +for i2c in $(ls /dev/i2c-*) +do + echo $i2c +done + +plugged_flash_drivers + while true do - echo "TEST" + echo "Detecting plugged and unplugged hardware. TBD" + #check in real time sleep 1 done From d0a13326ba79e0f564c7c4bb15d6fc569a604e9b Mon Sep 17 00:00:00 2001 From: Nazar Sopiha Date: Fri, 19 Feb 2021 02:08:25 +0200 Subject: [PATCH 3/3] Detect i2c and flash It is now detecting i2c and flash connected devices Then script goes into an infinite cycle - for further decetions of hot plugged and unplugged hardware Signed-off-by: Nazar Sopiha --- hwdetect/hwdetect.sh | 71 +++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/hwdetect/hwdetect.sh b/hwdetect/hwdetect.sh index 7c956de..3598954 100755 --- a/hwdetect/hwdetect.sh +++ b/hwdetect/hwdetect.sh @@ -1,68 +1,57 @@ #!/bin/bash #TODO: Detect plugged and unplugged irt -# -#somewhy this function gets an error ./hwdetect.sh: line 15: i2c_devices: command not found - -#function plugged_i2c() -#{ -# i2c_devices = $(ls /dev/i2c-*) -# echo "****Connected I2C****" -# for i2c in $i2c_devices -# do -# echo $i2c -# done -#} +function plugged_i2c() +{ + i2c_devices=$(ls /dev/i2c-*) + if [ -n "$i2c_devices" ] ; then + echo "****Connected I2C****" + for i2c in $i2c_devices ; do + echo $i2c + done + fi +} #credits to olegovich22, like his implementation function plugged_flash_drivers() { flash_devices=$(ls /dev/sd*) - if [ -n "$flash_devices" ] - then - - echo - echo "****Connected Flash drivers****" - - for d in $flash_devices - do - tput setaf 1 - echo -n "Detected flash driver controler on " - echo $d - tput sgr0 - tput setaf 2 - echo $(udevadm info $d | grep -oE "MODEL=.*") - echo $(udevadm info $d | grep -oE "VENDOR=.*") - echo -n $(udevadm info $d | grep -oE "BUS=.*") - tput sgr0 + if [ -n "$flash_devices" ] ; then echo - done - - echo - + echo "****Connected Flash drivers****" + + for d in $flash_devices ; do + tput setaf 1 + echo -n "Detected flash driver controler on " + echo $d + tput sgr0 + tput setaf 2 + echo $(udevadm info $d | grep -oE "MODEL=.*") + echo $(udevadm info $d | grep -oE "VENDOR=.*") + echo -n $(udevadm info $d | grep -oE "BUS=.*") + tput sgr0 + echo + done fi } -echo "Checking connected HW" - +echo "****Checking connected HW****" +echo " " -echo "****Connected I2C****" -for i2c in $(ls /dev/i2c-*) -do - echo $i2c -done +plugged_i2c plugged_flash_drivers + while true do echo "Detecting plugged and unplugged hardware. TBD" #check in real time -sleep 1 +sleep 3 done