diff options
| author | Charlotte Koch <charlotte@magentastripe.com> | 2024-10-02 13:27:38 -0700 |
|---|---|---|
| committer | Charlotte Koch <charlotte@magentastripe.com> | 2024-10-02 13:27:38 -0700 |
| commit | 628e38cabecb8b31ba4e619aa488e591ae6d4149 (patch) | |
| tree | b649ea6239572b5decef942e6c8f7c7f287de781 /script | |
| parent | 1df8631e84f6280dc534642bdd8167817ca153e0 (diff) | |
Move "add extra fonts to EPUB feature" out into its own script
Diffstat (limited to 'script')
| -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 - |
