simpleburner development restarted! I need to refresh python so python is also back
[simpleburner.git] / simpleburner.pl
blob98552e9f5fc45d330c55871ed4019992927e380b
1 #!/usr/bin/env perl
2 # file: made to simplyfi CD/DVD burning under CLI
3 #
4 # Copyright 2009, 2010 Marcin Karpezo <sirmacik at gmail dot com>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use encoding 'utf8';
21 use strict;
22 use warnings;
23 use Getopt::Long;
25 my $writer = "";
26 my $isomaker = "";
27 my $datadir = "/tmp";
28 my $isoname = "~/cd.iso";
29 my $device = "/dev/sr0";
30 my $speed ="";
31 my $mode = "tao";
32 my $test = "";
33 my $burn = "";
34 my $make = "";
36 GetOptions("data=s" => \$datadir,
37 "name=s" => \$isoname,
38 "device=s" => \$device,
39 "speed=s" => \$speed,
40 "mode=s" => \$mode,
41 "t|test" => \$test,
42 "b|burn-only" => \$burn,
43 "m|makeiso" => \$make,
44 "h|help" => \&helpmsg,);
46 sub warning {
47 print <<END;
48 simpleburner, made to simplyfi CD/DVD burning under CLI
50 simpleburner Copyright (C) 2009, 2010 Marcin Karpezo
51 This program comes with ABSOLUTELY NO WARRANTY.
52 This is free software, and you are welcome
53 to redistribute it under certain conditions.
54 For details see COPYING file.
56 END
59 sub helpmsg {
60 &warning;
61 print <<EOM;
62 Simpleburner, made to simplyfi CD/DVD burning under CLI
63 Usage: simpleburner [options]
65 -h, --help Displays this message
66 --data Directory with data to burn
67 --name Path and/or name of iso image (by default ~/cd.iso)
68 --device Device to use (default /dev/sr0)
69 --speed Burning speed (by default it will be autodetected)
70 --mode Burning mode, available options are: TAO (default), DAO, SAO, RAW
71 -t, --test Run in test mode
72 -b, --burn-only Run without making iso image
73 -m, --makeiso Make only iso image
75 Please send any bug reports or feuture requests to simpleburner-bugs\@googlegroups.com
76 EOM
77 exit 0;
79 sub programcheck {
80 print("Looking for cdrkit...");
81 if (-e '/usr/bin/wodim' and -e '/usr/bin/genisoimage') {
82 $writer = 'wodim';
83 $isomaker = 'genisoimage';
84 print("[OK!]\n");
85 } elsif (-e '/usr/bin/cdrecord' and -e '/usr/bin/mkisofs') {
86 print("Not found\nLooking for cdrtools...");
87 $writer = 'cdrecord';
88 $isomaker = 'mkisofs';
89 print("[OK!]\n");
90 } else {
91 print("Not found: Please install cdrkit or cdrtools!\n");
92 exit 1;
96 sub optcheck {
97 unless ($burn) {
98 unless ($datadir) {
99 print("Failed! You must define --data option.\nRun -h|--help for more information.\n");
100 exit 1;
103 unless ( -d $datadir) {
104 print("Failed! Data directory '$datadir' does not exist.\n");
105 exit 1;
109 sub makeiso {
110 if (-e $isoname) {
111 &oldisock;
113 print("Making iso image...\n");
114 $datadir =~ s/\s+/\\ /g;
115 my $command = "$isomaker -UR -quiet -allow-multidot -allow-leading-dots -iso-level 3 -o $isoname $datadir";
116 system($command);
117 unless ($? == "0") {
118 die "Can't make iso file!\n";
120 print("[OK!]\nFile stored in $isoname\n");
123 sub burniso {
124 print("Burning iso...\n");
125 my $burnspeed = "";
126 my $runtest = "";
127 if ($speed) {
128 $burnspeed = " --speed=$speed";
129 } elsif ($test) {
130 $runtest = "--dummy";
132 my $command = "$writer --eject -vs -$mode --dev=$device $burnspeed $runtest $isoname";
133 system("$command > /dev/null");
134 unless ($? == "0") {
135 die "Can't burn disc!\n";
137 print("[OK!]\n");
140 sub oldisock {
141 print("Old iso file detected, delete it? [Y/n] "); my $reply=<STDIN>; chomp $reply;
142 if ($reply eq "n") {
143 print("Burn it? [Y/n] "); my $reply=<STDIN>; chomp $reply;
144 if ($reply eq "n") {
145 print("Stopped!\n");
146 exit 1;
147 } else {
148 &burniso;
149 exit 0;
151 } else {
152 print("Deleting old iso file...");
153 unlink($isoname);
154 print("[OK]\n");
155 &makeiso;
156 &burniso;
160 if ($isoname =~ m/^~/) {
161 $isoname =~ s/^~/$ENV{'HOME'}/;
164 if ($datadir =~ m/^~/) {
165 $datadir =~ s/^~/$ENV{'HOME'}/;
169 &warning;
170 &programcheck;
171 if ($burn) {
172 &burniso;
173 } elsif ($make) {
174 &makeiso;
175 &optcheck;
176 } else {
177 &optcheck;
178 &oldisock;
181 #TODO:
182 # * Delete of iso image after burning, nie, 3 sty 2010, 19:04:50 CET
183 # * CD-RW cleaning, nie, 3 sty 2010, 19:05:14 CET
184 # ** Add audiocd burning 2009-10-26 21:33+0100