#!/bin/sh
########################################################################
# BooNE info-message utility
#
# To be placed in /etc/X11/xinit/xinitrc.d for execution upon X-session
# start.
#
# See whether the user has any new Info messages and display them to the
# screen.
#
# Use config file $BOONE_INFO/../info-message/info-message.cfg
#
# Chris Green <greenc@fnal.gov>
# UCR / BooNE
# 2002/04/09
#
########################################################################

# Default values in case config file doesn't tell us anything.
geometry=""
timeout=5

info_message_dir="/afs/fnal.gov/files/code/e898/code/6/info-message"
backtime="$info_message_dir/backtime"
cfgfile="$info_message_dir/info-message.cfg"

# Need to know about ups
if [ -f "/afs/fnal.gov/ups/etc/setups.sh" ] ; then 
  . "/afs/fnal.gov/ups/etc/setups.sh"
elif [ -f ~products/etc/setups.sh ]; then
  . ~products/etc/setups.sh
fi

# Source the config file
if [ -f "$cfgfile" ] ; then
  . $cfgfile
fi

# ups setup for the Info package
if [ -z "$SETUP_INFO" ]; then
  setup Info
fi

# If we have a .Info-marker, set the date on .Info to the date on
# .Info-marker else remove .Info
if [ -f ~/.Info-marker ]; then
  touch -r ~/.Info-marker ~/.Info
else
  rm ~/.Info
fi

# Do we have new Info articles?
if $INFO_DIR/bin/Info -anynewcode; then
  # No
  :
else
  # Put up an X window
  output="$($INFO_DIR/bin/Info -new)
"
  xmessage -geometry "$geometry" -timeout $timeout -buttons Dismiss -default Dismiss "$output" &
  # Update the reference marker.
  touch -r ~/.Info ~/.Info-marker
fi