Re: [Slightly-OT] On usability: managing usb devices & network profiles in a ion3 environment

Antonio De Leon <[email protected]>
Newsgroups gmane.comp.window-managers.ion.general
Message-ID <[email protected]>
On the question of detecting usb devices this tool can help on the
detection part.
lookfor-sd-devs.sh (application/x-sh, 1.4 KB)
#!/bin/bash
# $Id$

# desc: output /var/tmp/usb_sd[a-z][0-9] as text file, in it desc and size 
# 			of the device, and to stdout

export syspath=/sys/block
# ex. usblist="sda1 sdb"
export usblist=""
export tmpmnt="$(mktemp -d /tmp/tmp.XXXXXX)"

# notes: needs lsscsi
find_dev ()
{
	local n

	for b in  $(lsscsi -H|grep usb-storage|tr -d "[]"|sed 's/usb-storage//g'|tr "\n" " ") ; do
		d[$((++n))]="$(lsscsi |grep \\[$b |awk '{print $NF}')"
	done

	local l
	
	for l in ${d[*]} ; do
		echo $l
		usblist="${usblist} $(_test_mount $(basename $l))"
	done

	if [ -z "$usblist" ]; then
		return 1
	else
		echo $usblist
	fi
}

# param: 1:sdX
_test_mount () 
{
	local l=$1
	for n in 0 1 2 3 4 5 6 7 8 9; do
		mount -o ro /dev/${l}${n/0/\ } $tmpmnt >/dev/null 2>&1
		if [ "$?" -eq "0" ]; then 
			echo ${l}${n/0/\ }
		fi
		umount /dev/${l}${n/0/\ } $tmpmnt >/dev/null 2>&1
	done
}

id_dev ()
{
	local V
	local M
	local S
	local tmpdir="/var/tmp"

	for u in $usblist; do
		V="$(< $syspath/$(echo $u|tr -d [1-9])/device/vendor)"	
		M="$(< $syspath/$(echo $u|tr -d [1-9])/device/model)"	
		S="$(fdisk -l /dev/${u} 2>/dev/null |grep -E "GB|MB" |cut -f2 -d":"|cut -f1 -d",")"
		#
		echo "Device: $u" > $tmpdir/usb_${u}
		echo "Brand: $V" >> $tmpdir/usb_${u}
		echo "Model: $M" >> $tmpdir/usb_${u}
		echo "Size: ${S}" >> $tmpdir/usb_${u}
		cat $tmpdir/usb_${u}
	done
}

find_dev && id_dev

# vim: ts=2 bs=2
# lookfor-sd-devs.sh: end
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.