Created
April 23, 2014 06:21
-
-
Save madevelopers/11204479 to your computer and use it in GitHub Desktop.
A simple shell script for packaging epubs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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