#! /bin/sh

# Start-up shell script for the Smail Monitor. Used to set the
# required environment variables before running the program. Using
# script rather than a configuration file means that computation
# can be done.

# Author:  Philip Hazel <ph10@cus.cam.ac.uk>
# Version: 1.00
# Date:    March 1995


##################################################################
#      Set these variables as appropriate for your system        #
##################################################################

# The location of the smail log file.

SMAILLOGFILE=/var/spool/smail/log/logfile

# The location of the smail spool input directory.

SMAILINPUTDIR=/var/spool/smail/input

# The name of the smailmon binary program. It will be assumed that
# the readspool binary is in the same directory as the smailmon
# binary.

SMAILMON=$0.code

# The X11R5 library directory.

X11R5LIB=/opt/X11R5/lib

# The visible name for your domain. The only use made of this is for
# testing that certain addresses are the same when displaying the
# log tail, and for shortening sender addresses in the queue display. 

VISIBLE_NAME=??

# The initial depth for the main display window, in pixels. The minimum
# is 160, which is enough to hold the stripcharts but not the other
# display sub-windows.

START_DEPTH=700

# The title for smailmon's main display window. It is possible to have
# host name of the machine you are running on substituted into the
# title string. If you include the string ${fullhostname} then the
# complete name is used. If you include ${hostname} then the full
# host name will have the string contained in the DOMAIN variable
# stripped from its right-hand end before being substituted. Any other
# shell or environment variables may also be included.

# If you use any substitutions, remember to ensure that the $ and {} 
# characters are escaped from the shell, e.g. by using single quotes.

WINDOW_TITLE='${hostname} smailmon'

# The domain that you want to be stripped from the machine's full hostname
# when forming the short host name for the smailmon window title, as
# described above.

DOMAIN=??

# Parameters for the rolling display of the tail of the smail log file.
# The width and depth are measured in pixels; LOG_BUFFER specifies the
# amount of store to set aside for holding the log tail, which is displayed
# in a scrolling window. When this store is full, the earlier 50% of it
# is discarded - this is much more efficient that throwing it away line
# by line. The number given can be followed by the letter K to indicate
# that the value is in kilobytes. A minimum value of 1K is enforced.

LOG_DEPTH=150
LOG_WIDTH=750
LOG_BUFFER=20K

# The font which is used in the log tail display. This is defined in
# the normal X manner. It must be a "character cell" font, because this
# is required by the text widget.

LOG_FONT=-misc-fixed-medium-r-normal-*-14-140-*-*-*-*-iso8859-1

# Parameters for the display of message that are on the smail queue.
# The width and depth are measured in pixels.

QUEUE_DEPTH=200
QUEUE_WIDTH=750

# The font which is used in the queue display.

QUEUE_FONT=$LOG_FONT

# When a message has more than one undelivered address, they are listed
# one below the other. A limit can be placed on the number of addresses
# displayed for any one message. If there are more, then "..." is used
# to indicate this.

QUEUE_MAX_ADDRESSES=10

# The display of the contents of the queue is updated every QUEUE_INTERVAL
# seconds by default (there is a button to request update). 

QUEUE_INTERVAL=300

# The stripcharts are updated every STRIPCHART_INTERVAL seconds.

STRIPCHART_INTERVAL=60

# The following variable contains a specification of which stripcharts
# you want smailmon to display. The string consists of pairs of strings,
# delimited by slash characters. The first string in each pair is a regular
# expression that matches some distinguishing feature in a smail log entry.
# Entries that match the expression will be counted and displayed in a
# stripchart whose title is given by the second string. The string may 
# be continued over several input lines, provided that it is split
# after a slash, and an additional slash (optionally preceded by white
# space) is included at the start of the continuation line.

# The regular expression syntax supported by smailmon is as follows:

# A regular expression is zero or more branches, separated by `|'. It
# matches anything that matches one of the branches. A branch is zero or
# more pieces, concatenated. It matches a match for the first, followed by
# a match for the second, etc. A piece is an atom possibly followed by
# `*', `+', or `?'.
# 
# An atom followed by `*' matches a sequence of 0 or more matches of the atom.
# An atom followed by `+' matches a sequence of 1 or more matches of the atom.
# An atom followed by `?' matches a match of the atom, or the null string.
# 
# An atom is a regular expression in parentheses (matching a match for the
# regular expression), a range (see below), `.' (matching any single
# character), `^' (matching the null string at the beginning of the input
# string), `$' (matching the null string at the end of the input string),
# a `\' followed by a single character (matching that character), or a
# single character with no other significance (matching that character).
# 
# A range is a sequence of characters enclosed in `[]'. It normally
# matches any single character from the sequence. If the sequence begins
# with `^', it matches any single character not from the rest of the
# sequence. If two characters in the sequence are separated by `\-', this
# is shorthand for the full list of ASCII characters between them (e.g.
# `[0-9]' matches any decimal digit). To include a literal `]' in the
# sequence, make it the first character (following a possible `^'). To
# include a literal `-', make it the first or last character.

# A stripchart showing the count of messages in the queue is always 
# displayed on the left of smailmon's window. Stripcharts configured
# by this parameter are displayed to its right, in the order defined
# here.

STRIPCHARTS='/] received/in/
             /] delivered/out/
             /director:/local/
             /transport: smtp/smtp/'


##################################################################
#    It is not normally necessary to edit anything below here    #
##################################################################


# Code to find the host name for this system - unfortunately this
# is architecture-dependent.

arch="`uname -rs`"
case "$arch" in
  'Linux'*)
  hostname=/bin/hostname
  basename=/usr/bin/basename
;;
  'HP-UX'*)
  hostname=/bin/hostname
  basename=/bin/basename
;;
  'OSF1'*)
  hostname=/usr/bin/hostname
  basename=/usr/bin/basename
;;
  'SunOS 4.'*)
  hostname=/usr/bin/hostname
  basename=/usr/bin/basename
;;
  'SunOS 5.'*)
  hostname=/usr/ucb/hostname
  basename=/usr/ucb/basename
;;
  'IRIX'*)
  export hostname=/usr/bsd/hostname
  export basename=/sbin/basename
;;                                                            
  'ULTRIX'*)
  export hostname=/bin/hostname
  export basename=/usr/bin/basename
;;   
  *)
  echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
  echo Something has gone horribly wrong here.
  echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;;
esac

# Set hostname to the full hostname with the specified domain
# stripped off its end.

fullhostname=`${hostname}`
hostname=`${basename} ${fullhostname} .${DOMAIN}`

# Arrange for the window title field to be substituted by the shell
# so that it can contain either the full or the short host name. This
# is a tedious little bit of magic, but I don't know how to do it
# in a less tortuous way.

WINDOW_TITLE=`fullhostname=${fullhostname} hostname=${hostname} /bin/sh <<xx
echo ${WINDOW_TITLE}
xx`

# Add the X11R5 library to the library path, and then export the
# environment variables used by smailmon.

LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${X11R5LIB}

export LD_LIBRARY_PATH \
  LOG_BUFFER LOG_DEPTH LOG_FONT LOG_WIDTH \
  QUEUE_DEPTH QUEUE_FONT QUEUE_INTERVAL QUEUE_MAX_ADDRESSES \
  QUEUE_TOTAL QUEUE_WIDTH \
  SMAILINPUTDIR SMAILLOGFILE SMAILMON START_DEPTH \
  STRIPCHARTS STRIPCHART_INTERVAL VISIBLE_NAME WINDOW_TITLE

# Exec to the program we really want to run, thereby continuing in
# just the one process, and let it run in parallel with whatever 
# called this script.

exec ${SMAILMON} $* &

# End
