chiark / gitweb /
[PATCH] add silly script that names cdrom drives based on the cd in them.
[elogind.git] / extras / name_cdrom.pl
1 #!/usr/bin/perl
2
3 # a horribly funny script that shows how flexible udev can really be
4 # This is to be executed by udev with the following rules:
5 # CALLOUT, BUS="ide", PROGRAM="name_cdrom.pl %M %m", ID="good*", NAME="%1c", SYMLINK="cdrom" 
6 # CALLOUT, BUS="scsi", PROGRAM="name_cdrom.pl %M %m", ID="good*", NAME="%1c", SYMLINK="cdrom" 
7 #
8 # The scsi rule catches USB cdroms and ide-scsi devices.
9 #
10
11 use CDDB_get qw( get_cddb );
12
13 my %config;
14
15 $dev_node = "/tmp/cd_foo";
16
17 # following variables just need to be declared if different from defaults
18 $config{CDDB_HOST}="freedb.freedb.org";         # set cddb host
19 $config{CDDB_PORT}=8880;                        # set cddb port
20 $config{CDDB_MODE}="cddb";                      # set cddb mode: cddb or http
21 $config{CD_DEVICE}="$dev_node";                 # set cd device
22
23 # No user interaction, this is a automated script!
24 $config{input}=0;
25
26 $major = $ARGV[0];
27 $minor = $ARGV[1];
28
29 # create our temp device node to read the cd info from
30 if (system("mknod $dev_node b $major $minor")) {
31        die "bad mknod failed";
32        }
33
34 # get it on
35 my %cd=get_cddb(\%config);
36
37 # remove the dev node we just created
38 unlink($dev_node);
39
40 # print out our cd name if we have found it
41 unless(defined $cd{title}) {
42         print"bad unknown cdrom\n";
43 } else {
44         print "good $cd{artist}_$cd{title}\n";
45 }