diff --git a/scripts/book b/scripts/book new file mode 100755 index 0000000..237b32f --- /dev/null +++ b/scripts/book @@ -0,0 +1,27 @@ +#!/bin/sh + +# create temporary dir... +title=$(basename "$1") +temp="/tmp/book-$(echo "$title" | tr -- '[A-Z] ' '[a-z]-')" +mkdir "$temp" + +# ...and delete it on exit +trap 'rm -rf "$temp"' EXIT INT HUP +# extract book to it +unzip -q "$1" -d "$temp" + +# locate the path of the manifest +content_file=$temp/$(sed -n 's/.*full-path="\([^"]*\)".*/\1/p' "$temp/META-INF/container.xml") +content_dir="$(dirname "$content_file")" +# get the list of chapter files +filenames=$(sed -n '/media-type="application/s/.*href="\([^"]*\)".*/'"\1/p" "$content_file") +filepaths=$(printf "$content_dir/%s " $filenames) + +# strip filepaths from links +fix_links=$(printf "s/%s//g;" $filenames) +# set title to basename +fix_title="s/