Skip to content

Instantly share code, notes, and snippets.

@madevelopers
Created April 23, 2014 06:21
Show Gist options
  • Save madevelopers/11204479 to your computer and use it in GitHub Desktop.
Save madevelopers/11204479 to your computer and use it in GitHub Desktop.
A simple shell script for packaging epubs
#!/usr/bin/env bash
#
# A simple shell script for packaging epubs.
#
epub_dir="${1}" # required
epub_filename="${2}" # optional
function package_epub {
# get inside the epub directory and package it there
root=${1}
name=$(basename ${root})
# get inside the epub directory and package it there
cd ${root}
if [[ -z ${2} ]]; then
# use directory name as epub filename
# if preferred name is not defined
epub_file=${name}.epub
else
epub_file=${2}
fi
if [[ -f ${epub_file} ]]; then
# remove old epub
rm -f ${epub_file}
fi
if [[ ! -f mimetype ]]; then
# create mimetype if missing
echo "application/epub+zip" > mimetype
fi
# http://www.webvivant.com/zipping-epub-files.html
zip -j -X -0 -m ${epub_file} mimetype
zip -r -g -9 ${epub_file} *
echo "Done packaging epub: ${epub_file}"
}
if [[ -z ${epub_dir} ]]; then
echo "Please specify an epub directory as the first argument"
elif [[ -d ${epub_dir} ]]; then
package_epub ${epub_dir} ${epub_filename}
else
echo "epub directory not found or is not a directory"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment