chiark / gitweb /
[PATCH] update udev scsi_id to scsi_id 0.4
[elogind.git] / extras / scsi_id / gen_scsi_id_udev_rules.sh
1 #! /bin/sh
2
3 # This script generates and sends to stdout a set of udev.rules for use
4 # with all scsi block devices on your system. It creates a udev key NAME
5 # with prefix defaulting to "disk-", and appends the current kernel name
6 # and the udev kernel number (the partition number, empty for the entire
7 # disk).
8 #
9 # Managing these is probably better done via a gui interface.
10 #
11 # You can edit and append the output to your /etc/udev/udev.rules file.
12 # You probably want to to change names to be non-kernel defaults, so as to
13 # avoid confusion if a configuration change modifies /sys/block/sd*
14 # naming.
15 #
16 # /etc/scsi_id.config must be properly configured. If you are using this
17 # script, you probably want a single line enabling scsi_id for all
18 # devices as follows:
19 #
20 # options=-g
21 #
22 # The above assumes you will not attach block devices that do not
23 # properly support the page codes used by scsi_id, this is especially true
24 # of many USB mass storage devices (mainly flash card readers).
25 #
26
27 prefix=disk-
28 scsi_id=/sbin/scsi_id
29
30 dump_ids()
31 {
32         cd ${sysfs_dir}/block
33         for b in sd*
34         do
35                 echo -n "$b "
36                 $scsi_id -s /block/$b
37                 if [ $? != 0 ]
38                 then
39                         echo $0 failed for device $b >&2
40                         exit 1
41                 fi
42         done
43 }
44
45 sysfs_dir=$(mount | awk '$5 == "sysfs" {print $3}')
46
47 c=$(ls /${sysfs_dir}/block/sd* 2>/dev/null | wc -l)
48 if [ $c = 0 ]
49 then
50         echo $0 no block devices present >&2
51         exit 1
52 fi
53
54 echo "#"
55 echo "# Start of autogenerated scsi_id rules. Edit the NAME portions of these"
56 echo "# rules to your liking."
57 echo "#"
58 first_line=yes
59 dump_ids | while read in
60 do
61         set $in
62         name=$1
63         shift
64         id="$*"
65         if [ $first_line = "yes" ]
66         then
67                 first_line=no
68                 echo "BUS=\"scsi\", PROGRAM=\"${scsi_id}\", RESULT=\"${id}\", NAME=\"${prefix}${name}%n\""
69                 echo
70                 echo "# Further RESULT keys use the result of the last PROGRAM rule."
71                 echo "# Be careful not to add any rules containing PROGRAM key between here"
72                 echo "# and the end of this section"
73                 echo
74         else
75                 # No PROGRAM, so just use the last result of PROGRAM. The
76                 # following is the same as the above without the PROGRAM
77                 # key.
78                 echo "BUS=\"scsi\", RESULT=\"${id}\", NAME=\"${prefix}${name}%n\""
79         fi
80
81 done
82
83 echo "#"
84 echo "# End of autogenerated scsi_id rules"
85 echo "#"