2 # update-exim4.conf(8) - Generate /var/lib/exim4/config.autogenerated
8 UPEX4C_confdir
="/etc/exim4"
9 UPEX4C_sections
="main acl router transport retry rewrite auth"
11 # list of ue4cc options that need to support both colons and
12 # semicolons as separators. dc_other_hostnames and dc_smarthost
13 # has special handling.
14 UPEX4C_semicolon
="dc_local_interfaces dc_relay_nets dc_relay_domains"
15 EXIM
="/usr/sbin/exim4"
18 UPEX4C_autoconfigfile
=/var
/lib
/exim
4/config.autogenerated
19 UPEX4C_outputfile
="${UPEX4C_autoconfigfile}"
24 $0 - Generate exim4 configuration files
26 -v|--verbose - Enable verbose mode, tell about ignored files
27 -h|--help - Show this message
28 --keepcomments - Do not remove comment lines
29 --removecomments - Remove comment lines
30 -o|--output file - write output to file instead of ${UPEX4C_outputfile}
31 -d|--confdir directory - read input from given directory instead of ${UPEX4C_confdir}
32 --check - Test generated file for validity and remove it again.
37 TEMP
=$
(getopt
-n update-exim4.conf \
38 -l check
,keepcomments
,removecomments
,output
:,confdir
:,help,verbose
-- \
41 if test "$?" != 0; then
42 echo "Terminating..." >&2
47 while test "$1" != "--"; do
67 UPEX4C_outputfile
="$1"
78 # No non-option arguments allowed.
79 if [ "$#" -ne 0 ]; then
80 echo "No non option arguments ($@) allowed" >&2
85 # exit immediately if /etc/exim4/exim4.conf exists and -o was not specified
86 if [ -e /etc
/exim
4/exim4.conf
] && \
87 [ "${UPEX4C_outputfile}" = "${UPEX4C_autoconfigfile}" ] ; then
91 UE4CC
="$UPEX4C_confdir/update-exim4.conf.conf"
92 UPEX4C_confd
="$UPEX4C_confdir/conf.d"
94 [ -d "$(dirname "$UPEX4C_outputfile")" ] || \
95 { printf "$0: Error, missing $(dirname "$UPEX4C_outputfile"), exiting.\n" 1>&2 ; exit 1 ; }
97 if [ -f "$UE4CC" ]; then
100 echo >&2 "$0: Error, no $UE4CC, exiting."
105 UPEX4C_autoconfigfile
=/var
/lib
/exim
4/config.autogenerated
106 if [ "$(dirname ${UPEX4C_outputfile})" = "/var/lib/exim4" ] ; then
107 UPEX4C_tmp
="${UPEX4C_outputfile}.tmp"
109 UPEX4C_tmp
="$(tempfile -m600 -p ex4)"
117 echo "$*" | lowerpipe
122 # Use "abcdef... instead of a a-z or [:alnum:] here since the alternatives
123 # will also match non-ascii characters.
124 OUT
="$(echo $IN | sed 's/[^-0-9ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\/\.!*@_~:;< \[\]]/_/g')"
125 if [ "$OUT" != "$IN" ]; then
126 echo >&2 "$0: non-ascii value $IN read from $UE4CC, sanitizing to $OUT"
131 [ "${CFILEMODE}" = "" ] && CFILEMODE
=644
132 [ "${dc_use_split_config}" = "" ] && dc_use_split_config
='false'
133 [ "${dc_localdelivery}" = "" ] && dc_localdelivery
='mail_spool'
134 [ "${UPEX4C_comments:-}" = "" ] && UPEX4C_comments
="${ue4c_keepcomments:-no}"
136 TEMPLATEFILE
="${UPEX4C_confdir}/exim4.conf.template"
138 dc_use_split_config
="$(lowercase $dc_use_split_config)"
139 UPEX4C_verbose
="$(lowercase $UPEX4C_verbose)"
141 if [ "${dc_use_split_config}" = "true" ]; then
142 [ "${UPEX4C_verbose}" = "yes" ] && \
143 echo "using split configuration scheme from ${UPEX4C_confd}"
144 if ! [ -d "${UPEX4C_confd}" ]; then
145 printf >&2 "$0: Error, no ${UPEX4C_confd}, exiting.\n"
149 [ "${UPEX4C_verbose}" = "yes" ] && \
150 echo "using non-split configuration scheme from ${TEMPLATEFILE}"
153 # take only the first word from /etc/mailname
154 mailname
="$(< /etc/mailname sed -n 's/\([-[:alnum:]@\.]\+\).*/\1/;p;q' | lowerpipe | check_ascii_pipe)"
156 # barf if lookups are found. They have never been supported here.
157 if echo " ${dc_other_hostnames} ${dc_smarthost} ${dc_local_interfaces} ${dc_relay_nets} ${dc_relay_domains}"|
grep -q '[[:space:]]\(partial-\)\?\(cdb\|dbm\|dbmnz\|\(d\|ipl\|\(n\?wild\)\?l\)search\|nis\)\([\*@]\)\?[[:space:]]*;'; then
158 echo >&2 "WARNING: using 'lookup;' constructs in $UE4CC has never been supported! See /usr/share/doc/exim4-config/NEWS.Debian.gz for details."
161 dc_other_hostnames
="$(lowercase $dc_other_hostnames | check_ascii_pipe)"
162 # add localhost, get rid of spaces, trailing (semi)colons and make the list
164 local_domains
="$(echo @:localhost:"${dc_other_hostnames}" | \
165 sed -e 's/[;: ]*$//' -e 's/ *//' -e 's/;/:/g')"
168 # run-parts emulation, stolen from Branden's /etc/X11/Xsession
169 # Addition: Use file.rul instead if file if it exists.
172 unset LANG LC_COLLATE LC_ALL
175 errormessage
"$0: internal run_parts called without an argument"
177 if [ ! -d "$1" ]; then
178 errormessage
"$0: internal run_parts called, but $1 does not exist or is not a directory."
180 for F
in $
(ls $1); do
181 if expr "$F" : '[[:alnum:]_-]\+$' > /dev
/null
2>&1; then
182 if [ -f "$1/$F" ] ; then
183 if [ -f "$1/${F}.rul" ] ; then
190 if [ "${UPEX4C_verbose}" = "yes" ] && \
192 ! expr "$F" : '[[:alnum:]_-]\+\.rul'> /dev
/null
2>&1 ; then
194 "internal run-parts: ignoring file: $1/$F" 1>&2
201 # pretty-print messages of arbitrary length (no trailing newline)
202 echo "$*" |
fold -s -w ${COLUMNS:-80} >&2;
207 errormessage
"$0: internal cat_parts called without an argument"
209 if [ ! -d "$1" ]; then
210 errormessage
"$0: internal cat_parts called, but $1 does not exist or is not a directory."
212 for file in $
(run_parts
$1); do
213 echo "#####################################################"
215 echo "#####################################################"
218 echo "#####################################################"
220 echo "#####################################################"
225 rm -f "${UPEX4C_tmp}"
226 touch "${UPEX4C_tmp}"
227 # this can be removed by the end of 2007
228 #chown --reference=${TEMPLATEFILE} \
229 # ${UPEX4C_tmp} ${UPEX4C_outputfile}
230 #chmod --reference=${TEMPLATEFILE} \
231 # ${UPEX4C_tmp} ${UPEX4C_outputfile}
232 if [ "$(id -u)" = "0" ]; then
233 chown root
:Debian-exim
"${UPEX4C_tmp}"
234 [ -e "${UPEX4C_outputfile}" ] && \
235 chown root
:Debian-exim
"${UPEX4C_outputfile}"
237 chmod 640 "${UPEX4C_tmp}"
238 if [ -e "${UPEX4C_outputfile}" ]; then
239 chmod 640 "${UPEX4C_outputfile}"
244 if [ "${UPEX4C_comments}" = "no" ] ; then
245 grep -E -v '^[[:space:]]*#' |
sed -e '/^$/N;/\n$/D' ;
253 cat << EOF >> "${UPEX4C_tmp}"
255 # WARNING WARNING WARNING
256 # WARNING WARNING WARNING
257 # WARNING WARNING WARNING
258 # WARNING WARNING WARNING
259 # WARNING WARNING WARNING
260 # This file was generated dynamically from
263 if [ "${dc_use_split_config}" = "true" ] ; then
264 cat << EOF >> "${UPEX4C_tmp}"
265 # split config files in the $UPEX4C_confd/ directory.
268 cat << EOF >> "${UPEX4C_tmp}"
269 # non-split config ($UPEX4C_confdir/exim4.conf.localmacros
270 # and $UPEX4C_confdir/exim4.conf.template).
274 cat << EOF >> "${UPEX4C_tmp}"
275 # The config files are supplemented with package installation/configuration
276 # settings managed by debconf. This data is stored in
277 # $UPEX4C_confdir/update-exim4.conf.conf
278 # Any changes you make here will be lost.
279 # See /usr/share/doc/exim4-base/README.Debian.gz and update-exim4.conf(8)
280 # for instructions of customization.
281 # WARNING WARNING WARNING
282 # WARNING WARNING WARNING
283 # WARNING WARNING WARNING
284 # WARNING WARNING WARNING
285 # WARNING WARNING WARNING
289 # handle ";" in input values as separator change
291 for field
in $UPEX4C_semicolon; do
292 if eval echo \$
$field |
grep -q ";"; then
294 if ! echo $temp |
grep -q "^<"; then
296 eval "$field='$temp'"
301 # fix up smarthost line: change semicolons into single colons
302 dc_smarthost
="$(lowercase $dc_smarthost | check_ascii_pipe | sed 's/;/:/g')"
304 dc_relay_nets
="$(lowercase $dc_relay_nets | check_ascii_pipe)"
306 if echo "$dc_relay_nets" |
grep -q '^<;'; then
307 dc_relay_nets
="$dc_relay_nets ; 127.0.0.1 ; ::1"
309 dc_relay_nets
="$dc_relay_nets : 127.0.0.1 : ::::1"
312 dc_eximconfig_configtype
="$(lowercase $dc_eximconfig_configtype | check_ascii_pipe)"
313 dc_hide_mailname
="$(lowercase $dc_hide_mailname | check_ascii_pipe)"
314 dc_readhost
="$(lowercase $dc_readhost | check_ascii_pipe)"
315 case "$dc_eximconfig_configtype" in
317 if [ "${dc_hide_mailname}" = "true" ] && [ -n "${dc_readhost}" ] ; then
326 if [ "${dc_use_split_config}" = "true" ] ; then
327 for i
in ${UPEX4C_sections} ; do
328 cat_parts
"${UPEX4C_confd}/$i"
334 if [ -e "/etc/exim4/exim4.conf.localmacros" ]; then
335 LOCALMACROS
="/etc/exim4/exim4.conf.localmacros"
337 cat "${LOCALMACROS:-/dev/null}" "${TEMPLATEFILE:-/dev/null}" | \
341 mv -f "${UPEX4C_tmp}" "${UPEX4C_outputfile}"
342 chmod "${CFILEMODE}" "${UPEX4C_outputfile}"
343 [ "${UPEX4C_verbose}" = "yes" ] && \
344 echo "Not substituting variables since conftype is none (or other)"
349 UPEX4C_macros
="##############################################\n"
350 UPEX4C_macros
="${UPEX4C_macros}# the following macro definitions were created\n"
351 UPEX4C_macros
="${UPEX4C_macros}# dynamically by $0\n"
356 contents
="$(lowercase ${@} | check_ascii_pipe)"
357 printf "%s" ".ifndef $macroname\n$macroname=$contents\n.endif\n"
361 UPEX4C_macros
="${UPEX4C_macros}$(preprocess_macro "$1" "$2")"
367 sed -n '/^[[:upper:]]/p;' | \
368 grep -v '^CFILEMODE=' | \
370 errormessage
"undocumented line $line found in $1, generating exim macro"
371 left
="$(echo $line | sed 's/\([^=]*\).*/\1/')"
372 right
="$(echo $line | sed 's/[^=]*=\(.*\)/\1/')"
373 preprocess_macro
"$left" "$right"
377 if [ "${dc_local_interfaces}" != "" ] ; then
378 seed_macro
"MAIN_LOCAL_INTERFACES" "${dc_local_interfaces}"
381 if [ "${dc_minimaldns}" = "true" ] ; then
382 seed_macro
"DC_minimaldns" "1"
383 if guessed_name
="$(hostname --fqdn | lowerpipe | check_ascii_pipe | grep '\.')" ; then
384 seed_macro
"MAIN_HARDCODE_PRIMARY_HOSTNAME" "$guessed_name"
386 errormessage
"hostname --fqdn did not return a fully qualified name, dc_minimaldns will not work. Please fix your /etc/hosts setup."
390 if [ -n "${hide_mailname:-}" ]; then
391 seed_macro
"HIDE_MAILNAME" "${hide_mailname:-}"
393 seed_macro
"MAIN_PACKAGE_VERSION" "$UPEX4C_version"
394 seed_macro
"MAIN_LOCAL_DOMAINS" "${local_domains}"
395 seed_macro
"MAIN_RELAY_TO_DOMAINS" "${dc_relay_domains}"
396 seed_macro
"ETC_MAILNAME" "$mailname"
397 seed_macro
"LOCAL_DELIVERY" "${dc_localdelivery}"
398 seed_macro
"MAIN_RELAY_NETS" "${dc_relay_nets}"
399 seed_macro
"DCreadhost" "${dc_readhost}"
400 seed_macro
"DCsmarthost" "${dc_smarthost}"
401 seed_macro
"DC_eximconfig_configtype" "${dc_eximconfig_configtype}"
402 seed_macro
"DCconfig_${dc_eximconfig_configtype}" "1"
404 # dump everything starting with a capital into macros as well
405 # this is going to stay undocumented, but fixes PEBCAK where people write
408 UPEX4C_macros
="${UPEX4C_macros}$(file2macros $UE4CC)"
410 UPEX4C_macros
="${UPEX4C_macros}##############################################\n"
412 case "${dc_use_split_config}" in
414 for i
in ${UPEX4C_sections} ; do
415 echo "# begin processing $i #####"
416 cat_parts
"${UPEX4C_confd}/$i"
417 echo "# end of $i #####"
420 |
sed "s|^\(UPEX4CmacrosUPEX4C.*\)$|\1\n$UPEX4C_macros|" \
422 RELEVANTTEMPLATE
="$UPEX4C_confd"
425 if [ ! -r "$TEMPLATEFILE" ] ; then
426 echo "Error: Unsplit config selected and $TEMPLATEFILE missing ... exiting" 1>&2
430 if [ -e "/etc/exim4/exim4.conf.localmacros" ]; then
431 LOCALMACROS
="${UPEX4C_confdir}/exim4.conf.localmacros"
433 cat "${LOCALMACROS:-/dev/null}" "${TEMPLATEFILE:-/dev/null}" \
435 |
sed "s|^\(UPEX4CmacrosUPEX4C.*\)$|\1\n$UPEX4C_macros|" \
437 RELEVANTTEMPLATE
="$TEMPLATEFILE"
440 errormessage
"Invalid value for dc_use_split_config: \"${dc_use_split_config}\", exiting."
441 rm -f "${UPEX4C_tmp}"
446 # check for left-over DEBCONF strings that may cause installation trouble
447 # (fix PEBCAK for people who don't accept conffile changes and don't
449 if grep -qr '^[^#]*DEBCONF[[:lower:]_]\+DEBCONF' $RELEVANTTEMPLATE \
450 && ! grep -qr '^[[:space:]]*DEBCONFstringOK_config_adapted[[:space:]]*=' $RELEVANTTEMPLATE; then
451 errormessage
"DEBCONFsomethingDEBCONF found in exim configuration. This is most probably caused by you upgrading to exim4 4.67-3 or later without accepting the suggested conffile changes. Please read /usr/share/doc/exim4-config/NEWS.Debian.gz for 4.67-2 and 4.67-4"
454 # check for left-over UPEX4CmacrosUPEX4C comment string that may cause
455 # installation trouble (fix PEBCAK for people who don't accept conffile
456 # changes and don't read docs)
457 if grep -qr '# UPEX4CmacrosUPEX4C' $RELEVANTTEMPLATE \
458 && ! grep -qr '^[[:space:]]*UPEX4CmacrosOK_config_adapted[[:space:]]*=' $RELEVANTTEMPLATE; then
459 errormessage
"UPEX4CmacrosUPEX4C found in an exim configuration comment. This is most probably caused by you upgrading to exim4 4.67-5 or later without accepting the suggested conffile changes. Please read /usr/share/doc/exim4-config/NEWS.Debian.gz for 4.67-5"
463 # test validity if called without -o or if --check was supplied
464 if [ "${UPEX4C_outputfile}" = "${UPEX4C_autoconfigfile}" ] || \
465 [ "x${UPEX4C_check}" = "xyes" ]; then
466 if [ -x "${EXIM}" ] ; then
467 if ! "${EXIM}" -C "${UPEX4C_tmp}" -bV > /dev
/null
; then
468 # we have an error in the configuration file. Do not install
469 # and activate. However, errors in string expansions inside
470 # the configuration file are not detected by this check!
471 errormessage
"Invalid new configfile ${UPEX4C_tmp}, not installing ${UPEX4C_tmp} to ${UPEX4C_outputfile}"
476 if [ "x${UPEX4C_check}" = "xyes" ]; then
477 rm -f "${UPEX4C_tmp}"
481 mv -f "${UPEX4C_tmp}" "${UPEX4C_outputfile}"
482 chmod "${CFILEMODE}" "${UPEX4C_outputfile}"