View Single Post
Old 11-09-2015, 01:19 PM   #7
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Not exactly.

I think you need to pass the `-D` switch as well.
Otherwise you can see you have a listing for the actual directories as well, which I *think* might be a problem, and if you take a look at the raw file, the mimetype is moved over.
I have no idea how exactly the mimetype is read, but apparently it's very fragile!
Must be right at the beginning, blah blah blah...

Code:
#!/bin/bash

epub="$(realpath "$1")"
tmp_epub=$(mktemp -d)

unzip "$epub" -d $tmp_epub
pushd $tmp_epub
CONTENT='\t\t<meta property="rendition:layout">pre-paginated</meta>\n\t\t<meta name="original-resolution" content="584x754"/>'
sed -i '/<\/metadata>/i\'"$CONTENT" content.opf
zip -X0 "$epub" mimetype
zip -rDX9 "$epub" * -x mimetype
pushd
rm -rf $tmp_epub
My script doesn't do as much moving around, which is like a total waste of a CPU cycle or two.
And it's "cleaner" to put the extracted files in /tmp - right?

You can also redirect most of the output to /dev/null if you want to make it really professional and distribute it.

Last edited by eschwartz; 11-09-2015 at 01:24 PM.
eschwartz is offline   Reply With Quote