#!/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/[^<]*/<title>$title/" # join all the files and open in w3m sed -e $fix_links -e "$fix_title" $filepaths > "$temp/book.html" w3m "$temp/book.html"