#!/usr/bin/perl -wT
# vim: set sw=4 ts=4 si et: 
# Written by Katja and Guido Socher
# run this file with chmod 6755 to allow the normal user
# to burn a CD without beeing root.
# 
# adapt the next line to the device number that you 
# get from the command cdrecord -scanbus
my $dev="0,4,0";
#
%ENV=();
$ENV{'PATH'}='/bin:/usr/bin:/usr/local/bin';
sub help(){
    print "cdrecordeasy -- record a normal data CD from an image file

USAGE: cdrecordeasy image.file

EXAMPLE: cdrecordeasy image.file
Explanation: The image.file will written to cdrom.

You can preview your CD before burning with the following command:
mount -o loop -t iso9660 image.file /some/directory
";
    exit 0;
}
# run a command and use unbuffered IO to display the
# output while the command is still running.
sub runcmd($){
    my $cmd=shift;
    $|=1;
    my $buff;
    open(PP,"$cmd 2>&1 |")||die;
    while(sysread(PP,$buff,8)>0){
        print "$buff";
    }
    close PP;
}
if ($ARGV[0] && $ARGV[0] eq "-h"){
    help();
}
help() if (scalar @ARGV !=1 );
$<=$>;
my $file="";
# untaint it:
if ($ARGV[0] =~/([#-~]+)/){
    $file=$1;
}else{
    die "ERROR: invalid file name $ARGV[0]\n";
}
die "ERROR: can not read image file: $file\n" unless( -r "$file");
#print `id`;
runcmd("cdrecord -v dev=$dev speed=4 $file");
__END__

