0

Using this a2x command creates a valid .epub file (book.epub):

$ a2x -v -k -f epub -d book book.asc
a2x: archiving: mimetype
a2x: archiving: META-INF/container.xml
a2x: archiving: OEBPS/ch01.html
a2x: archiving: OEBPS/ch02.html
a2x: archiving: OEBPS/content.opf
a2x: archiving: OEBPS/docbook-xsl.css
a2x: archiving: OEBPS/index.html
a2x: archiving: OEBPS/pr01.html
a2x: archiving: OEBPS/toc.ncx

However, if I try to manually create an .epub archive using the artifacts (contained in book.epub.d) of the a2x command and zip command, the resulting .epub file is not valid:

$ zip -vr book.epub book.epub.d/ -x "*.DS_Store"
  adding: book.epub.d/  (in=0) (out=0) (stored 0%)
  adding: book.epub.d/META-INF/ (in=0) (out=0) (stored 0%)
  adding: book.epub.d/META-INF/container.xml    (in=255) (out=175) (deflated 31%)
  adding: book.epub.d/mimetype  (in=20) (out=20) (stored 0%)
  adding: book.epub.d/OEBPS/    (in=0) (out=0) (stored 0%)
  adding: book.epub.d/OEBPS/ch01.html   (in=1161) (out=686) (deflated 41%)
  adding: book.epub.d/OEBPS/ch02.html   (in=679) (out=414) (deflated 39%)
  adding: book.epub.d/OEBPS/content.opf (in=1288) (out=476) (deflated 63%)
  adding: book.epub.d/OEBPS/docbook-xsl.css (in=5738) (out=1518) (deflated 74%)
  adding: book.epub.d/OEBPS/index.html  (in=1156) (out=590) (deflated 49%)
  adding: book.epub.d/OEBPS/pr01.html   (in=770) (out=485) (deflated 37%)
  adding: book.epub.d/OEBPS/toc.ncx (in=772) (out=325) (deflated 58%)

I suspect this is because the archive's files include book.epub.d in the paths. Is there a way to exclude this?

craig
  • 25,664
  • 27
  • 119
  • 205

2 Answers2

2

I do a succession of zip commands to zip an EPUB:

cd /home/bookdirectory (where mimetype, OEBPS and META-INF are subdirectories)
zip -X book.epub mimetype
zip -r book.epub META-INF
zip -r book.epub OEBPS

I had trouble for the longest time, until I figured that the -X was essential on the mimetype zip.

I notice your zip exclude is a lowercase x ..maybe switch that to upper-case?

Paulb
  • 1,471
  • 2
  • 16
  • 39
  • `-x` excludes specified files; `-X` excludes 'extra file attributes'. The `-X` flag on your first line works, as `.DS_Store` is only present in the root (`book.epub.d` in my case) directory; this file isn't present in the two sub-directories (`META-INF` and `OEBPS`). – craig Mar 25 '14 at 13:24
2

Here is the command I have used successfully:

zip -Xr epubfilename.ePUB mimetype  META-INF OEBPS -x \*.DS_Store

This places files in the right order (mime type first, then META-INF with container.xml next, finally everything else) and excludes .DS_store since it looks like you are on a Mac.

Note that you will need to do this from within the book.epub.d directory in your example to produce the correct output.

I also recommend double checking results with epubcheck (https://github.com/IDPF/epubcheck or http://validator.idpf.org) if you are not already doing so.

mwu
  • 472
  • 6
  • 13
  • Worked for me. I had to Google .DS_Store (not applicable in my case). +1 for epubcheck. That is a critical tool I use daily. – Paulb Mar 25 '14 at 11:25
  • This works: `zip -Xr epubfilename.ePUB mimetype META-INF OEBPS` as does `zip -r epubfilename.ePUB mimetype META-INF OEBPS -x \*.DS_Store`. You can use `-x` to exclude specific files (`.DS_Store`); '-X' excludes all 'extra file attributes (including `.DS_Store`). – craig Mar 25 '14 at 13:29
  • The key to solving the problem, it seems, is to specify the names of files and sub-folders to include; I haven't tested the order so I'll take your word for it. – craig Mar 25 '14 at 13:31
  • You don't need to specify the order beyond the mimetype file, and you can use wildcards for the remaining files and directories. A simple bash wrapper: http://blog.threepress.org/2009/11/06/3-scripts-for-epub-creation/ – Liza Daly Mar 25 '14 at 13:37