#!/bin/sh
# Copyright (c) 2008-2023 Andrew Ruthven <andrew@etc.gen.nz>
# This code is hereby licensed for public consumption under the GNU GPL v3.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

ME=molly-guard

if [ ! -f /usr/bin/mythtv_recording_soon ]; then
  echo "I: $ME: I can't find /usr/bin/mythtv_recording_soon, skipping check" >&2
  exit 0
fi

HOST="$(hostname --short)"

sigh()
{
  echo "Good thing I asked; I won't $MOLLYGUARD_CMD $HOST ..." >&2
  exit 1
}


if /usr/bin/mythtv_recording_soon; then
  trap 'echo;sigh' 1 2 3 10 12 15
  printf "MythTV is either recording now, or will be soon. Type YES to %s: " "$MOLLYGUARD_CMD"
  read CONFIRM || :

  [ "$(echo "$CONFIRM" | tr 'A-Z' 'a-z')" = "yes" ] || sigh

  trap - 1 2 3 10 12 15
fi

exit 0

