chiark / gitweb /
7a14e866a623884e246c3cef8982caace4978f2f
[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="%2c", SYMLINK="cdrom"
6 # CALLOUT, BUS="scsi", PROGRAM="name_cdrom.pl %M %m", ID="good*", NAME="%2c", 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 unlink($dev_node);
31 if (system("mknod $dev_node b $major $minor")) {
32        die "bad mknod failed";
33 }
34
35 # get it on
36 my %cd=get_cddb(\%config);
37
38 # remove the dev node we just created
39 unlink($dev_node);
40
41 # print out our cd name if we have found it
42 unless(defined $cd{title}) {
43         print"bad unknown cdrom\n";
44 } else {
45         $cd{artist} =~ s/ /_/g;
46         $cd{title} =~ s/ /_/g;
47         print "good $cd{artist}-$cd{title}\n";
48 }