Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions hwdetect/hwdetect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

function find_sdcard()
{
ls /dev | grep mmcblk
lsblk | grep sda
}

function find_i2c()
{
mapfile -t i2c_array < <(ls /dev | grep i2c)
for i in ${i2c_array[@]}; do
echo $i
done
Comment on lines +11 to +14
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • inconsistent indentation;

Not mistake, but I'm just curious why arrays are used here if the results are actually not processed in any way which requires it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided that it could be processed later, but I had no opportunity to check the workflow of this part of the script on my laptop. Probably I`ll check it later on the board.

}

function find_usb_ttl()
{
if ! command -v lsusb &> /dev/null
then
echo "COMMAND lsusb could not be found"
echo "Please install it before"
return -1
fi
lsusb | grep "USB-Serial"
}

function find_flash()
{
if ! command -v lsblk &> /dev/null
then
echo "COMMAND lsblk could not be found"
echo "Please install it before"
return -1
fi
lsblk -rno SIZE,NAME,HOTPLUG,MOUNTPOINT | grep -w 1| grep -vE "sr|loop" | awk '{if ($4 != "") print $1, " ", $4}'
}

while true; do
PS3='Choose the type of the device: '
options=("USB to TTL convertors" "Flash drives" "SD cards" "i2c" "Quit")
select opt in "${options[@]}"
do
case $opt in
"USB to TTL convertors")
echo "Detected $opt:"
find_usb_ttl
;;
"Flash drives")
echo "Detected $opt:"
find_flash
;;
"SD cards")
echo "Detected $opt:"
find_sdcard
;;
"i2c")
echo "Detected $opt:"
find_i2c
;;
"Quit")
exit 0
;;
*) echo "Invalid option $REPLY";;
esac
done
done