2004-01-06 12:11:53 +03:00
#!/usr/bin/perl
# a horribly funny script that shows how flexible udev can really be
# This is to be executed by udev with the following rules:
2004-01-14 05:34:38 +03:00
# KERNEL="[hs]d[a-z]", PROGRAM="name_cdrom.pl %M %m", NAME="%1c", SYMLINK="cdrom"
2004-01-06 12:11:53 +03:00
2004-01-14 05:34:38 +03:00
use strict ;
use warnings ;
2004-01-06 12:11:53 +03:00
2004-01-14 05:34:38 +03:00
use CDDB_get qw( get_cddb ) ;
2004-01-06 12:11:53 +03:00
2004-01-14 05:34:38 +03:00
my $ dev_node = "/tmp/cd_foo" ;
2004-01-06 12:11:53 +03:00
# following variables just need to be declared if different from defaults
2004-01-14 05:34:38 +03:00
my % config ;
2004-01-06 12:11:53 +03:00
$ config { CDDB_HOST } = "freedb.freedb.org" ; # set cddb host
$ config { CDDB_PORT } = 8880 ; # set cddb port
$ config { CDDB_MODE } = "cddb" ; # set cddb mode: cddb or http
$ config { CD_DEVICE } = "$dev_node" ; # set cd device
# No user interaction, this is a automated script!
$ config { input } = 0 ;
2004-01-14 05:34:38 +03:00
my $ major = $ ARGV [ 0 ] ;
my $ minor = $ ARGV [ 1 ] ;
2004-01-06 12:11:53 +03:00
# create our temp device node to read the cd info from
2004-01-10 12:04:13 +03:00
unlink ( $ dev_node ) ;
2004-01-06 12:11:53 +03:00
if ( system ( "mknod $dev_node b $major $minor" ) ) {
die "bad mknod failed" ;
2004-01-10 12:04:13 +03:00
}
2004-01-06 12:11:53 +03:00
# get it on
my % cd = get_cddb ( \ % config ) ;
# remove the dev node we just created
unlink ( $ dev_node ) ;
2004-01-14 05:34:38 +03:00
# print out our cd name if we have found it or skip rule by nonzero exit
if ( defined $ cd { title } ) {
2004-01-10 12:04:13 +03:00
$ cd { artist } =~ s/ /_/g ;
$ cd { title } =~ s/ /_/g ;
2004-01-14 05:34:38 +03:00
print "$cd{artist}-$cd{title}\n" ;
} else {
exit - 1 ;
2004-01-06 12:11:53 +03:00
}