#!/bin/bash -
#===============================================================================
#
#         FILE: make_reports
#
#        USAGE: ./make_reports
#
#  DESCRIPTION: Script to generate all the feedWatcher reports needed for
#               conferences, etc
#
#      OPTIONS: ---
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: ---
#       AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
#      VERSION: 0.0.1
#      CREATED: 2023-01-09 17:07:23
#     REVISION: 2023-01-09 17:39:22
#
#===============================================================================

set -o nounset                              # Treat unset variables as an error

# SCRIPT=${0##*/}
# DIR=${0%/*}

#
# Paths
#
BASEDIR="$HOME/HPR/feed_watcher"

cd "$BASEDIR" || { echo "Failed to cd to $BASEDIR"; exit 1; }

#
# Files and sanity checks
#
FW="$BASEDIR/feedWatcher"
[ -e "$FW" ] || {
    echo "Script $FW appears to be missing"
    exit 1
}
FWTPL3="$BASEDIR/feedWatcher_3.tpl"
[ -e "$FWTPL3" ] || {
    echo "Template $FWTPL3 appears to be missing"
    exit 1
}
FWHTML="$BASEDIR/feedWatcher.html"
FWMKD="$BASEDIR/feedWatcher.mkd"
FWPDF="$BASEDIR/feedWatcher.pdf"

#
# Generate HTML, JSON and OPML reports.
# The template defaults to 'feedWatcher.tpl', the JSON file to
# 'feedWatcher.json' and the OPML file to 'feedWatcher.opml'. The script
# reports information about this, except for the HTML.
#
$FW -template -json -opml -out="$FWHTML"
if [[ -e "$FWHTML" ]]; then
    echo "HTML written to $FWHTML"
else
    echo "$FWHTML doesn't seem to have been written"
fi

#
# Generate Markdown
#
$FW -tem="$FWTPL3" -out="$FWMKD"
if [[ -e "$FWMKD" ]]; then
    echo "Markdown written to $FWMKD"
else
    echo "$FWMKD doesn't seem to have been written"
fi

#
# Use the Makefile to create PDF
#
make all
RES=$?
[ $RES -ne 0 ] && {
    echo "Problem running 'make'; aborting!"
    exit $RES
}

if [[ -e "$FWPDF" ]]; then
    echo "PDF written to $FWPDF"
else
    echo "$FWPDF doesn't seem to have been written"
fi

exit

# vim: syntax=sh:ts=8:sw=4:ai:et:tw=78:fo=tcrqn21

