slitaz-tools view boxes/burn-box @ rev 880

tazbox: huge update & bug fix
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue May 06 22:55:12 2014 +0300 (2014-05-06)
parents e232f0e1413a
children 5d80f6fdbdb7
line source
1 #!/bin/sh
2 #
3 # Burn-box a small front end to cdrkit powered by Yad/GTK. Keep the main
4 # window uncluttered and use a wizard to create audio/video/data CD/DVD.
5 # The main box lets users burn an ISO and audio files from a single directory.
6 #
7 # Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License
8 #
9 # Author: Christophe Lincoln <pankso@slitaz.org>
10 #
11 . /lib/libtaz.sh
12 export TEXTDOMAIN='slitaz-boxes' # i18n
14 # LibTaz parser and store options. Burn-box can be used with an ISO image
15 # or an audio directory in option: burn-box --iso=/path/to/image.iso
16 [ "$iso" ] || iso=" "
17 [ "$audio" ] || audio="$HOME"
19 # Internal variables
20 boxopts="--height=300 --width=620"
21 icon=media-optical-dvd-rw
22 options="-eject -multi"
23 speed=$(fgrep "drive speed" /proc/sys/dev/cdrom/info | cut -f3)
24 tmpdir=$(mktemp -d)
26 #
27 # Functions
28 #
30 # Help and usage
31 usage() {
32 newline; _ 'Burn-box a small front end to cdrkit powered by Yad/GTK.'
33 newline; boldify $(_ 'Usage:')
34 echo " $(basename $0) [$(_n 'command')|$(_n 'option')] [$(_n 'file')]"
36 newline; boldify $(_ 'Commands:')
37 optlist "\
38 wodim-help|-wh $(_n 'Show all Wodim options')
39 iso|-i $(_n 'Burn an ISO image')
40 audio|-a $(_n 'Create and burn an audio CD')
41 blank $(_n 'Erase a RW disk')"
43 newline; boldify $(_ 'Options:')
44 echo "\
45 --iso=$(_n '/path/to/image.iso')
46 --audio=$(_n '/path/to/directory')"
48 newline; boldify $(_ 'Examples:')
49 echo "\
50 $(basename $0) iso $(_n '/path/to/image.iso')
51 $(basename $0) --iso=$(_n '/path/to/image.iso')"
52 newline
53 }
55 # Ouput a command to a Yad/GTK box. Usage: cmd | out --title="Title" --tail
56 gtkout() {
57 yad --window-icon=$icon $boxopts \
58 --margins=4 --fontname=monospace \
59 --text-info "$@" --button="gtk-close:1"
60 }
62 # Decode audio files with: decode [file]
63 decode_audio() {
64 _ 'Decoding files from: $audio'
65 for f in "$audio"/*.*
66 do
67 debug "handling $f"
68 case "$f" in
69 *.wav)
70 cp -f "$f" $tmpdir ;;
71 *.mp3|*.MP3|*.ogg)
72 ext=${f##*.}
73 if [ ! -f "${f%.$ext}.wav" ]; then
74 decode "$f"
75 mv ${f%.$ext}.wav $tmpdir
76 fi ;;
77 esac
78 done
79 }
81 # Burn an ISO image.
82 burn_iso() {
83 if [ "${iso##*.}" != "iso" ]; then
84 _ 'Not an ISO image: "$iso"'; exit 1
85 fi
86 wodim -v speed=$speed $options "$iso"
87 }
89 # Burn some audio tracks from a directory.
90 burn_audio() {
91 decode_audio
92 echo "TODO: check_size"
93 du -sh $tmpdir
94 wodim -v speed=$speed $options -pad -dao -audio $tmpdir/*.wav
95 rm -rf $tmpdir
96 }
98 # Main GUI box function with pure Yad spec
99 burn_main() {
100 yad --title="$(_ 'Burn-box')" --window-icon=$icon $boxopts \
101 --image=$icon --image-on-top \
102 --text="<b>$(_n 'Burn ISO images and audio files [data in next releases]')</b>" \
103 --form \
104 --field="$(_n 'Drive speed:')" "$speed" \
105 --field="$(_n 'Wodim options:')" " $options" \
106 --field="$(_n 'ISO image:'):FL" "$iso" \
107 --field="$(_n 'Audio files:'):DIR" "$audio" \
108 --button="$(_n 'Wodim help'):$0 wodim-help" \
109 --button="$(_n 'Blank CD'):$0 blank" \
110 --button="$(_n 'Burn'):0" \
111 --button="gtk-close:1"
112 }
114 # Main function
115 burn() {
116 # Store box results
117 main=$(burn_main)
119 # Deal with --button values
120 case $? in
121 0) continue ;;
122 *) exit 0 ;;
123 esac
125 # Get values from $main
126 eval $(echo $main | awk -F'|' \
127 '{printf "speed=\"%s\" options=\"%s\" iso=\"%s\" audio=\"%s\"", $1, $2, $3, $4}')
128 speed=${speed%%,*} # first from comma separated list
130 # Handle ISO image
131 if [ "$iso" != "(null)" ]; then
132 burn_iso 2>&1 | gtkout --title="$(_n 'Burning ISO')" --tail
133 fi
135 # Handle Audio files.
136 if [ "$audio" != "$HOME" ]; then
137 burn_audio 2>&1 | gtkout --title="$(_n 'Burning Audio')" --tail
138 fi
139 }
141 #
142 # Commands
143 #
145 case "$1" in
146 -h|--help)
147 usage ;;
148 wodim-help|-wh)
149 wodim --help 2>&1 | gtkout --title="$(_n 'Wodim Help')" ;;
150 iso|-i)
151 # Let burn an ISO from cmdline: burn-box -i /path/to/image.iso
152 [ "$iso" == " " ] && iso="$2"
153 if [ ! -f "$iso" ]; then
154 _ 'Missing ISO image "$iso"'; exit 1
155 fi
156 burn_iso ;;
157 audio|-a)
158 # Let create an audio CD from cmdline: burn-box -a /path/to/audio
159 [ "$2" ] && audio="$2"
160 [ "$audio" == "$HOME" ] && unset audio
161 if [ ! -d "$audio" ]; then
162 _ 'Missing audio directory "$audio"'; exit 1
163 fi
164 burn_audio ;;
165 blank)
166 wodim -v -blank=fast 2>&1 | gtkout --title="$(_n 'Blank disk')" --tail ;;
167 ""|--*)
168 burn ;;
169 *)
170 usage ;;
171 esac
173 exit 0