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