1 | #!/bin/sh
|
---|
2 |
|
---|
3 | # Create EPub file from RFC2629-formatted source
|
---|
4 | #
|
---|
5 | # Copyright (c) 2010, Julian Reschke (julian.reschke@greenbytes.de)
|
---|
6 | # All rights reserved.
|
---|
7 | #
|
---|
8 | # Redistribution and use in source and binary forms, with or without
|
---|
9 | # modification, are permitted provided that the following conditions are met:
|
---|
10 | #
|
---|
11 | # * Redistributions of source code must retain the above copyright notice,
|
---|
12 | # this list of conditions and the following disclaimer.
|
---|
13 | # * Redistributions in binary form must reproduce the above copyright notice,
|
---|
14 | # this list of conditions and the following disclaimer in the documentation
|
---|
15 | # and/or other materials provided with the distribution.
|
---|
16 | # * Neither the name of Julian Reschke nor the names of its contributors
|
---|
17 | # may be used to endorse or promote products derived from this software
|
---|
18 | # without specific prior written permission.
|
---|
19 | #
|
---|
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
---|
24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
---|
25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
---|
26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
30 | # POSSIBILITY OF SUCH DAMAGE.
|
---|
31 |
|
---|
32 | if [ $# != 1 ] ; then
|
---|
33 | echo Usage: $0 xmlsourcefile >&2
|
---|
34 | exit 2
|
---|
35 | fi
|
---|
36 |
|
---|
37 | if [ ! -r $1 ] ; then
|
---|
38 | echo $0: can\'t read $1
|
---|
39 | exit 1
|
---|
40 | fi
|
---|
41 |
|
---|
42 | base=$(basename $1 .xml)
|
---|
43 | epub=$base.epub
|
---|
44 | tmpfolder=mkepubtmp-$$
|
---|
45 |
|
---|
46 | xslt() {
|
---|
47 | if type saxon >/dev/null 2> /dev/null; then
|
---|
48 | saxon $1 $2 basename=$base
|
---|
49 | elif type xsltproc >/dev/null 2> /dev/null; then
|
---|
50 | xsltproc --stringparam basename $base $2 $1
|
---|
51 | else
|
---|
52 | echo $0: needs either "saxon" or "xsltproc" >&2
|
---|
53 | fi
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | (
|
---|
58 | mkdir $tmpfolder
|
---|
59 | cd $tmpfolder
|
---|
60 | echo "application/epub+zip\c" > mimetype
|
---|
61 | mkdir META-INF
|
---|
62 | echo '<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
---|
63 | <rootfiles>
|
---|
64 | <rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
|
---|
65 | </rootfiles>
|
---|
66 | </container>
|
---|
67 | ' > META-INF/container.xml
|
---|
68 | mkdir OEBPS
|
---|
69 | xslt ../$1 ../rfc2629toOpf.xslt > OEBPS/content.opf
|
---|
70 | xslt ../$1 ../rfc2629toNcx.xslt > OEBPS/toc.ncx
|
---|
71 | xslt ../$1 ../rfc2629toEPXHTML.xslt > OEBPS/$base.xhtml
|
---|
72 | xslt ../$1 ../extractInlineCss.xslt > OEBPS/rfc2629xslt.css
|
---|
73 | xslt ../$1 ../extractExtRefs.xslt | while read filename
|
---|
74 | do
|
---|
75 | cp ../$filename OEBPS/
|
---|
76 | done
|
---|
77 |
|
---|
78 | [ -r ../$epub ] && rm ../$epub
|
---|
79 | zip ../$epub -X0 mimetype
|
---|
80 | zip ../$epub -Xr META-INF OEBPS
|
---|
81 | )
|
---|
82 | rm -rfv $tmpfolder
|
---|