#! /bin/bash
# hathifetch.sh
# Program to retrieve JSON records from Hathi Trust and extract the marc records from those JSON records.
# $Id: hathifetch.sh

E_BADARGS=65

scriptdir=$( (cd -P $(dirname $0) && pwd) )
if ! [ -e $scriptdir/SolrMarc.jar ]
then
  scriptdir=$( (cd -P $(dirname $0)/.. && pwd) )
fi

if ! [ -p /dev/stdin ]
then
  if [ $# -eq 0 ]
  then
    echo "    Usage: `basename $0` [-s NumToSkip] [-n NumToReturn] file_with_ids "
    echo "      or : `basename $0` [-s NumToSkip] [-n NumToReturn] url_with_ids "
    echo "      or : cat file_with_hathi_ids | `basename $0` [-s NumToSkip] [-n NumToReturn]"
    echo "      other options  -d = debug     retrieve and print the recordURL strings only"
    echo "                     -v = verbose   fetch records and print them out as Ascii Marc"
    echo "      Note: file_with_ids can be Hathi Record numbers only (one per line), or Hathi Data listings"
    echo "            like the following line where the Hathi Record number is one of several entries on a line."
    echo "      Note also that the program supports reading gzipped input files."
    exit $E_BADARGS
  fi
fi

java -Dsolrmarc.main.class="org.solrmarc.tools.HathiPlunderer" -jar $scriptdir/SolrMarc.jar $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12

exit 0
