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