]> git.ipfire.org Git - thirdparty/systemd.git/blame - extras/name_cdrom.pl
[PATCH] oops forgot to add the new klibc/include directory
[thirdparty/systemd.git] / extras / name_cdrom.pl
CommitLineData
a05b7750
GKH
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:
88f09368 5# KERNEL="[hs]d[a-z]", PROGRAM="name_cdrom.pl %M %m", NAME="%c{1}", SYMLINK="cdrom"
a05b7750 6
33084f1e
KS
7use strict;
8use warnings;
a05b7750 9
33084f1e 10use CDDB_get qw( get_cddb );
a05b7750 11
33084f1e 12my $dev_node = "/tmp/cd_foo";
a05b7750
GKH
13
14# following variables just need to be declared if different from defaults
33084f1e 15my %config;
a05b7750
GKH
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
33084f1e
KS
24my $major = $ARGV[0];
25my $minor = $ARGV[1];
a05b7750
GKH
26
27# create our temp device node to read the cd info from
d6e86b37 28unlink($dev_node);
a05b7750
GKH
29if (system("mknod $dev_node b $major $minor")) {
30 die "bad mknod failed";
d6e86b37 31}
a05b7750
GKH
32
33# get it on
34my %cd=get_cddb(\%config);
35
36# remove the dev node we just created
37unlink($dev_node);
38
33084f1e
KS
39# print out our cd name if we have found it or skip rule by nonzero exit
40if (defined $cd{title}) {
d6e86b37
KS
41 $cd{artist} =~ s/ /_/g;
42 $cd{title} =~ s/ /_/g;
33084f1e
KS
43 print "$cd{artist}-$cd{title}\n";
44} else {
45 exit -1;
a05b7750 46}