~ubuntu-branches/ubuntu/karmic/tovid/karmic

« back to all changes in this revision

Viewing changes to src/makevcd

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2008-01-24 22:04:40 UTC
  • Revision ID: james.westby@ubuntu.com-20080124220440-x7cheljduf1rdgnq
Tags: upstream-0.31
ImportĀ upstreamĀ versionĀ 0.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
ME="[makevcd]:"
 
3
. tovid-init
 
4
 
 
5
# makevcd
 
6
# Part of the tovid suite
 
7
# =======================
 
8
# A bash script for creating a VCD cue/bin set and burning it
 
9
# to a recordable CD.
 
10
#
 
11
# Project homepage: http://www.tovid.org
 
12
#
 
13
#
 
14
# Copyright (C) 2005 tovid.org <http://www.tovid.org>
 
15
#
 
16
# This program is free software; you can redistribute it and/or
 
17
# modify it under the terms of the GNU General Public License
 
18
# as published by the Free Software Foundation; either
 
19
# version 2 of the License, or (at your option) any later
 
20
# version.
 
21
#
 
22
# This program is distributed in the hope that it will be useful,
 
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
25
# GNU General Public License for more details.
 
26
#
 
27
# You should have received a copy of the GNU General Public License
 
28
# along with this program; if not, write to the Free Software
 
29
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Or see:
 
30
#
 
31
#           http://www.gnu.org/licenses/gpl.txt
 
32
 
 
33
SCRIPTNAME=`cat << EOF
 
34
--------------------------------
 
35
makevcd
 
36
A script to create cue/bin files for a (S)VCD and burn them to a CD
 
37
Part of the tovid suite, version $TOVID_VERSION
 
38
$TOVID_HOME_PAGE
 
39
--------------------------------
 
40
EOF`
 
41
 
 
42
USAGE=`cat << EOF
 
43
Usage: makevcd [OPTIONS] {VCDIMAGER.xml}
 
44
 
 
45
Where OPTIONS may be any of the following:
 
46
 
 
47
  -overwrite         Overwrite existing cue/bin image
 
48
  -burn              (default only make image)
 
49
  -device DEVICE     (default /dev/cdrw)
 
50
  -speed NUM         (default 12)
 
51
 
 
52
And:
 
53
 
 
54
  VCDIMAGER.xml is the name of a file containing a VCDImager XML
 
55
      description (For XML format, see http://www.vcdimager.org/).
 
56
      If you use(d) 'makexml' to create the XML file, you can use
 
57
      that as input here.
 
58
 
 
59
See the makevcd manual page ('man makevcd') for additional documentation.
 
60
 
 
61
EOF`
 
62
 
 
63
SEPARATOR="=========================================="
 
64
 
 
65
# Print script name, usage notes, and optional error message, then exit.
 
66
# Args: $1 == text string containing error message
 
67
usage_error ()
 
68
{
 
69
  echo "$USAGE"
 
70
  echo $SEPARATOR
 
71
  echo "$@"
 
72
  exit 1
 
73
}
 
74
 
 
75
# Print out a runtime error specified as an argument, and exit
 
76
runtime_error ()
 
77
{
 
78
    killsubprocs
 
79
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
 
80
    echo "makevcd encountered an error during the VCD creation process:"
 
81
    echo $@
 
82
    echo "See if anything in the above output helps you diagnose the"
 
83
    echo "problem, and please file a bug report containing the above"
 
84
    echo "output with http://www.tovid.org. Sorry for the inconvenience!"
 
85
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
 
86
    exit 1
 
87
}
 
88
# Defaults
 
89
QUIET=false
 
90
IMAGE=:
 
91
CDRW_DEVICE="/dev/cdrw"
 
92
BURN_SPEED=12
 
93
OVERWRITE=false
 
94
BURN=false
 
95
 
 
96
# ==========================================================
 
97
# EXECUTION BEGINS HERE
 
98
echo $"$SCRIPTNAME"
 
99
 
 
100
assert_dep "$vcd" "You are missing dependencies required to image and burn (S)VCDs!"
 
101
 
 
102
while test x"${1:0:1}" = "x-"; do
 
103
    case "$1" in
 
104
      "-quiet" ) QUIET=: ;;
 
105
      "-overwrite" )
 
106
        OVERWRITE=:
 
107
        ;;
 
108
      "-burn" )
 
109
        BURN=:
 
110
        ;;
 
111
      "-device" )
 
112
        shift
 
113
        CDRW_DEVICE="$1"
 
114
        ;;
 
115
      "-speed" )
 
116
        shift
 
117
        BURN_SPEED=$1
 
118
        ;;
 
119
      * )
 
120
        usage_error "Error: Unrecognized command-line option $1"
 
121
        ;;
 
122
    esac
 
123
 
 
124
    # Get next argument
 
125
    shift
 
126
done
 
127
 
 
128
if test $# -ne 1; then
 
129
    usage_error "Please provide the name of a VCDimager XML file \
 
130
containing the (S)VCD description."
 
131
else
 
132
    # XML input is last argument
 
133
    VCDIMAGER_XML="$1"
 
134
fi
 
135
 
 
136
# Look for earlier attempts to image this VCD
 
137
for prev_try in "$VCDIMAGER_XML.cue" "$VCDIMAGER_XML.bin"; do
 
138
    if test -f "$prev_try"; then
 
139
        echo "Found a previous makevcd attempt: $prev_try!"
 
140
        if $OVERWRITE; then
 
141
            echo -n "Removing it...  "
 
142
            rm -fv "$prev_try"
 
143
        elif $BURN; then
 
144
            echo "Will use this for burning the disc."
 
145
            IMAGE=false
 
146
        else
 
147
            echo "Use '-overwrite' to override and re-image; or"
 
148
            echo "use '-burn' to write this existing image."
 
149
            echo "Exiting..."
 
150
            exit 1
 
151
        fi
 
152
    fi
 
153
done
 
154
 
 
155
 
 
156
# Create the cue/bin image
 
157
if $IMAGE; then
 
158
    # TODO: Warn if there isn't enough space to make cue/bin
 
159
    VCDIMAGER_CMD="vcdxbuild -c \"$VCDIMAGER_XML.cue\" -b \
 
160
        \"$VCDIMAGER_XML.bin\" \"$VCDIMAGER_XML\""
 
161
    echo $SEPARATOR
 
162
    echo "Creating cue/bin disc image with the following command:"
 
163
    echo $VCDIMAGER_CMD
 
164
    if eval $VCDIMAGER_CMD; then
 
165
        echo "Done."
 
166
        $QUIET || echo "Use 'makevcd -burn $VCDIMAGER_XML' to burn your VCD."
 
167
        $QUIET || echo "Thanks for using tovid!"
 
168
    else
 
169
        runtime_error "Imaging failed, please see vcdxbuild output above."
 
170
    fi
 
171
fi
 
172
 
 
173
# Burn the VCD
 
174
if $BURN; then
 
175
    # Sanity check: Make sure given device is valid (somehow)
 
176
    # before creating the cue/bin. Give option to proceed anyway?
 
177
    # (i.e., could there be any point to proceeding?)
 
178
    # Here's a simple way: just quit
 
179
    if test -b $CDRW_DEVICE; then :
 
180
       else
 
181
       echo "Couldn't find $CDRW_DEVICE! Stopping here."
 
182
       exit 1
 
183
    fi
 
184
 
 
185
    # Remind user to insert a CD
 
186
    $QUIET || echo "Please insert a blank CD-R(W) disc into your CD-recorder"
 
187
    $QUIET || echo "($CDRW_DEVICE) if you have not already done so."
 
188
 
 
189
    # check for cdrw and blank if so
 
190
    if cdrdao disk-info --device /dev/hdc --driver generic-mmc 2>&1 |
 
191
    grep -q CD-RW.*yes; then
 
192
    echo $SEPARATOR
 
193
    echo "Found rewritable CD - starting to blank in 10 seconds - press ctrl-c to quit"
 
194
    countdown 10
 
195
        cdrdao blank --driver generic-mmc  $CDRW_DEVICE
 
196
    fi 
 
197
    # Burn the disc
 
198
    CDRDAO_CMD="cdrdao write --device $CDRW_DEVICE --driver generic-mmc \
 
199
        --speed $BURN_SPEED \"$VCDIMAGER_XML.cue\""
 
200
    echo $SEPARATOR
 
201
    echo "Burning cue/bin image to $CDRW_DEVICE with the following command:"
 
202
    echo $CDRDAO_CMD
 
203
    if eval $CDRDAO_CMD; then
 
204
        if ! $QUIET; then
 
205
            echo "Done. You should now have a working VCD or SVCD. Please report"
 
206
            echo "any problems you might have to http://www.tovid.org."
 
207
            echo "Thanks for using tovid!"
 
208
        else
 
209
            echo "Done."
 
210
        fi
 
211
    else
 
212
        runtime_error "Could not burn the disc to $CDRW_DEVICE at speed $BURN_SPEED."
 
213
    fi
 
214
fi
 
215
 
 
216
exit 0