add scan_scsi.linux
[platform/upstream/cdrkit.git] / packaging / scan_scsi.linux
1 #!/bin/bash
2 #
3 # show generic devices for CDROM SCSI devices
4 #
5 # needs a mounted /proc filesystem, printf, echo and grep
6 #
7 # when invoked with a number, the n-th cdrom SCSI address is
8 # printed.
9 #
10 # example: 'scan_scsi.linux 2' will print the SCSI settings for
11 #          the second cdrom device, namely '0,4,0' in my
12 #          system.
13 #
14 # BUGS: limited to 9 devices
15 #
16
17 NUMBER=0
18 LETTER=a
19 while read ID; do
20         if [ ".${ID%%' '}" = ".Attached devices:" ]; then
21                 continue;
22         fi
23         read ignore;
24         read ignore type ignore;
25         echo $ID '  ' $type ' -> ' /dev/sg$NUMBER
26         #echo $ID '  ' $type ' -> ' /dev/sg$NUMBER or /dev/sg$LETTER
27         NUMBER=$(($NUMBER + 1))
28 #done <test_scanscsi | grep "WORM\|CD-ROM" |
29 done </proc/scsi/scsi | grep "WORM\|CD-ROM" | \
30 (DRIVES=1
31 while read CD_DRIVE; do
32         if test $# -ne 0; then
33                 if test $DRIVES -eq $1; then
34                         CD_DRIVE=${CD_DRIVE#Host: scsi}
35                         SCSIHOST=${CD_DRIVE%% *}
36                         CHANNEL=${CD_DRIVE#*Channel: }
37                         CHANNEL=${CHANNEL%% *}
38                         SCSIID=${CD_DRIVE#*Id: }
39                         SCSIID=${SCSIID%% *}
40                         SCSILUN=${CD_DRIVE#*Lun: }
41                         SCSILUN=${SCSILUN%% *}
42                         #CD_DRIVE=${CD_DRIVE% or /dev/*}
43                         echo ${CHANNEL},${SCSIID},${SCSILUN}
44                         break;
45                 fi
46         else
47                         echo ${CD_DRIVE}
48         fi
49         DRIVES=$(($DRIVES + 1))
50 done)