#!/bin/sh
#
# display-config
#
# This shell reads the GNATS configuration file, and displays the results
# in a more humane format.
#
 
GNATS_ROOT=/usr/local/lib/gnats/gnats-db

#
# First, we grab the file.
#

. $GNATS_ROOT/gnats-adm/config


#
# Clear the screen
#

tput clear

#
# Now, display each value, accompanied by some descriptive text.
#

echo This is a display of the information inside the config file, decoded
echo into a more \'user-friendly\' format.  The actual lines from the
echo config file are displayed prior to the explaination.  The config
echo lines are preceeded by the record number for each line, to make
echo identification easier.
echo
echo
grep -in '^GNATS_ADDR' $GNATS_ROOT/gnats-adm/config
grep -in '^GNATS_ADMIN' $GNATS_ROOT/gnats-adm/config
grep -in '^GNATS_SITE' $GNATS_ROOT/gnats-adm/config
echo \'$GNATS_ADDR\' is the userid on \'$GNATS_SITE\' which receives bug reports.
echo
echo The Gnats administrator\'s e-mail id is: \'$GNATS_ADMIN\'
echo 
grep -in '^SUBMITTER' $GNATS_ROOT/gnats-adm/config
echo The name for this local GNATS submission site is \'$SUBMITTER\'
echo
grep -in '^DEFAULT_RELEASE' $GNATS_ROOT/gnats-adm/config
echo If GNATS problems are submitted with no release number they will 
echo default to \'$DEFAULT_RELEASE\'
echo
grep -in '^DEFAULT_ORGANIZATION' $GNATS_ROOT/gnats-adm/config
echo The default organization is \'$DEFAULT_ORGANIZATION\'
echo
grep -in '^DEFAULT_SUBMITTER' $GNATS_ROOT/gnats-adm/config
echo The default submitter is\: \'$DEFAULT_SUBMITTER\'
echo

#
# Process the booleans.
#

grep -in '^NOTIFY' $GNATS_ROOT/gnats-adm/config
if [ $NOTIFY ]
then
   echo Automatic reminders are enabled.  \(default\)
   echo This means that if a call is not changed out of the \'open\' state
   echo after a predefined period of time, a reminder is e-mailed to the 
   echo maintainer\(s\) of the PR.
   # Decode the business hours.
grep -in '^BDAY_START' $GNATS_ROOT/gnats-adm/config
grep -in '^BDAY_END' $GNATS_ROOT/gnats-adm/config
grep -in '^BWEEK_START' $GNATS_ROOT/gnats-adm/config
grep -in '^BWEEK_END' $GNATS_ROOT/gnats-adm/config
   if [ $BDAY_START -gt 12 ]
   then
      BDAY_START=`echo $BDAY_START - 12 | bc`
      BDAY_START=$BDAY_START" pm"
   else
      BDAY_START=$BDAY_START" am"
   fi
   if [ $BDAY_END -gt 12 ]
   then
      BDAY_END=`echo $BDAY_END - 12 | bc`
      BDAY_END=$BDAY_END" pm"
   else
      BDAY_END=$BDAY_END" am"
   fi
   case $BWEEK_START in
   0) WEEK_START="Sunday";;
   1) WEEK_START="Monday";;
   2) WEEK_START="Tuesday";;
   3) WEEK_START="Wednesday";;
   4) WEEK_START="Thursday";;
   5) WEEK_START="Friday";;
   6) WEEK_START="Saturday";;
   esac
   case $BWEEK_END in
   0) WEEK_END="Sunday";;
   1) WEEK_END="Monday";;
   2) WEEK_END="Tuesday";;
   3) WEEK_END="Wednesday";;
   4) WEEK_END="Thursday";;
   5) WEEK_END="Friday";;
   6) WEEK_END="Saturday";;
   esac
   echo Business hours are\:
   echo \ \ \ \ \  $WEEK_START through $WEEK_END $BDAY_START to $BDAY_END
else
   echo Automatic reminders are disabled.
   echo No reminders are sent to maintainer\(s\) of PRs.
fi

echo

grep -in '^ACKNOWLEDGE' $GNATS_ROOT/gnats-adm/config
if [ $ACKNOWLEDGE ]
then
   echo Automatic acknowledgements are enabled.  \(default\)
   echo This option will tell GNATS to send an acknowledgement to the
   echo originator of a PR when the PR is filed in the database.
else
   echo Automatic acknowledgements are disabled.
   echo When a PR is submitted, an acknowledgement will not be sent to
   echo the originator.
fi

echo

grep -in '^KEEP_RECEIVED_HEADERS' $GNATS_ROOT/gnats-adm/config
if [ $KEEP_RECEIVED_HEADERS ]
then
   echo GNATS is configured to keep mail headers.  \(default\)
   echo Please note that this takes up a lot of space in your database,
   echo and is seldom used.  It is useful for debugging.
else
   echo GNATS is configured to remove mail headers before filing the PR.
fi

echo

grep -in '\^DEBUG_MODE' $GNATS_ROOT/gnats-adm/config
if [ $DEBUG_MODE ]
then
   echo Debug mode is set.  This means that ALL mail will be forwarded to \\c
   echo \'$GNATS_ADMIN\'.
else
   echo Debug mode is not set.  \(default\)
fi

