fix tls_cipher memory lifetime.
[exim.git] / src / scripts / exim_install
CommitLineData
61ec970d 1#! /bin/sh
61ec970d
PH
2
3# Script to install Exim binaries in BIN_DIRECTORY, which is defined in
4# the local Makefile. It expects to be run in a build directory. It needs
5# to be run as root in order to make exim setuid to root. If exim runs setuid
6# to (e.g.) exim, this script should be run as that user or root.
7
8# This script also installs a default configuration file in CONFIGURE_FILE
9# if there is no configuration file there, but only if CONFIGURE_FILE specifies
10# single file. If it specifies a list, no action is taken.
11
12# If a default configuration file is installed, the existence of the system
13# aliases file is tested. A default, containing only comments, is installed if
14# necessary.
15
16# If INFO_DIRECTORY is defined in any of the local Makefiles, and the Exim doc
17# directory contains the Texinfo documentation, this script also installs a
18# the info files in INFO_DIRECTORY.
19
20# If DESTDIR is defined, all file paths are prefixed with ${DESTDIR}, with the
21# sole exception of the reference to the system aliases file in the default
22# configuration, because it is assumed that Exim is not actually going to be
23# run from this position. For backward compatibility, if DESTDIR is not
24# defined, ROOT is used instead.
25
26# The script can be made to output what it would do, without actually doing
27# anything, by giving it the option "-n" (cf make). Arguments are the names
28# of things to install. No arguments installs everything.
29
30do_chown=yes
31do_symlink=yes
32
33while [ $# -gt 0 ] ; do
34 case "$1" in
35 -n)
36 real="true || "
37 ver="verification "
38 com=": "
39 echo $com ""
40 echo $com "*** Verification mode only: no commands will actually be obeyed"
41 echo $com "*** You can cut and paste the bits you want to a shell, etc"
42 echo $com ""
43 echo cd `pwd`
44 ;;
45
46 -no_chown)
47 do_chown=no
48 ;;
49
50 -no_symlink)
51 do_symlink=no
52 ;;
53
54 *)
55 break
56 ;;
57 esac
58 shift
59done
60
61# Get the values of BIN_DIRECTORY, CONFIGURE_FILE, INFO_DIRECTORY, NO_SYMLINK,
62# SYSTEM_ALIASES_FILE, and EXE from the global Makefile (in the build
63# directory). EXE is empty except in the Cygwin environment. In each case, keep
64# the latest definition, thus respecting the Makefiles precedence. The sed
65# sequences here are messy, but have to be very "basic" in order to work on
66# Solaris, where the regular expressions in sed are primitive indeed. Modify at
67# your peril.
68
69BIN_DIRECTORY=`sed -n -e '/^ *BIN_DIRECTORY *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
70CONFIGURE_FILE=`sed -n -e '/^ *CONFIGURE_FILE *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
71INFO_DIRECTORY=`sed -n -e '/^ *INFO_DIRECTORY *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
72NO_SYMLINK=`sed -n -e '/^ *NO_SYMLINK *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
14487e4c
PH
73
74CHOWN=`sed -n -e '/^ *CHOWN_COMMAND *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
75MV=`sed -n -e '/^ *MV_COMMAND *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
76
61ec970d
PH
77SYSTEM_ALIASES_FILE=`sed -n -e '/^ *SYSTEM_ALIASES_FILE *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
78EXE=`sed -n -e '/^ *EXE *=/{s/^[^=]*= *//; s/ \{1,\}#.*//;s/ *$//;h;}' -e '${g;p;}' Makefile`
79
80# Set a default for SYSTEM_ALIASES_FILE
81
82if [ "${SYSTEM_ALIASES_FILE}" = "" ] ; then
83 SYSTEM_ALIASES_FILE=/etc/aliases
84fi
85
86# Allow INST_xx to over-ride xx
87case "$INST_BIN_DIRECTORY" in ?*) BIN_DIRECTORY="$INST_BIN_DIRECTORY";; esac
88case "$INST_CONFIGURE_FILE" in ?*) CONFIGURE_FILE="$INST_CONFIGURE_FILE";; esac
89case "$INST_INFO_DIRECTORY" in ?*) INFO_DIRECTORY="$INST_INFO_DIRECTORY";; esac
90case "$INST_SYSTEM_ALIASES_FILE" in ?*) SYSTEM_ALIASES_FILE="$INST_SYSTEM_ALIASES_FILE";; esac
91
14487e4c
PH
92case "$INST_CHOWN" in ?*) CHOWN="$INST_CHOWN";; esac
93case "$INST_MV" in ?*) MV="$INST_MV";; esac
94
61ec970d
PH
95case "$INST_UID" in '') INST_UID=root;; *) INST_UID="$INST_UID";; esac
96case "$INST_CP" in '') CP=cp;; *) CP="$INST_CP";; esac
61ec970d 97case "$INST_LN" in '') LN=ln;; *) LN="$INST_LN";; esac
61ec970d
PH
98case "$INST_CHMOD" in '') CHMOD=chmod;; *) CHMOD="$INST_CHMOD";; esac
99case "$INST_DIRNAME" in '') DIRNAME=dirname;; *) DIRNAME="$INST_DIRNAME";; esac
100case "$INST_MKDIR" in '') MKDIR=mkdir;; *) MKDIR="$INST_MKDIR";; esac
101
102# Allow the user to over-ride xx
103case "$inst_dest" in ?*) BIN_DIRECTORY="$inst_dest";; esac
104case "$inst_conf" in ?*) CONFIGURE_FILE="$inst_conf";; esac
105case "$inst_info" in ?*) INFO_DIRECTORY="$inst_info";; esac
106case "$inst_aliases" in ?*) SYSTEM_ALIASES_FILE="$inst_aliases";; esac
107
108# Insert ${DESTDIR} at the start of all paths so that the whole thing can be
109# installed under a different file root. For backwards compatibility, use
110# ${ROOT} if ${DESTDIR} is not set. However, we need to save the value of
111# the real system aliases file, and use that in the default configuration.
112
113ACTUAL_SYSTEM_ALIASES_FILE=${SYSTEM_ALIASES_FILE}
114DESTDIR=${DESTDIR:-${ROOT}}
115
116BIN_DIRECTORY=${DESTDIR}${BIN_DIRECTORY}
117CONFIGURE_FILE=${DESTDIR}${CONFIGURE_FILE}
118SYSTEM_ALIASES_FILE=${DESTDIR}${SYSTEM_ALIASES_FILE}
119
120if [ "${INFO_DIRECTORY}" != "" ] ; then
121 INFO_DIRECTORY=${DESTDIR}${INFO_DIRECTORY}
122fi
123
124# Overrides of other things
125case "$inst_uid" in ?*) INST_UID="$inst_uid";; esac
126case "$inst_cp" in ?*) CP="$inst_cp";; esac
127case "$inst_mv" in ?*) MV="$inst_mv";; esac
128case "$inst_ln" in ?*) LN="$inst_ln";; esac
129case "$inst_chown" in ?*) CHOWN="$inst_chown";; esac
130case "$inst_chmod" in ?*) CHMOD="$inst_chmod";; esac
131case "$inst_dirname" in ?*) DIRNAME="$inst_dirname";; esac
132case "$inst_mkdir" in ?*) MKDIR="$inst_mkdir";; esac
133
134# chown is a special case; in at least one OS it is in /usr/etc instead
135# of in /usr/bin, and therefore not likely to be on the path. Another OS
136# has it in /usr/sbin. This fudge tries to cope with these variations.
137
138# Otherwise, and for other commands, we assume that the normal PATH will
139# give access to where they are on your operating system (normally /usr/bin
140# or /bin).
141
142if [ "${CHOWN}" = "chown" -a -x /usr/sbin/chown ] ; then
143 CHOWN=/usr/sbin/chown
144fi
145
146if [ "${CHOWN}" = "chown" -a ! -f /usr/bin/chown -a -f /usr/etc/chown ] ; then
147 CHOWN=/usr/etc/chown
148fi
149
14487e4c
PH
150# The values of CHOWN and MV taken from the Makefile are sometimes set to
151# "look_for_it", which causes a search of the usual suspects. This code is
152# similar to that in exicyclog, but has to be fudged for upper/lower case
153# distinctions.
154
155for cmd in CHOWN MV ; do
156 eval "oldcmd=\$$cmd"
157 if [ "$oldcmd" != "look_for_it" ] ; then continue ; fi
158 if [ "$cmd" = "CHOWN" ] ; then cmdlc="chown" ; fi
159 if [ "$cmd" = "MV" ] ; then cmdlc="mv" ; fi
160 newcmd=$cmdlc
161 for dir in /bin /usr/bin /usr/sbin /usr/etc ; do
162 if [ -f $dir/$cmdlc ] ; then
163 newcmd=$dir/$cmdlc
164 break
165 fi
166 done
167 eval $cmd=$newcmd
168done
169
61ec970d
PH
170# See if the exim monitor has been built
171
172if [ -f eximon -a -f eximon.bin ]; then
173 exim_monitor="eximon eximon.bin"
174fi
175
176# If bin directory doesn't exist, try to create it
177
178if [ ! -d "${BIN_DIRECTORY}" ]; then
179 echo mkdir -p ${BIN_DIRECTORY}
180 ${real} mkdir -p ${BIN_DIRECTORY}
181 if [ $? -ne 0 ]; then
182 echo $com ""
183 echo $com "*** Exim installation ${ver}failed ***"
184 exit 1
185 else
186 ${real} echo $com ${BIN_DIRECTORY} created
187 fi
188fi
189
190# If no arguments, install everything
191
192if [ $# -gt 0 ]; then
193 set $@
194else
195 set exim${EXE} ${exim_monitor} exim_dumpdb${EXE} exim_fixdb${EXE} \
196 exim_tidydb${EXE} exinext exiwhat exim_dbmbuild${EXE} exicyclog \
197 exigrep eximstats exipick exiqgrep exiqsumm exim_lock${EXE} \
198 exim_checkaccess
199fi
200
201echo $com ""
202echo $com Installation directory is ${BIN_DIRECTORY}
203echo $com ""
204
205while [ $# -gt 0 ]; do
206 name=$1
207 shift
208
209 if [ ! -s ${name} ]; then
210 echo $com ""
211 echo $com "*** `pwd`/${name} does not exist or is empty"
212 echo $com "*** Have you built Exim successfully?"
213 echo $com "*** Exim installation ${ver}failed ***"
214 exit 1
215 fi
216
217 # The exim binary is handled specially
218
219 if [ $name = exim${EXE} ]; then
220 version=exim-`./exim -bV -C /dev/null | \
221 awk '/Exim version/ { OFS=""; print $3,"-",substr($4,2,length($4)-1) }'`${EXE}
222
223 if [ "${version}" = "exim-${EXE}" ]; then
224 echo $com ""
225 echo $com "*** Could not run ./exim to find version number ***"
226 echo $com "*** Exim installation ${ver}failed ***"
227 exit 1
228 fi
229
230 # Do something only if newer than existing file, or no existing file
231
232 if ../scripts/newer ${name} ${BIN_DIRECTORY}/${version}; then
233 echo ${CP} ${name} ${BIN_DIRECTORY}/${version}
234 ${real} ${CP} ${name} ${BIN_DIRECTORY}/${version}
235 if [ $? -ne 0 ]; then
236 echo $com ""
237 echo $com "*** Exim installation ${ver}failed ***"
238 exit 1
239 fi
240
241 # After copy, set ownership and permissions, unless disabled
242
243 if [ "$do_chown" != "no" ]; then
244 echo ${CHOWN} ${INST_UID} ${BIN_DIRECTORY}/${version}
245 ${real} ${CHOWN} ${INST_UID} ${BIN_DIRECTORY}/${version}
246 if [ $? -ne 0 ]; then
247 echo $com ""
248 echo $com "*** You must be ${INST_UID} to install exim ***"
249 exit 1
250 fi
251 echo ${CHMOD} a+x ${BIN_DIRECTORY}/${version}
252 ${real} ${CHMOD} a+x ${BIN_DIRECTORY}/${version}
253 if [ $? -ne 0 ]; then
254 echo $com ""
255 echo $com "*** Exim installation ${ver}failed ***"
256 exit 1
257 fi
258 echo ${CHMOD} u+s ${BIN_DIRECTORY}/${version}
259 ${real} ${CHMOD} u+s ${BIN_DIRECTORY}/${version}
260 if [ $? -ne 0 ]; then
261 echo $com ""
262 echo $com "*** Exim installation ${ver}failed ***"
263 exit 1
264 fi
265 else
266 echo $com "$CHOWN $INST_UID omitted: -no_chown was specified"
267 echo $com "$CHMOD u+s omitted: -no_chown was specified"
268 fi
269
270 # Now sort out the "exim" alias, unless NO_SYMLINK is set.
271
272 if [ "X$NO_SYMLINK" = "X" ] && [ "$do_symlink" != "no" ] ; then
273
274 # First check whether "exim" exists in the directory.
275 if [ -f ${BIN_DIRECTORY}/exim ]; then
276
277 # If it's not a symbolic link, make a copy with the old version number
278 if [ `ls -l ${BIN_DIRECTORY}/exim | cut -c1-1` != 'l' ]; then
279 oldversion=exim-`${BIN_DIRECTORY}/exim -bV -C /dev/null | \
280 awk '/Exim version/ { OFS=""; print $3,"-",substr($4,2,length($4)-1) }'`${EXE}
281 if [ "${version}" = "${oldversion}" ] ; then
282 echo $com ""
283 echo $com "*** Existing file called exim has the same version and compile number ***"
284 echo $com "*** Exim installation ${ver}failed ***"
285 exit 1
286 fi
287 echo ${CP} ${BIN_DIRECTORY}/exim ${BIN_DIRECTORY}/${oldversion}
288 ${real} ${CP} ${BIN_DIRECTORY}/exim ${BIN_DIRECTORY}/${oldversion}
289 if [ $? -ne 0 ]; then
290 echo $com ""
291 echo $com "*** Exim installation ${ver}failed ***"
292 exit 1
293 fi
294 fi
295
296 # Now we can move the name "exim" to be a symbolic link to the new
297 # version, atomically.
298
299 echo \(cd ${BIN_DIRECTORY}\; ${LN} -s ${version} temporary_exim\)
300 (${real} cd ${BIN_DIRECTORY}; ${real} ${LN} -s ${version} temporary_exim)
301 if [ $? -ne 0 ]; then
302 echo $com ""
303 echo $com "*** Exim installation ${ver}failed ***"
304 exit 1
305 fi
306
307 echo ${MV} -f ${BIN_DIRECTORY}/temporary_exim ${BIN_DIRECTORY}/exim
308 ${real} ${MV} -f ${BIN_DIRECTORY}/temporary_exim ${BIN_DIRECTORY}/exim
309 if [ $? -ne 0 ]; then
310 echo $com ""
311 echo $com "*** Exim installation ${ver}failed ***"
312 exit 1
313 fi
314
315 # If "exim" does not already exist just create a symbolic link.
316
317 else
318 echo \(cd ${BIN_DIRECTORY}\; ${LN} -s ${version} exim\)
319 (${real} cd ${BIN_DIRECTORY}; ${real} ${LN} -s ${version} exim)
320 if [ $? -ne 0 ]; then
321 echo $com ""
322 echo $com "*** Exim installation ${ver}failed ***"
323 exit 1
324 fi
325 fi
326
327 else
328 echo $com "creation of symlink omitted"
329 if [ "X$NO_SYMLINK" != "X" ] ; then
330 echo $com "(NO_SYMLINK is specified in Local/Makefile)"
331 else
332 echo $com "(-no_symlink was specified)"
333 fi
334 fi
335
336 # New binary is not newer than the installed file
337
338 else
339 echo $com ${name} is not newer than ${BIN_DIRECTORY}/${version}
340 fi
341
342 # Handle everything other than the exim binary itself
343
344 else
345 if ../scripts/newer ${name} ${BIN_DIRECTORY}/${name}; then
346 if [ -f ${BIN_DIRECTORY}/${name} ]; then
347 echo ${CP} ${BIN_DIRECTORY}/${name} ${BIN_DIRECTORY}/${name}.O
348 ${real} ${CP} ${BIN_DIRECTORY}/${name} ${BIN_DIRECTORY}/${name}.O
349 if [ $? -ne 0 ]; then
350 echo $com ""
351 echo $com "*** Exim installation ${ver}failed ***"
352 exit 1
353 fi
354 fi
355 echo ${CP} ${name} ${BIN_DIRECTORY}
356 ${real} ${CP} ${name} ${BIN_DIRECTORY}
357 if [ $? -ne 0 ]; then
358 echo $com ""
359 echo $com "*** Exim installation ${ver}failed ***"
360 exit 1
361 fi
362 else
363 echo $com ${name} is not newer than ${BIN_DIRECTORY}/${name}
364 fi
365 fi
366
367done
368
369
370
371# If there is no configuration file, install the default, modifying it to refer
372# to the configured system aliases file. If there is no setting for
373# SYSTEM_ALIASES_FILE, use the traditional /etc/aliases. If the file does not
374# exist, install a default (dummy) for that too.
375
376# However, if CONFIGURE_FILE specifies a list of files, skip this code.
377
378echo $com ""
379
17792b53 380if [ `expr -- "${CONFIGURE_FILE}" : ".*:"` -ne 0 ] ; then
61ec970d
PH
381 echo $com Runtime configuration is specified as the following list:
382 echo $com ' ' ${CONFIGURE_FILE}
383 echo $com Therefore, skipping automatic installation.
384
385elif [ ! -f ${CONFIGURE_FILE} ]; then
386 echo $com Installing default configuration in ${CONFIGURE_FILE}
387 echo $com because there is no existing configuration file.
388 if [ "${SYSTEM_ALIASES_FILE}" = "" ] ; then
389 SYSTEM_ALIASES_FILE=/etc/aliases
390 echo $com This configuration has system aliases in ${SYSTEM_ALIASES_FILE}.
391 fi
392
393 echo ${MKDIR} -p `${DIRNAME} ${CONFIGURE_FILE}`
394 ${real} ${MKDIR} -p `${DIRNAME} ${CONFIGURE_FILE}`
395
396 echo sed -e '\\'
397 echo " \"/SYSTEM_ALIASES_FILE/ s'SYSTEM_ALIASES_FILE'${ACTUAL_SYSTEM_ALIASES_FILE}'\"" '\\'
398 echo " ../src/configure.default > \${CONFIGURE_FILE}"
399
400 # I can't find a way of writing this using the ${real} feature because
401 # it seems that the output redirection always happens, even when -n was
402 # specified. So control it the hard way.
403
404 if [ "$real" = "" ] ; then
405 sed -e \
406 "/SYSTEM_ALIASES_FILE/ s'SYSTEM_ALIASES_FILE'${ACTUAL_SYSTEM_ALIASES_FILE}'" \
407 ../src/configure.default > ${CONFIGURE_FILE}
408 else
409 true
410 fi
411
412 if [ $? -ne 0 ]; then
413 echo $com ""
414 echo $com "*** Exim installation ${ver}failed ***"
415 exit 1
416 fi
417 if [ ! -f ${SYSTEM_ALIASES_FILE} ]; then
418 echo $com '****'
419 echo $com Installing a dummy ${SYSTEM_ALIASES_FILE} file because you do not have
420 echo $com one, and the default configuration requires it. You should
421 echo $com edit ${SYSTEM_ALIASES_FILE} and at least create an alias for postmaster.
422 echo $com '***'
423 echo ${CP} ../src/aliases.default ${SYSTEM_ALIASES_FILE}
424 ${real} ${CP} ../src/aliases.default ${SYSTEM_ALIASES_FILE}
425 fi
426
427else
428 echo $com Configuration file ${CONFIGURE_FILE} already exists
429fi
430
431# Install info files if the directory is defined and the Texinfo
432# source documentation is present.
433
434if [ "${INFO_DIRECTORY}" != "" -a -f ../doc/spec.texinfo ] ; then
435 echo $com ""
436 if [ ! -d "${INFO_DIRECTORY}" ] ; then
437 echo mkdir -p ${INFO_DIRECTORY}
438 ${real} mkdir -p ${INFO_DIRECTORY}
439 if [ $? -ne 0 ]; then
440 echo $com ""
441 echo $com "*** Exim installation ${ver}failed ***"
442 exit 1
443 else
444 echo $com ${INFO_DIRECTORY} created
445 fi
446 fi
447
448 echo $com Info installation directory is ${INFO_DIRECTORY}
449 echo $com ""
450
451 ${real} makeinfo --no-split --output exim.info ../doc/spec.texinfo
452 echo ${CP} exim.info ${INFO_DIRECTORY}
453 ${real} ${CP} exim.info ${INFO_DIRECTORY}
454 ${real} install-info --section="Exim" \
455 --entry "* User guide: (exim). Exim manual" \
456 ${INFO_DIRECTORY}/exim.info ${INFO_DIRECTORY}/dir
457 ${real} makeinfo --no-split --output exim_filter.info ../doc/filter.texinfo
458 echo ${CP} exim_filter.info ${INFO_DIRECTORY}
459 ${real} ${CP} exim_filter.info ${INFO_DIRECTORY}
460 ${real} install-info --section="Exim" \
461 --entry "* Filtering: (exim_filter). Filtering mail with Exim" \
462 ${INFO_DIRECTORY}/exim_filter.info ${INFO_DIRECTORY}/dir
463fi
464
465# Everything OK
466
467echo $com ""
468echo $com Exim installation ${ver}complete
469
470# End of exim_install