Unzip and zip OpenOffice.org ODT filesPosted: October 25, 2014
As you probably know, ODT files of OpenOffice.org (LibreOffice) are in essence just ZIP archives.
It is very easy to unpack them. But it is not so easy to create them. If you simply zip the contents of unpacked ODT and change the extension to .odt, it will not work.
The key here is that the mimetype file shall come into the archive first.
Two simple bash scripts are given here to extract and then pack back the ODT files.
Script odt_extract (provide .odt file name and desired destination directory as command line arguments):
echo "Extracting ODT file $1 to directory $2 ..."
unzip "$1" -d "$2" #1>/dev/null
Script odt_compress (provide source directory and desired .odt file name as command line arguments):
echo "Compressing contents of directory $1 into ODT compatible document $2 ... "
# Move into document source directory
# Special zipping procedure to create correctly structured ODT file
# Remember that if the provided resulting file path is relative, it shall be so in respect to the current working directory!
# First comes the "mimetype" file ...
zip -0 -X "$2" mimetype #1>/dev/null
# ... then everything else follows
zip -r "$2" * -x mimetype #1>/dev/null