slitaz-tools view tinyutils/burnbox @ rev 516

tazx: incorrect tux; slitaz installer creates 1008 user
author Rohit Joshi <jozee@slitaz.org>
date Wed Nov 10 20:26:12 2010 -0500 (2010-11-10)
parents 764a5707fd96
children 6e8c38a0aee3
line source
1 #!/bin/sh
2 #
3 # Gtkdialog box to burn CD or DVD using Wodim with basic options. Burnbox
4 # can burn ISO images, blank rewritable CD or create audio CD with WAV.
5 #
6 # (c) - SliTaz GNU/Linux 2009 - GNU GPL v3
8 # Authors : Christophe Lincoln <pankso@slitaz.org>
9 # Rohit Joshi <jozee@slitaz.org>
10 #
11 VERSION=20100315
12 TMPDIR="/tmp/burn-cd"
14 chk_install()
15 {
16 for pkg in $@
17 do
18 if [ ! -d /var/lib/tazpkg/installed/${pkg} ]; then
19 UNINSTALLED="$UNINSTALLED $pkg"
20 fi
21 done
22 if [ ! "$UNINSTALLED" = "" ] ; then
23 xterm -geometry 80x16 -title "INSTALL PACKAGE" \
24 -e "echo -n \"This option depends on $UNINSTALLED. Please install and try again..\"; sleep 4;"
25 fi
26 }
28 # Auto Install DEPENDS and/or SUGGESTED
29 install()
30 {
31 #echo "pkgs to install: $1"
32 for pkg in $1 ; do
33 # Avoid reinstall
34 if [ ! -d /var/lib/tazpkg/installed/"$pkg" ]; then
35 xterm -geometry 80x16 -title "INSTALL PACKAGE" \
36 -e " echo \"This option depends on $pkg. Installing $pkg as root: \" ; subox tazpkg get-install $pkg --forced; sleep 2;
37 echo -e \"----\nPress ENTER to close and PROCEED with decoding...\"; read i; exit 0; "
38 fi
39 done
41 }
44 # Check read write permission for device.
45 chk_rw_permissions()
46 {
47 xterm -geometry 80x16 -title "Check Permission" \
48 -e '
49 if [ ! -r "$DEVICE" -o ! -w "$DEVICE" ]; then
50 echo "You dont have read write permission for $DEVICE; "
51 echo "Add yourself to group cdrom: addgroup tux cdrom"
52 else
53 echo "You have read write permission for $DEVICE. You can proceed to burn."
54 fi
55 sleep 3;
56 '
57 }
59 # Display audio cd size.
60 audio_cd_stats()
61 {
62 AUDIO_CD_SIZE=`du -m $TMPDIR | awk '{print $1}'`
63 TRACK_NB=`ls -1 $TMPDIR | wc -l`
64 echo -n "Total $TRACK_NB tracks: $AUDIO_CD_SIZE Mb"
65 }
68 decode_ogg()
69 {
70 if ls $TMPDIR | grep -q .ogg; then
71 cd $TMPDIR
72 xterm -geometry 80x16 -title "Oggdec" \
73 -e 'for i in *.ogg; do oggdec "$i" && rm "$i"; done; sleep 2'
74 fi
75 }
77 decode_mp3()
78 {
80 if ls $TMPDIR | grep -q .mp3; then
81 cd $TMPDIR
82 install "mpg123"
84 xterm -geometry 80x16 -title "mpg123" \
85 -e 'for file in *.mp3; do
86 mpg123 --rate 44100 --stereo --buffer 3072 --resync -w `basename "$file" .mp3`.wav "$file" && rm -f "$file";
87 done; sleep 2'
88 fi
89 }
91 decode_video()
92 {
93 # convert videos into a VCD/SVCD/DVD compatible mpg video format
94 if ls $TMPDIR | grep -q ".avi\|.mov\|.wmv\|.flv" ; then
95 cd $TMPDIR
96 install "ffmpeg"
98 xterm -geometry 80x16 -title "ffmpeg" \
99 -e ' echo -n "Select target type (pal-vcd ntsc-vcd pal-svcd ntsc-svcd pal-dvd ntsc-dvd) "; read TARGET_OPTIONS
100 for file in *.avi *.wmv *.mov *.flv; do
101 ext=`echo "${file##*.}"`
102 output_file=`basename "$file" .$ext`.mpg
103 ffmpeg -i "$file" -target "$TARGET_OPTIONS" "$output_file" && rm "$file";
104 done; sleep 2;
105 '
106 fi
109 }
111 # convert spaces in filename with _ and remove special characters "()'&" {}\! and translate uppercase to lowercase
112 fix_filename()
113 {
114 ls /tmp/burn-cd/* | while read file
115 do
116 mv "$file" `echo $file | tr ' ' '_' | tr -d '[{}(),\!&]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g' `
117 done
119 }
121 # We must think about " space " between directory/track and
122 # filter directory copy to avoid copying other files than audio.
123 # Only burning non-compressed wav format is supported directly.
125 copy_audio_file()
126 {
127 if ls "$NEW_TRACK" | grep -q .ogg; then
128 cp "${NEW_TRACK%.ogg}.ogg" $TMPDIR
129 fix_filename
130 decode_ogg
131 elif ls "$NEW_TRACK" | grep -q ".[m\|M][p\|P]3"; then
132 # cp "${NEW_TRACK%.mp3}.mp3" $TMPDIR
133 cp "$NEW_TRACK" "$TMPDIR"
134 fix_filename
135 decode_mp3
136 else
137 cp "${NEW_TRACK%.wav}.wav" $TMPDIR
138 fi
139 }
142 copy_audio_dir()
143 {
145 for i in .wav .ogg .mp3
146 do
147 cp "$NEW_DIR"/*$i $TMPDIR 2>/dev/null
148 done
149 fix_filename
150 decode_ogg
151 decode_mp3
152 }
154 # Only burning mpg video format is supported directly. MPEG-1 video for vcd and MPEG-2 for svcd and dvd
155 copy_video_file()
156 {
157 if ls "$NEW_TRACK" | grep -q ".mpg\|.mpeg"; then
158 cp "${NEW_TRACK%.mp*}.mpg" $TMPDIR
159 elif ls "$NEW_TRACK" | grep -q ".avi\|.mov\|.wmv\|.flv"; then
160 ext=`echo "${NEW_TRACK##*.}"`
161 cp "${NEW_TRACK%.$ext}.$ext" $TMPDIR
162 fix_filename
163 if "$CHECKBOX_DECODE" ; then decode_video ; fi
164 else
165 echo "mpg format supported"
166 fi
167 }
169 copy_video_dir()
170 {
171 for i in .mpg .avi .mov .wmv .mpeg .flv
172 do
173 cp "$NEW_DIR"/*$i $TMPDIR 2>/dev/null
174 done
175 fix_filename
176 if "$CHECKBOX_DECODE" ; then decode_video ; fi
177 }
179 copy_file()
180 {
181 case "$BURN_MODE" in
182 audio-cd)
183 copy_audio_file ;;
184 vcd|svcd|video-dvd)
185 copy_video_file ;;
186 *)
187 cp "$NEW_TRACK" $TMPDIR ; fix_filename ;;
188 esac
190 }
192 copy_dir()
193 {
194 case "$BURN_MODE" in
195 audio-cd)
196 copy_audio_dir ;;
197 vcd|svcd|video-dvd)
198 copy_video_dir ;;
199 *)
200 cp "$NEW_DIR" $TMPDIR 2>/dev/null
201 fix_filename ;;
202 esac
203 }
204 # =====ISO=====
205 burn_iso()
206 {
207 xterm -geometry 80x16 -title "Wodim" \
208 -e "wodim -v speed=$SPEED dev=$DEVICE $OPTIONS '$ISO_IMAGE'; sleep 4
209 "
210 }
211 # =====AUDIO=====
212 # Use -pad to avoid file size error.
213 burn_audio()
214 {
216 install "cdrkit"
217 xterm -geometry 80x16 -title "Wodim:AUDIO" \
218 -e " echo \"BURN TYPE SELECTED = $BURN_MODE \"; sleep 1;
219 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao -audio $TMPDIR/*.wav; sleep 4
221 "
222 }
223 # =====DATA=====
224 burn_cddata()
225 {
227 install "cdrkit"
229 xterm -geometry 80x16 -title "Wodim:CD DATA" \
230 -e " echo \"BURN TYPE SELECTED = $BURN_MODE \"; sleep 1;
231 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao -data $TMPDIR/*; sleep 4
233 "
235 }
237 burn_dvddata()
238 {
239 # For multisession support, remove --dvd-compat option
240 install "dvd+rw-tools"
242 xterm -geometry 80x16 -title "growisofs:DVD DATA" \
243 -e " echo \"BURN TYPE SELECTED = $BURN_MODE \"; sleep 1;
244 # no iso-file available
245 growisofs -dvd-compat -speed=$SPEED -pad -J -r -f -Z $DEVICE $TMPDIR/*; sleep 4
246 "
247 }
249 # ====VIDEO=====
250 burn_dvdvideo()
251 {
253 install "dvd+rw-tools"
255 # current assumption: compatible dvd-video format
256 xterm -geometry 80x16 -title "growisofs:DVD VIDEO" \
257 -e " echo \"BURN TYPE SELECTED = $BURN_MODE\"; sleep 1;
258 growisofs -dvd-video -udf -pad -J -r -f -Z $DEVICE -speed=$SPEED $TMPDIR/*; sleep 2
259 "
261 }
263 burn_vcd()
264 {
266 install "vcdimager"
268 mkdir -p $TMPDIR/vcd
269 xterm -geometry 80x16 -title "vcdimager:VCD" \
270 -e " echo \"BURN TYPE SELECTED = $BURN_MODE $UNINSTALLED \"; sleep 1;
271 vcdimager -t vcd2 -l VCD -c $TMPDIR/vcd/vcd.cue -b $TMPDIR/vcd/vcd.bin $TMPDIR/*.mpg; sleep 2;
272 # cdrdao write --device $DEVICE $TMPDIR/vcd/vcd.cue; sleep 2
273 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao cuefile=$TMPDIR/vcd/vcd.cue ; sleep 2
274 "
277 }
279 burn_svcd()
280 {
282 install "vcdimager"
284 mkdir -p $TMPDIR/svcd
285 xterm -geometry 80x16 -title "vcdimager:SVCD" \
286 -e " echo \"BURN TYPE SELECTED = $BURN_MODE\"
287 vcdimager -t svcd -l SVCD -c $TMPDIR/svcd/svcd.cue -b $TMPDIR/svcd/svcd.bin $TMPDIR/*.mpg; sleep 2;
288 # cdrdao write --device $DEVICE $TMPDIR/svcd/svcd.cue; sleep 2;
289 wodim -v speed=$SPEED dev=$DEVICE $OPTIONS -pad -dao cuefile=$TMPDIR/svcd/svcd.cue ; sleep 2
290 "
292 }
294 # =====CLONE=====
296 rip_disc()
297 {
298 SUGGESTED="cdrkit-isoinfo"
299 if ! "$CHECKBOX_FOLDER" ; then SAVE_DISC="/tmp/burn-cd" ; fi
300 if [ -d /var/lib/tazpkg/installed/${SUGGESTED} ]; then
301 xterm -geometry 80x16 -title "dd" \
302 -e ' echo "RIPPING DISC $DEVICE AT $SAVE_DISC..."
303 COUNT=`isoinfo -d -i $DEVICE | grep "^Volume size is:" | cut -d " " -f 4`
304 BLOCK=`isoinfo -d -i $DEVICE | grep "^Logical block size is:" | cut -d " " -f 5`
305 dd if=$DEVICE of=$SAVE_DISC/image.iso bs=$BLOCK count=$COUNT; sleep 4
306 sleep 2;
307 # eject ;
308 '
309 else
310 xterm -geometry 80x16 -title "dd" \
311 -e ' echo "Though you dont have the cdrkit-isoinfo package installed, \
312 you can still rip but it may be slower."
313 echo -n "Would you like to continue (y/N)? : "; read ans
314 if [ "$ans" = "y" ]; then
315 echo "RIPPING DISC $DEVICE AT $SAVE_DISC...."
316 dd if=$DEVICE of=$SAVE_DISC/image.iso;
317 sleep 2;
318 #eject ;
319 fi
320 '
321 fi
322 if ! "$CHECKBOX_FOLDER" ; then
323 ISO_IMAGE="/tmp/burn-cd/image.iso"
324 xterm -geometry 80x16 -title "dd" \
325 -e ' echo -e " ---Please insert EMPTY DISC at $DEVICE ---\n ---press ENTER to continue..." && read close;'
326 burn_iso
327 fi
328 }
330 blank_dvd()
331 {
332 xterm -geometry 80x16 -title "growisofs:DVD ERASE" \
333 -e "growisofs -Z $DEVICE=/dev/zero"
334 }
336 burn_disc()
337 {
338 case "$BURN_MODE" in
339 audio*)
340 burn_audio ;;
341 data-cd*)
342 burn_cddata ;;
343 data-dvd*)
344 burn_dvddata;;
345 video*)
346 burn_dvdvideo;;
347 vcd*)
348 burn_vcd;;
349 svcd*)
350 burn_svcd;;
351 esac
353 }
355 track_list()
356 {
357 for file in `ls $TMPDIR` ; do
358 track_size=`du -m $TMPDIR/$file | awk '{print $1}'`
359 echo "$file | $track_size"
360 done
361 }
363 export BIN=$0
364 # Main GTK interface
365 MAIN_DIALOG='
366 <window title="SliTaz - Burnbox" icon-name="drive-optical">
367 <vbox>
369 <notebook labels=" Burn CD/DVD (Audio,Video,Data)| Backup Disc| Burn ISO | Help/Settings">
371 <vbox>
372 <tree icon_name="audio-x-generic">
373 <width>500</width><height>200</height>
374 <variable>TRACKS_LIST</variable>
375 <label>Track name (Double-click to remove a track) | Track Size (Mb)</label>
376 <input>$BIN track_list</input>
377 <action>rm "/tmp/burn-cd/$TRACKS_LIST"</action>
378 <action>refresh:TRACKS_LIST</action>
379 <action>refresh:TRACKS_SIZE</action>
380 </tree>'
382 # Select burn audio-cd, data-cd, dvd-video or vcd/svcd
383 MAIN_DIALOG=${MAIN_DIALOG}'
384 <frame>
385 <hbox>
386 <text>
387 <label> Select Burn type: </label>
388 </text>
389 <combobox>'
390 tmp2="${MAIN_DIALOG}"
391 for i in audio-cd data-cd data-dvd video-dvd vcd svcd; do
392 [ "$i" = "$BURN_MODE" ] || tmp2="$tmp2<item>$i</item>"
393 done
394 tmp3='
395 <variable>BURN_MODE</variable>
396 </combobox>
397 <checkbox>
398 <label> Enable decoding video</label>
399 <variable>CHECKBOX_DECODE</variable>
400 <default>true</default>
401 </checkbox>
402 </hbox>
403 '
404 MAIN_DIALOG="$tmp2$tmp3"
405 # Select, add and burn audio buttons.
406 MAIN_DIALOG=${MAIN_DIALOG}"
407 <hbox>
408 <text>
409 <label> File: </label>
410 </text>
411 <entry accept=\"filename\">
412 <label>Select an Audio/Video/data track</label>
413 <variable>NEW_TRACK</variable>
414 </entry>
415 <button>
416 <label>Browse</label>
417 <input file stock=\"gtk-open\"></input>
418 <action type=\"fileselect\">NEW_TRACK</action>
419 </button>
420 <button>
421 <label>Add</label>
422 <input file stock=\"gtk-add\"></input>
423 <action>$0 copy_file</action>
424 <action>refresh:TRACKS_LIST</action>
425 <action>refresh:TRACKS_SIZE</action>
426 </button>
427 </hbox>
428 <hbox>
429 <text>
430 <label> Folder:</label>
431 </text>
432 <entry accept=\"directory\">
433 <label>Select an Audio/Video/Data track</label>
434 <variable>NEW_DIR</variable>
435 </entry>
436 <button>
437 <label>Browse</label>
438 <input file stock=\"gtk-open\"></input>
439 <action type=\"fileselect\">NEW_DIR</action>
440 </button>
441 <button>
442 <label>Add</label>
443 <input file stock=\"gtk-add\"></input>
444 <action>$0 copy_dir</action>
445 <action>refresh:TRACKS_LIST</action>
447 <action>refresh:TRACKS_SIZE</action>
448 </button>
449 </hbox>"
451 MAIN_DIALOG=${MAIN_DIALOG}"
452 <hbox>
453 <text>
454 <variable>TRACKS_SIZE</variable>
455 <input>$0 audio_cd_stats</input>
456 </text>
457 <button>
458 <label>Clean</label>
459 <input file stock=\"gtk-clear\"></input>
460 <action>rm -rf $TMPDIR/*</action>
461 <action>refresh:TRACKS_LIST</action>
462 <action>refresh:TRACKS_SIZE</action>
463 <action>clear:NEW_TRACK</action>
464 <action>clear:NEW_DIR</action>
465 </button>
466 <button>
467 <label>Burn disc</label>
468 <input file icon=\"forward\"></input>
469 <action>$0 burn_disc</action>
470 </button>
471 </hbox>
472 </frame>
473 </vbox> "
475 # Backup CD
476 MAIN_DIALOG=${MAIN_DIALOG}'
477 <vbox>
479 <text use-markup="true">
480 <label>
481 "
482 <b>Choose either the Data or the Audio CD backup frame </b>
483 "
484 </label>
485 </text>
487 <frame Data CD/DVD backup >
488 <text>
489 <label>
490 " "
491 </label>
492 </text>
493 <checkbox>
494 <label>Save backup on Hard Disk Folder (Unselect to backup on CD disc)</label>
495 <variable>CHECKBOX_FOLDER</variable>
496 <default>true</default>
497 <action>if true enable:SAVE_DISC</action>
498 <action>if true enable:OPENBUTTON</action>
499 <action>if false disable:SAVE_DISC</action>
500 <action>if false disable:OPENBUTTON</action>
501 </checkbox>
502 <hbox>
503 <text use-markup="true">
504 <label>" Backup Folder Path:"</label>
505 </text>
506 <entry accept="directory">
507 <label>Select a folder to save cloned disc to</label>
508 <variable>SAVE_DISC</variable>
509 </entry>
510 <button>
511 <label>Browse</label>
512 <input file stock="gtk-open"></input>
513 <variable>OPENBUTTON</variable>
514 <action type="fileselect">SAVE_DISC</action>
515 </button>
516 </hbox>
517 '
518 # Burn backup button.
519 MAIN_DIALOG=${MAIN_DIALOG}"
520 <hbox>
521 <text>
522 <label>\"Proceed to backup your data CD: \" </label>
523 </text>
524 <button>
525 <label>Backup DataCD</label>
526 <variable>DATA_RIP</variable>
527 <input file icon=\"forward\"></input>
528 <action>$0 rip_disc</action>
529 </button>
530 </hbox>
531 </frame>"
532 MAIN_DIALOG=${MAIN_DIALOG}'
533 <frame Audio CD backup>
534 <text>
535 <label>
536 " "
537 </label>
538 </text>
539 <hbox>
540 <text>
541 <label> "Proceed to clone your audio CD:"</label>
542 </text>
543 <button>
544 <label> Backup AudioCD</label>
545 <variable>AUDIO_RIP</variable>
546 <input file icon="forward"></input>
547 <action>asunder</action>
548 </button>
549 </hbox>
550 </frame>
552 </vbox>'
554 MAIN_DIALOG=${MAIN_DIALOG}'
555 <vbox>
556 <text use-markup="true">
557 <label>
558 "
559 "
560 </label>
561 </text>
562 <frame Select ISO and burn>
563 <hbox>
564 <text>
565 <label>
566 " "
567 </label>
568 </text>
569 <text use-markup="true">
570 <label>"<b>ISO path:</b>"</label>
571 </text>
572 <entry>
573 <variable>ISO_IMAGE</variable>
574 </entry>
575 <button>
576 <label>Browse</label>
577 <input file stock="gtk-open"></input>
578 <action type="fileselect">ISO_IMAGE</action>
579 </button>
580 </hbox>
581 '
582 # Burn iso button.
583 MAIN_DIALOG=${MAIN_DIALOG}"
584 <hbox>
585 <button>
586 <label>Burn ISO</label>
587 <input file icon=\"forward\"></input>
588 <action>$0 burn_iso</action>
589 </button>
590 </hbox>
591 </frame>
592 </vbox>"
596 #
597 #
598 # tmp3=
599 MAIN_DIALOG=${MAIN_DIALOG}'
600 <vbox>
601 <frame Information>
603 <text width_request="250" use-markup="true">
604 <label>
605 "Burnbox burns ISOs, backs up CD/DVDs, burns data CD/DVDs, audio CDs and video CDs (VCD/SVCD)
606 "
607 </label>
608 </text>
609 <hbox>
610 <text use-markup="true">
611 <label> "<b> Please consult HELP file if needed: </b>" </label>
612 </text>
613 <button>
614 <input file icon="help"></input>
615 <action> browser /usr/share/doc/slitaz-tools/burnbox.html </action>
616 </button>
617 </hbox>
619 </frame>
620 <frame Settings>
621 <text>
622 <label>
623 "Before burning, please verify/change device writer settings below if needed.
624 "
625 </label>
626 </text>
628 <hbox>
629 <text use-markup="true">
630 <label>"<b>Device: </b>"</label>
631 </text>
632 <entry>
633 <default>/dev/cdrom</default>
634 <variable>DEVICE</variable>
635 </entry>
636 </hbox>
637 <hbox>
638 <text use-markup="true">
639 <label>"<b>Speed: </b>"</label>
640 </text>
641 <entry>
642 <input>cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3</input>
643 <variable>SPEED</variable>
644 </entry>
645 </hbox>
646 <hbox>
647 <text use-markup="true">
648 <label>"<b>Options: </b>"</label>
649 </text>
650 <entry>
651 <default>-eject -multi</default>
652 <variable>OPTIONS</variable>
653 </entry>
654 <button>
655 <input file icon="help"></input>
656 <action>xterm -sb -geometry 95x25 -title "wodim help" -e "wodim --help ; echo -e \"----\nENTER to continue...\" && read close"</action>
657 </button>
658 </hbox> '
660 MAIN_DIALOG=${MAIN_DIALOG}'
661 </frame>
662 <frame Blank CD/DVD-RW>
663 <hbox>
664 <text use-markup="true">
665 <label>"<b>Option: </b>"</label>
666 </text>
667 <entry>
668 <variable>BLANK_OPTS</variable>
669 <default>fast</default>
670 </entry>
671 <button>
672 <input file icon="help"></input>
673 <action>xterm -geometry 80x16 -title "wodim blank=help" -e "wodim blank=help ; echo -e \"----\nENTER to continue...\" && read close"</action>
674 </button>
675 <button>
676 <label>Blank disc</label>
677 <input file icon="forward"></input>
678 <action>xterm -title "Wodim" -e "wodim -v -blank=$BLANK_OPTS dev=$DEVICE; sleep 2"</action>
679 </button>
680 </hbox>
681 </frame>
682 </vbox>'
683 export MAIN_DIALOG=${MAIN_DIALOG}'
685 </notebook>'
686 MAIN_DIALOG=${MAIN_DIALOG}"<hbox>
687 <button>
688 <input file icon=\"dialog-information\"></input>
689 <label> Check Permissions for Device</label>
690 <action>$0 chk_rw_permissions</action>
691 </button>
692 "
693 MAIN_DIALOG=${MAIN_DIALOG}'
694 <button>
695 <label>Exit</label>
696 <input file icon="exit"></input>
697 <action type="exit">Exit</action>
698 </button>
699 </hbox>
701 </vbox>
702 </window>
703 '
705 # Script can be called with an arg to exec a function.
706 if [ -n "$1" ]; then
707 $1
708 else
709 mkdir -p $TMPDIR
710 gtkdialog --center --program=MAIN_DIALOG >/dev/null
711 rm -rf $TMPDIR
712 fi
714 exit 0