chiark / gitweb /
[PATCH] udev_volume_id: fix FAT label reading
[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 # KERNEL="[hs]d[a-z]", PROGRAM="name_cdrom.pl %M %m", NAME="%c{1}", SYMLINK="cdrom"
6
7 use strict;
8 use warnings;
9
10 use CDDB_get qw( get_cddb );
11
12 my $dev_node = "/tmp/cd_foo";
13
14 # following variables just need to be declared if different from defaults
15 my %config;
16 $config{CDDB_HOST}="freedb.freedb.org";         # set cddb host
17 $config{CDDB_PORT}=8880;                        # set cddb port
18 $config{CDDB_MODE}="cddb";                      # set cddb mode: cddb or http
19 $config{CD_DEVICE}="$dev_node";                 # set cd device
20
21 # No user interaction, this is a automated script!
22 $config{input}=0;
23
24 my $major = $ARGV[0];
25 my $minor = $ARGV[1];
26
27 # create our temp device node to read the cd info from
28 unlink($dev_node);
29 if (system("mknod $dev_node b $major $minor")) {
30        die "bad mknod failed";
31 }
32
33 # get it on
34 my %cd=get_cddb(\%config);
35
36 # remove the dev node we just created
37 unlink($dev_node);
38
39 # print out our cd name if we have found it or skip rule by nonzero exit
40 if (defined $cd{title}) {
41         $cd{artist} =~ s/ /_/g;
42         $cd{title} =~ s/ /_/g;
43         print "$cd{artist}-$cd{title}\n";
44 } else {
45         exit -1;
46 }