Skip to content

Instantly share code, notes, and snippets.

@robotmedia
Created September 19, 2011 13:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robotmedia/1226536 to your computer and use it in GitHub Desktop.
Save robotmedia/1226536 to your computer and use it in GitHub Desktop.
Zepub: Shell Script to Package & Validate ePub Files
#
# zepub.sh 0.1
# Package & Validate ePub Files
# by @robot_media (http://www.robotmedia.net)
# thanks to @lizcastro (http://www.elizabethcastro.com/epub/)
#
# INSTRUCTIONS
#
# Make zepub.sh executable: chmod +x zepub.sh
# Optional: to validate the resulting ePub files change the validator_path variable below.
#
# EXAMPLES
#
# sh zepub book.epub
# sh zepub book.epub /my/epub/folder
# Path to EpubCheck (http://code.google.com/p/epubcheck)
validator_path="/path/to/epubcheck/epubcheck-1.2.jar"
function usage () {
cat <<EOF
Usage: zepub output [input]
EOF
}
# Output argument
if [ -z "$1" ]; then
usage
exit 0
fi
output=$1
# Remove existing output
rm -f $output
# Input argument
if [ -n "$2" ]; then
input=$2
else
input="."
fi
# Package
initial=$PWD
cd $input
zip -0Xq $initial/$output mimetype
zip -Xr9Dq $initial/$output * -x zepub.sh *.epub *.DS_Store
echo $output
# Validate
if [ -f $validator_path ]; then
cd $initial
java -jar $validator_path $output
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment