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

tazinst: add TGT_HOSTNAME to /etc/hosts
author Richard Dunbar <mojo@slitaz.org>
date Fri Jan 11 15:21:41 2013 +0000 (2013-01-11)
parents 6e62d41a70d2
children 463e0588d40d
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 SliTaz GNU/Linux - BSD License
8 #
9 # Author: Christophe Lincoln <pankso@slitaz.org>
10 #
11 . /lib/libtaz.sh
13 # LibTaz parser and store options. Burn-box can be used with an ISO image
14 # or an audio directory in option: burn-box --iso=/path/to/image.iso
15 [ "$iso" ] || iso=" "
16 [ "$audio" ] || audio="$HOME"
18 # Internal variables (we need a space before options).
19 boxopts="--height=300 --width=520 --window-icon=drive-cdrom"
20 options=" -eject -multi"
21 speed=$(fgrep "drive speed" /proc/sys/dev/cdrom/info | cut -f 3)
22 tmpdir=/tmp/$(basename $0)
24 # Internationalization
25 . /usr/bin/gettext.sh
26 TEXTDOMAIN='slitaz-boxes'
27 export TEXTDOMAIN
29 #
30 # Functions
31 #
33 # Help and usage
34 usage() {
35 cat << EOT
37 $(gettext "Usage:") $(basename $0) [command|option] [file]
39 $(gettext "Commands:")
40 wodim-help|-wh $(gettext "Show all Wodim options")
41 iso|-i $(gettext "Burn an ISO image")
42 audio|-a $(gettext "Create and burn an audio CD")
44 $(gettext "Options:")
45 --iso=/path/to/image.iso
46 --audio=/path/to/directory
48 $(gettext "Examples:")
49 $(basename $0) iso /path/to/image.iso
50 $(basename $0) --iso=/path/to/image.iso
52 EOT
53 }
55 # Ouput a command to a Yad/GTK box. Usage: cmd | out --title="Title" --tail
56 gtkout() {
57 yad --text-info $boxopts "$@" --margins=4 --button="gtk-close":1
58 }
60 # Decode audio files with: decode [file]
61 decode_audio() {
62 gettext "Decoding files from:"; echo " $audio"
63 rm -rf $tmpdir && mkdir -p $tmpdir
64 for f in "$audio"/*.*
65 do
66 [ "$debug" ] && echo "DEBUG: handling $f"
67 case "$f" in
68 *.wav)
69 cp -f "$f" $tmpdir ;;
70 *.mp3|*.MP3|*.ogg)
71 ext=${f##*.}
72 if [ ! -f "${f%.$ext}.wav" ]; then
73 decode "$f"
74 mv ${f%.$ext}.wav $tmpdir
75 fi ;;
76 esac
77 done
78 }
80 # Burn an ISO image.
81 burn_iso() {
82 [ "${iso##*.}" != "iso" ] && \
83 (gettext "Not an ISO image:"; echo " $iso") && exit 1
84 wodim -v speed=$speed $options "$iso"
85 }
87 # Burn some audio tracks from a directory.
88 burn_audio() {
89 decode_audio
90 echo "TODO: check_size"
91 du -sh $tmpdir
92 wodim -v speed=$speed $options -pad -dao -audio $tmpdir/*.wav
93 rm -rf $tmpdir
94 }
96 # Main GUI box function with pure Yad spec
97 burn_main() {
98 text="$(gettext "Burn ISO images and audio files [data in next releases]")"
99 yad --form $boxopts --title="Burn-box" \
100 --image=application-x-cd-image --image-on-top \
101 --text="<b>$text</b>" \
102 --field="$(gettext "Drive speed:")":NUM \
103 --field="$(gettext "Wodim options:")" \
104 --field="$(gettext "ISO image:")":FL \
105 --field="$(gettext "Audio files:")":DIR \
106 --button="$(gettext "Wodim help")":"$0 wodim-help" \
107 --button="$(gettext "Blank CD")":"$0 blank" \
108 --button="$(gettext "Burn")":0 \
109 --button="gtk-close":1 \
110 "$speed" "$options" "$iso" "$audio"
111 }
113 # Main function
114 burn() {
115 # Store box results
116 main=$(burn_main)
118 # Deal with --button values
119 case $? in
120 0) continue ;;
121 *) exit 0 ;;
122 esac
124 # Get value from $main
125 speed=$(echo $main | cut -d "|" -f 1 | cut -d "," -f 1)
126 options=$(echo $main | cut -d "|" -f 2)
127 iso=$(echo $main | cut -d "|" -f 3)
128 audio=$(echo $main | cut -d "|" -f 4)
130 # Handle ISO image
131 if [ "$iso" != "(null)" ]; then
132 burn_iso 2>&1 | gtkout --title="Burning ISO" --tail
133 fi
135 # Handle Audio files.
136 if [ "$audio" != "$HOME" ]; then
137 burn_audio 2>&1 | gtkout --title="Burning Audio" --tail
138 fi
139 }
141 #
142 # Commands
143 #
145 case "$1" in
146 wodim-help|-wh)
147 wodim --help 2>&1 | gtkout --title="Wodim Help" ;;
148 iso|-i)
149 # Let burn an ISO from cmdline: burn-box -i /path/to/image.iso
150 [ "$iso" == " " ] && iso="$2"
151 if [ ! -f "$iso" ]; then
152 gettext "Missing ISO image"; echo " $iso" && exit 1
153 fi
154 burn_iso ;;
155 audio|-a)
156 # Let create an audio CD from cmdline: burn-box -a /path/to/audio
157 [ "$2" ] && audio="$2"
158 [ "$audio" == "$HOME" ] && unset audio
159 if [ ! -d "$audio" ]; then
160 gettext "Missing audio directory"; echo " $audio" && exit 1
161 fi
162 burn_audio ;;
163 blank)
164 wodim -v -blank=all 2>&1 | gtkout --title="Wodim Blank" --tail ;;
165 ""|--*)
166 burn ;;
167 *)
168 usage ;;
169 esac
171 exit 0