More about IT >

makepub

Makepub is a small Linux/UNIX utility that takes some of the last-minute drudgery out of building an ePub media file from source. It is also intended as an educational tool, to:

To this end it is written as a monolithic posix-compliant shell script.

Makepub is compatible with the IDPF EPUB 2.0.1, 3 and 3.0.1 specifications.

Any and all feedback will be gratefully received.

Current version: 0.0.3 dated 22 Jul 2016.

Copyright © Guy Inchbald 2016.

Quick download from here.

What it does

Makepub uses zip to build an ePub media file from a prepared xml source tree.

When you run makepub, it will prompt you for the filename and make sure that the .epub dot extension is done right. If you just hit return, it will default to new.epub. If an epub with the same name already exists, it will be overwritten.

Makepub currently takes care of the xml container and mimetype, along with the picky zip compression requirements.

If you have already provided a mimetype, makepub will overwrite it.

If you have set up your own /META-INF directory, makepub will:

The main content files are assumed to be in an /OEBPS directory. This is an integral part of the IDPF EPUB 2.0.1 specification, which although obsolescent is still widely used, and it is also compatible with the later 3 and 3.0.1 specifications.

If you have put anything else next to /OEBPS, makepub will ignore it.

What it doesn't do

At the moment the package document (.opf file) must still be provided within /OEBPS.

Makepub does *not* check *your* source files or your .opf package document!

Before running

Check for the dependency on your system and if need be install it:

Ensure necessary EPUB 2.0.1 compliance:

Download makepub.sh and place a runtime copy in the parent directory next to /OEBPS.

Wishlist

Detect zip, compress, gzip, etc. and use whichever.

Ability to create and populate both /OEBPS and /OEBPS/content.opf.

Option to abandon 2.0.1 compatibility and run with 3+.

Options to enter source and dest path/filenames at runtime:

Source code

#!/bin/sh
# makepub version 0.0.3
# last modified 22 Jul 2016
# Validated posix compliant by ShellCheck: https://www.shellcheck.net/
# Copyright © Guy Inchbald 2016
#
# Description
# -----------
# Builds an ePub media file, from prepared xml source including package document (.opf)
#
# Before running
# --------------
# Install any missing dependencies:
#   zip
# Ensure necessary EPUB 2.0.1 compliance: 
#   all plain text files UTF-8 character encoded,
#   all content files placed in /OEPBS and defined in /OEBPS/content.opf
# Place your runtime copy of makepub.sh in the parent directory of /OEBPS
#
# Function
# --------
# Prompts for manual filename entry in command shell,
#   entry of .epub dot extension is optional,
#   If no filename is provided, defaults to new.epub.
# Creates and overwrites any existing mimetype.
# Checks for and if need be creates /META-INF/container.xml,
#   ignores any other files in /META-INF.
# Overwrites any existing epub with the same name.
# Compatible with IDPF EPUB 2.0.1, 3 and 3.0.1 specifications, 
#   but does *not* check *your* source files or package document!
#
# Wantlist
# --------
# Detect zip, compress, gzip, etc. and use whichever.
# Ability to create and populate both /OEBPS and /OEBPS/content.opf.
# Option to abandon 2.0.1 compatibility and run with 3+.
# Options to enter source and dest path/filenames at runtime:
#   ./makepub.sh -s source/path -d dest/path/filename,
#   before checking whether or not the .epub suffix is entered.

# input filename from terminal. (read -p is undefined in posix)
printf "Enter ePub file name and press [ENTER]: "
read -r NAME

# check for null return
if [ -z "$NAME" ]; then
  NAME=new
fi

# ensure .epub dot extension is present
if [ ${NAME} = ${NAME%.epub} ]; then
  NAME=$NAME.epub
fi

# create mimetype file, uncompressed
echo "application/epub+zip" > mimetype 
zip -X0 $NAME mimetype

# check for and if need be add the xml container, compressed
if [ ! -d META-INF ]; then
  mkdir META-INF
fi
if [ ! -r META-INF/container.xml ]; then
  echo > META-INF/container.xml
  printf '\n\n  \n    \n  \n' >> META-INF/container.xml
fi
zip -X9Dr $NAME META-INF

# add the rest, compressed
zip -X9Dr $NAME OEBPS

Updated 22 July 2016