diff options
Diffstat (limited to 'script/epub_font_stuffer.sh')
| -rw-r--r-- | script/epub_font_stuffer.sh | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/script/epub_font_stuffer.sh b/script/epub_font_stuffer.sh new file mode 100644 index 0000000..fe9939f --- /dev/null +++ b/script/epub_font_stuffer.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# +# epub_font_stuffer +# Charlotte Koch <charlotte@magentastripe.com> +# +# By default, the EPUB generated by asciidoctor-epub3(1) includes only a +# base set of fonts. This script augments the EPUB by including *all* the +# fonts from the given directory. +# +# This file is part of WilloraPDF. +# +# REQUIREMENTS: zip(1), unzip(1), rsync(1) +# + +set -e + +INPUT="" +OUTPUT="" +FONTDIR="" + +# Parse and verify command line arguments. + +die() { + echo "FATAL: $1" + exit 1 +} + +while [ $# -gt 0 ]; do + case "$1" in + --input) + INPUT="$2" + shift 2 + ;; + --output) + OUTPUT="$2" + shift 2 + ;; + --fontdir) + FONTDIR="$2" + shift 2 + ;; + *) + die "Unknown option: $1" + ;; + esac +done + +test -n "${INPUT}" || die "Missing argument: --input" +test -n "${OUTPUT}" || die "Missing argument: --output" +test -n "${FONTDIR}" || die "Missing argument: --fontdir" + +test -f "${INPUT}" || die "Can't find input file: ${INPUT}" +test -d "${FONTDIR}" || die "Can't find font directory: ${FONTDIR}" + +# Work around the need to change directories in the subsequent zip(1) +# command +real_output="$(pwd)/${OUTPUT}" + +# Extract the EPUB to a temporary location, copy the additional fonts into +# it, then zip it back up. +workdir="$(mktemp -d)" + +function cleanup() { + rm -rf ${workdir} +} + +trap cleanup EXIT + +unzip -q -d ${workdir} ${INPUT} +rsync -avr ${FONTDIR}/ ${workdir}/EPUB/fonts/ +cd ${workdir} +zip -r ${real_output} . +cd - |
