#!/bin/sh -e
#
# booktext - convert input images into text files
# dependencies: tesseract-ocr

while getopts 'o:' flag; do
  case "${flag}" in
    o) outfile=${OPTARG} ;;
    *) exit 1 ;;
  esac
done
shift "$((OPTIND - 1))"

[ -f "${outfile:=scantotext.txt}" ] && {
  echo "'${outfile}' already exists"
  exit 1
}

for file; do
  echo "Converting: ${file}"
  tesseract -l eng "${file}" - >>"${outfile}"
done
