Created changelog file, will be updated after new release
[simpleburner.git] / simpleburner.pl
blob0bca3b544dfc725ce0b8db752ed085b28baa4c88
1 #!/usr/bin/env perl
2 # file: made to simplyfi CD/DVD burning under CLI
3 #
4 # Copyright 2009 Marcin Karpezo <sirmacik at gmail dot com>
5 # license = BSD
6 # version = 20091028
7 # All rights reserved.
9 # Redistribution and use in source and binary forms, with or without modification,
10 # are permitted provided that the following conditions are met:
11 # * Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # * Neither the name of the simpleburner nor the names of its contributors may
17 # be used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 use encoding 'utf8';
32 use strict;
33 use warnings;
34 use Getopt::Long;
36 my $writer = "";
37 my $isomaker = "";
38 my $datadir = "";
39 my $isoname = "/tmp/cd.iso";
40 my $device = "/dev/sr0";
41 my $speed ="";
42 my $mode = "tao";
43 my $test = "";
44 my $burn = "";
45 my $make = "";
47 GetOptions("data=s" => \$datadir,
48 "name=s" => \$isoname,
49 "device=s" => \$device,
50 "speed=s" => \$speed,
51 "mode=s" => \$mode,
52 "t|test" => \$test,
53 "b|burn-only" => \$burn,
54 "m|makeiso" => \$make,
55 "h|help" => \&helpmsg,);
57 sub helpmsg {
58 my $helpmsg = <<EOM;
59 Simpleburner, made to simplyfi CD/DVD burning under CLI
60 Usage: simpleburner [options]
62 -h, --help Displays this message
63 --data Directory with data to burn
64 --name Path and/or name of iso image (by default /tmp/cd.iso)
65 --device Device to use (default /dev/sr0)
66 --speed Burning speed (by default it will be autodetected)
67 --mode Burning mode, available options are: TAO (default), DAO, SAO, RAW
68 -t, --test Run in test mode
69 -b, --burn-only Run without making iso image
70 -m, --makeiso Make only iso image
72 Please send any bug reports to simpleburner-bugs\@googlegroups.com
73 EOM
74 print($helpmsg);
75 exit 0;
77 sub programcheck {
78 print("Looking for cdrkit...");
79 if (-e '/usr/bin/wodim' and -e '/usr/bin/genisoimage') {
80 $writer = 'wodim';
81 $isomaker = 'genisoimage';
82 print("[OK!]\n");
83 } elsif (-e '/usr/bin/cdrecord' and -e '/usr/bin/mkisofs') {
84 print("Not found\nLooking for cdrtools...");
85 $writer = 'cdrecord';
86 $isomaker = 'mkisofs';
87 print("[OK!]\n");
88 } else {
89 print("Not found: Please install cdrkit or cdrtools!\n");
90 exit 1;
94 sub optcheck {
95 unless ($burn) {
96 unless ($datadir) {
97 print("Failed! You must deine --data option.\nRun -h|--help for more information.\n");
98 exit 1;
101 unless ( -d $datadir) {
102 print("Failed! Data directory '$datadir' does not exist.\n");
103 exit 1;
107 sub oldisock {
108 print("Old iso file detected, delete it? [Y/n] "); my $reply=<STDIN>; chomp $reply;
109 if ($reply eq "n") {
110 print("Burn it? [Y/n] "); my $reply=<STDIN>; chomp $reply;
111 if ($reply eq "n") {
112 print("Stopped!\n");
113 exit 1;
114 } else {
115 &burniso;
116 exit 0;
118 } else {
119 print("Deleting old iso file...");
120 unlink($isoname);
121 print("[OK]\n");
125 sub makeiso {
126 if (-e $isoname) {
127 &oldisock;
129 print("Making iso image...\n");
130 $datadir =~ s/\s+/\\ /g;
131 my $command = "$isomaker -UR -quiet -allow-multidot -allow-leading-dots -iso-level 3 -o $isoname $datadir";
132 system($command);
133 unless ($? == "0") {
134 die "Can't make iso file!\n";
136 print("[OK!]\nFile stored in $isoname\n");
139 sub burniso {
140 print("Burning iso...\n");
141 my $burnspeed = "";
142 my $runtest = "";
143 if ($speed) {
144 $burnspeed = " --speed=$speed";
145 } elsif ($test) {
146 $runtest = "--dummy";
148 my $command = "$writer --eject -vs -$mode --dev=$device $burnspeed $runtest $isoname";
149 system("$command > /dev/null");
150 unless ($? == "0") {
151 die "Can't burn disc!\n";
153 print("[OK!]\n");
156 if ($isoname =~ m/^~/) {
157 $isoname =~ s/^~/$ENV{'HOME'}/;
160 if ($datadir =~ m/^~/) {
161 $datadir =~ s/^~/$ENV{'HOME'}/;
166 &programcheck;
167 &optcheck;
168 if ($burn) {
169 &burniso;
170 } elsif ($make) {
171 &makeiso;
172 } else {
173 &makeiso;
174 &burniso;
177 #TODO:
178 # ** Add audiocd burning 2009-10-26 21:33+0100