Merge branch 'list_safety'
[exim.git] / src / src / eximon.src
CommitLineData
059ec3d9
PH
1# Base source of start-up shell script for the Exim Monitor. Used to set the
2# required environment variables before running the program. Using script
3# rather than a configuration file means that computation can be done.
4# The build process concatenates on the front of this various settings from
5# os-specific files and from the user's configuration file.
6
7# Copyright (c) 2004 University of Cambridge.
8# See the file NOTICE for conditions of use and distribution.
9
10# Except when they appear in comments, the following placeholders in this
11# source are replaced when it is turned into a runnable script:
12#
13# CONFIGURE_FILE_USE_NODE
14# CONFIGURE_FILE
15# BIN_DIRECTORY
16# BASENAME_COMMAND
17# HOSTNAME_COMMAND
18# X11_LD_LIBRARY
19
20# PROCESSED_FLAG
21
22# Save arguments (can be the usual X parameters)
23
24cmd_args="$@"
25
26# See if this installation is using the esoteric "USE_NODE" feature of Exim,
27# in which it uses the host's name as a suffix for the configuration file name.
28
29if [ "CONFIGURE_FILE_USE_NODE" = "yes" ]; then
30 hostsuffix=.`uname -n`
31fi
32
33# Now find the configuration file name. This has got complicated because
34# CONFIGURE_FILE may now be a list of files. The one that is used is the first
35# one that exists. Mimic the code in readconf.c by testing first for the
36# suffixed file in each case.
37
38set `awk -F: '{ for (i = 1; i <= NF; i++) print $i }' <<End
39CONFIGURE_FILE
40End
41`
42while [ "$config" = "" -a $# -gt 0 ] ; do
43 if [ -f "$1$hostsuffix" ] ; then
44 config="$1$hostsuffix"
45 elif [ -f "$1" ] ; then
46 config="$1"
47 fi
48 shift
49done
50
51# Determine where the spool directory is and whether there is any setting of
52# log_file_path. Search for an exim_path setting in the configure file;
53# otherwise use the bin directory. Call that version of Exim to find the spool
54# directory and the setting of log_file_path.
55
56config=${EXIMON_EXIM_CONFIG-$config}
57
58# Add code here to redefine "config" if an alternative configuration file
59# should be used in some circumstances. If you do that, you should also arrange
60# for the value to be set in EXIMON_EXIM_CONFIG, and to export that variable
61# into the environment. BEWARE: a tab character is needed in the command below.
62# It has had a nasty tendency to get lost in the past. Use a variable to hold a
63# space and a tab to keep the tab in one place.
64
65st=' '
66EXIM_PATH=`grep "^[$st]*exim_path" $config | sed "s/.*=[$st]*//"`
67if test "$EXIM_PATH" = ""; then EXIM_PATH=BIN_DIRECTORY/exim; fi
68
69SPOOL_DIRECTORY=`$EXIM_PATH -C $config -bP spool_directory | sed 's/.*=[ ]*//'`
70LOG_FILE_PATH=`$EXIM_PATH -C $config -bP log_file_path | sed 's/.*=[ ]*//'`
71
72# If log_file_path is "syslog" then logging is only to syslog, and the monitor
73# is unable to display a log tail unless EXIMON_LOG_FILE_PATH is set to tell
74# it where the log data is. Otherwise, remove any occurrences of
75# "syslog:" or ":syslog" (spaces allowed in various places) and look at the
76# remainder of the entry. If it's null, the default is "mainlog" in the
77# "log" directory in the spool directory. Otherwise, set the name from the
78# given path.
79
80if [ "$EXIMON_LOG_FILE_PATH" != "" ] ; then
81 LOG_FILE_NAME="$EXIMON_LOG_FILE_PATH"
82elif [ "$LOG_FILE_PATH" = "syslog" ] ; then
83 LOG_FILE_NAME=""
84 echo \*\*\*
85 echo Exim is using the syslog interface for its log data. If you redirect all
86 echo MAIL.INFO syslog messages into a separate file, you can point eximon at
87 echo that file with the EXIMON_LOG_FILE_PATH environment variable.
88 echo \*\*\*
89else
90 LOG_FILE_NAME=`echo $LOG_FILE_PATH | \
91 sed -e 's/ *: *syslog *: */:/' \
92 -e 's/ *: *syslog *$//' \
93 -e 's/^ *syslog *: *//' \
94 -e 's/%s/main/'`
95 if [ "$LOG_FILE_NAME" = "" ] ; then
96 LOG_FILE_NAME=$SPOOL_DIRECTORY/log/mainlog
97 fi
98fi
99
100# The basename and hostname commands vary from system to system
101
102basename=BASENAME_COMMAND
103hostname=HOSTNAME_COMMAND
104
105# SunOS5 is a pain in that they may be in one of two places. So is Linux
106# in the case of basename. Set up a general mechanism for searching for
107# them in several places.
108
109if [ "${basename}" = "look_for_it" ] ; then
110 if [ -f /usr/bin/basename ] ; then
111 basename=/usr/bin/basename
112 else
113 if [ -f /bin/basename ] ; then
114 basename=/bin/basename
115 else
116 basename=/usr/ucb/basename
117 fi
118 fi
119fi
120
121if [ "${hostname}" = "look_for_it" ] ; then
122 if [ -f /usr/bin/hostname ] ; then
123 hostname=/usr/bin/hostname
124 else
125 if [ -f /bin/hostname ] ; then
126 hostname=/bin/hostname
127 else
128 hostname=/usr/ucb/hostname
129 fi
130 fi
131fi
132
133# Set hostname to the full hostname with the specified domain
134# stripped off its end. On Solaris 2, the default basename
135# command treats its suffix argument as a pattern. Consequently,
136# if fullhostname contains no dots but ends with what looks like
137# the domain, straightforward use of basename screws things up.
138# Use a general test for this case, just in case any other OS
139# do the same.
140
141fullhostname=`${hostname}`
142case `${basename} abc .c` in
143 a) hostname=`${basename} ${fullhostname} '\.'${DOMAIN}` ;;
144 *) hostname=`${basename} ${fullhostname} .${DOMAIN}` ;;
145esac
146
147
148# Arrange for the window title field to be substituted by the shell
149# so that it can contain either the full or the short host name. This
150# is a tedious little bit of magic, but I don't know how to do it
151# in a less tortuous way.
152
153WINDOW_TITLE=`fullhostname=${fullhostname} hostname=${hostname} /bin/sh <<xx
154echo ${WINDOW_TITLE}
155xx
156`
157
158# Add the X11 library to the library path, and then export the
159# environment variables used by eximon. The string X11-LD-LIBRARY
160# (with underscores, not hyphens) below is replaced by the configured
161# library name when the script is built. (Hyphens are used in the description
162# to stop it getting changed there too.)
163
164X11LIB=X11_LD_LIBRARY
165
166if [ "${LD_LIBRARY_PATH}" = "" ] ; then
167 LD_LIBRARY_PATH=${X11LIB}
168else
169 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${X11LIB}
170fi
171
172export EXIM_PATH LD_LIBRARY_PATH \
173 LOG_BUFFER LOG_DEPTH LOG_FILE_NAME LOG_FONT LOG_WIDTH \
174 ACTION_OUTPUT ACTION_QUEUE_UPDATE\
175 MENU_EVENT MIN_HEIGHT MIN_WIDTH \
176 QUALIFY_DOMAIN QUEUE_DEPTH QUEUE_FONT QUEUE_INTERVAL QUEUE_MAX_ADDRESSES \
177 QUEUE_STRIPCHART_NAME QUEUE_TOTAL QUEUE_WIDTH SPOOL_DIRECTORY \
178 START_DEPTH LOG_STRIPCHARTS SIZE_STRIPCHART SIZE_STRIPCHART_NAME \
179 START_SMALL STRIPCHART_INTERVAL \
180 TEXT_DEPTH WINDOW_TITLE
181
182# Exec to the program we really want to run, thereby continuing in
183# just the one process, and let it run in parallel with whatever
184# called this script.
185
186exec ${EXIMON_BINARY} $cmd_args &
187
188# End