#!/bin/bash # 20130220: lit2epub by B. Watson (part of convertlit slackbuilds.org build) # Licensed under the WTFPL. # Wrapper script for convertlit, zips up convertlit's output dir # and cleans it up afterward. Leave the shebang line alone, this # uses at least one bash-specific feature. NAME=$( basename $0 ) TMP=${TMP:-/tmp} OUTDIR=$TMP/$NAME.$$.$RANDOM set -e if [ "$1" = "" -o "$1" = "--help" -o "$1" = "-h" ]; then cat <&2 exit 1 fi elif [ "$2" = "-" ]; then OUTFILE="$OUTDIR/output.epub" else OUTFILE="$( readlink -f "$OUTFILE" )" fi # convertlit and zip both want to spew status messages to stdout, # redirect to stderr so we can output just the .epub to stdout. convertlit -d "$INFILE" "$OUTDIR"/ 1>&2 ( cd "$OUTDIR" ; zip -r "$OUTFILE" * 1>&2 ) if [ "$2" = "-" ]; then cat "$OUTFILE" OUTFILE="(standard output)" fi echo 1>&2 echo "$INFILE => $OUTFILE" 1>&2 exit 0