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}
36 TEMP
=$
(getopt
-n update-exim4.conf \
37 -l keepcomments
,removecomments
,output
:,confdir
:,help,verbose
-- \
40 if test "$?" != 0; then
41 echo "Terminating..." >&2
46 while test "$1" != "--"; do
63 UPEX4C_outputfile
="$1"
74 # No non-option arguments allowed.
75 if [ "$#" -ne 0 ]; then
76 echo "No non option arguments ($@) allowed" >&2
81 # exit immediately if /etc/exim4/exim4.conf exists and -o was not specified
82 if [ -e /etc
/exim
4/exim4.conf
] && \
83 [ "${UPEX4C_outputfile}" = "${UPEX4C_autoconfigfile}" ] ; then
87 UE4CC
="$UPEX4C_confdir/update-exim4.conf.conf"
88 UPEX4C_confd
="$UPEX4C_confdir/conf.d"
90 [ -d "$(dirname "$UPEX4C_outputfile")" ] || \
91 { printf "$0: Error, missing $(dirname "$UPEX4C_outputfile"), exiting.\n" 1>&2 ; exit 1 ; }
93 if [ -f "$UE4CC" ]; then
96 echo >&2 "$0: Error, no $UE4CC, exiting."
105 echo "$*" | lowerpipe
110 # Use "abcdef... instead of a a-z or [:alnum:] here since the alternatives
111 # will also match non-ascii characters.
112 OUT
="$(echo $IN | sed 's/[^-0-9ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\/\.!*@_~:;< \[\]]/_/g')"
113 if [ "$OUT" != "$IN" ]; then
114 echo >&2 "$0: non-ascii value $IN read from $UE4CC, sanitizing to $OUT"
119 [ "${CFILEMODE}" = "" ] && CFILEMODE
=644
120 [ "${dc_use_split_config}" = "" ] && dc_use_split_config
='false'
121 [ "${dc_localdelivery}" = "" ] && dc_localdelivery
='mail_spool'
122 [ "${UPEX4C_comments:-}" = "" ] && UPEX4C_comments
="${ue4c_keepcomments:-no}"
124 TEMPLATEFILE
="${UPEX4C_confdir}/exim4.conf.template"
126 dc_use_split_config
="$(lowercase $dc_use_split_config)"
127 UPEX4C_verbose
="$(lowercase $UPEX4C_verbose)"
129 if [ "${dc_use_split_config}" = "true" ]; then
130 [ "${UPEX4C_verbose}" = "yes" ] && \
131 echo "using split configuration scheme from ${UPEX4C_confd}"
132 if ! [ -d "${UPEX4C_confd}" ]; then
133 printf >&2 "$0: Error, no ${UPEX4C_confd}, exiting.\n"
137 [ "${UPEX4C_verbose}" = "yes" ] && \
138 echo "using non-split configuration scheme from ${TEMPLATEFILE}"
141 # take only the first word from /etc/mailname
142 mailname
="$(< /etc/mailname sed -n 's/\([-[:alnum:]@\.]\+\).*/\1/;p;q' | lowerpipe | check_ascii_pipe)"
144 # barf if lookups are found. They have never been supported here.
145 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
146 echo >&2 "WARNING: using 'lookup;' constructs in $UE4CC has never been supported! See /usr/share/doc/exim4-config/NEWS.Debian.gz for details."
149 dc_other_hostnames
="$(lowercase $dc_other_hostnames | check_ascii_pipe)"
150 # add localhost, get rid of spaces, trailing (semi)colons and make the list
152 local_domains
="$(echo @:localhost:"${dc_other_hostnames}" | \
153 sed -e 's/[;: ]*$//' -e 's/ *//' -e 's/;/:/g')"
155 UPEX4C_internal_tmp
="$(tempfile -m600 -p ex4)"
157 trap "rm -f ${UPEX4C_internal_tmp}" EXIT INT TERM
159 # run-parts emulation, stolen from Branden's /etc/X11/Xsession
160 # Addition: Use file.rul instead if file if it exists.
163 unset LANG LC_COLLATE LC_ALL
166 errormessage
"$0: internal run_parts called without an argument"
168 if [ ! -d "$1" ]; then
169 errormessage
"$0: internal run_parts called, but $1 does not exist or is not a directory."
171 for F
in $
(ls $1); do
172 if expr "$F" : '[[:alnum:]_-]\+$' > /dev
/null
2>&1; then
173 if [ -f "$1/$F" ] ; then
174 if [ -f "$1/${F}.rul" ] ; then
181 if [ "${UPEX4C_verbose}" = "yes" ] && \
183 ! expr "$F" : '[[:alnum:]_-]\+\.rul'> /dev
/null
2>&1 ; then
185 "internal run-parts: ignoring file: $1/$F" 1>&2
192 # pretty-print messages of arbitrary length (no trailing newline)
193 echo "$*" |
fold -s -w ${COLUMNS:-80} >&2;
198 errormessage
"$0: internal cat_parts called without an argument"
200 if [ ! -d "$1" ]; then
201 errormessage
"$0: internal cat_parts called, but $1 does not exist or is not a directory."
203 for file in $
(run_parts
$1); do
204 echo "#####################################################"
206 echo "#####################################################"
209 echo "#####################################################"
211 echo "#####################################################"
216 rm -f "${UPEX4C_outputfile}.tmp"
217 touch "${UPEX4C_outputfile}.tmp"
218 # this can be removed by the end of 2007
219 #chown --reference=${TEMPLATEFILE} \
220 # ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile}
221 #chmod --reference=${TEMPLATEFILE} \
222 # ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile}
223 if [ "$(id -u)" = "0" ]; then
224 chown root
:Debian-exim
"${UPEX4C_outputfile}.tmp"
225 [ -e "${UPEX4C_outputfile}" ] && \
226 chown root
:Debian-exim
"${UPEX4C_outputfile}"
228 chmod 640 "${UPEX4C_outputfile}.tmp"
229 if [ -e "${UPEX4C_outputfile}" ]; then
230 chmod 640 "${UPEX4C_outputfile}"
235 if [ "${UPEX4C_comments}" = "no" ] ; then
236 grep -E -v '^[[:space:]]*#' |
sed -e '/^$/N;/\n$/D' ;
244 cat << EOF >> "${UPEX4C_outputfile}.tmp"
246 # WARNING WARNING WARNING
247 # WARNING WARNING WARNING
248 # WARNING WARNING WARNING
249 # WARNING WARNING WARNING
250 # WARNING WARNING WARNING
251 # This file was generated dynamically from
254 if [ "${dc_use_split_config}" = "true" ] ; then
255 cat << EOF >> "${UPEX4C_outputfile}.tmp"
256 # split config files in the $UPEX4C_confd/ directory.
259 cat << EOF >> "${UPEX4C_outputfile}.tmp"
260 # non-split config ($UPEX4C_confdir/exim4.conf.localmacros
261 # and $UPEX4C_confdir/exim4.conf.template).
265 cat << EOF >> "${UPEX4C_outputfile}.tmp"
266 # The config files are supplemented with package installation/configuration
267 # settings managed by debconf. This data is stored in
268 # $UPEX4C_confdir/update-exim4.conf.conf
269 # Any changes you make here will be lost.
270 # See /usr/share/doc/exim4-base/README.Debian.gz and update-exim4.conf(8)
271 # for instructions of customization.
272 # WARNING WARNING WARNING
273 # WARNING WARNING WARNING
274 # WARNING WARNING WARNING
275 # WARNING WARNING WARNING
276 # WARNING WARNING WARNING
280 # handle ";" in input values as separator change
282 for field
in $UPEX4C_semicolon; do
283 if eval echo \$
$field |
grep -q ";"; then
285 if ! echo $temp |
grep -q "^<"; then
287 eval "$field='$temp'"
292 # fix up smarthost line: change semicolons into single colons
293 dc_smarthost
="$(lowercase $dc_smarthost | check_ascii_pipe | sed 's/;/:/g')"
295 dc_relay_nets
="$(lowercase $dc_relay_nets | check_ascii_pipe)"
297 if echo "$dc_relay_nets" |
grep -q '^<;'; then
298 dc_relay_nets
="$dc_relay_nets ; 127.0.0.1 ; ::1"
300 dc_relay_nets
="$dc_relay_nets : 127.0.0.1 : ::::1"
303 dc_eximconfig_configtype
="$(lowercase $dc_eximconfig_configtype | check_ascii_pipe)"
304 dc_hide_mailname
="$(lowercase $dc_hide_mailname | check_ascii_pipe)"
305 dc_readhost
="$(lowercase $dc_readhost | check_ascii_pipe)"
306 case "$dc_eximconfig_configtype" in
308 if [ "${dc_hide_mailname}" = "true" ] && [ -n "${dc_readhost}" ] ; then
317 if [ "${dc_use_split_config}" = "true" ] ; then
318 for i
in ${UPEX4C_sections} ; do
319 cat_parts
"${UPEX4C_confd}/$i"
322 >> "${UPEX4C_outputfile}.tmp"
325 if [ -e "/etc/exim4/exim4.conf.localmacros" ]; then
326 LOCALMACROS
="/etc/exim4/exim4.conf.localmacros"
328 cat "${LOCALMACROS:-/dev/null}" "${TEMPLATEFILE:-/dev/null}" | \
330 >> "${UPEX4C_outputfile}.tmp"
332 mv -f "${UPEX4C_outputfile}.tmp" "${UPEX4C_outputfile}"
333 chmod "${CFILEMODE}" "${UPEX4C_outputfile}"
334 [ "${UPEX4C_verbose}" = "yes" ] && \
335 echo "Not substituting variables since conftype is none (or other)"
340 UPEX4C_macros
="##############################################\n"
341 UPEX4C_macros
="${UPEX4C_macros}# the following macro definitions were created\n"
342 UPEX4C_macros
="${UPEX4C_macros}# dynamically by $0\n"
347 contents
="$(lowercase ${@:-empty} | check_ascii_pipe)"
348 printf "%s" ".ifndef $macroname\n$macroname=$contents\n.endif\n"
352 UPEX4C_macros
="${UPEX4C_macros}$(preprocess_macro "$1" "$2")"
358 sed -n '/^[[:upper:]]/p;' | \
359 grep -v '^CFILEMODE=' | \
361 errormessage
"undocumented line $line found in $1, generating exim macro"
362 left
="$(echo $line | sed 's/\([^=]*\).*/\1/')"
363 right
="$(echo $line | sed 's/[^=]*=\(.*\)/\1/')"
364 preprocess_macro
"$left" "$right"
368 if [ "${dc_local_interfaces}" != "" ] ; then
369 seed_macro
"MAIN_LOCAL_INTERFACES" "${dc_local_interfaces}"
372 if [ "${dc_minimaldns}" = "true" ] ; then
373 seed_macro
"DC_minimaldns" "1"
374 if guessed_name
="$(hostname --fqdn | lowerpipe | check_ascii_pipe | grep '\.')" ; then
375 seed_macro
"MAIN_HARDCODE_PRIMARY_HOSTNAME" "$guessed_name"
377 errormessage
"hostname --fqdn did not return a fully qualified name, dc_minimaldns will not work. Please fix your /etc/hosts setup."
381 if [ -n "${hide_mailname:-}" ]; then
382 seed_macro
"HIDE_MAILNAME" "${hide_mailname:-}"
384 seed_macro
"MAIN_PACKAGE_VERSION" "$UPEX4C_version"
385 seed_macro
"MAIN_LOCAL_DOMAINS" "${local_domains}"
386 seed_macro
"MAIN_RELAY_TO_DOMAINS" "${dc_relay_domains}"
387 seed_macro
"ETC_MAILNAME" "$mailname"
388 seed_macro
"LOCAL_DELIVERY" "${dc_localdelivery}"
389 seed_macro
"MAIN_RELAY_NETS" "${dc_relay_nets}"
390 seed_macro
"DCreadhost" "${dc_readhost}"
391 seed_macro
"DCsmarthost" "${dc_smarthost}"
392 seed_macro
"DC_eximconfig_configtype" "${dc_eximconfig_configtype}"
393 seed_macro
"DCconfig_${dc_eximconfig_configtype}" "1"
395 # dump everything starting with a capital into macros as well
396 # this is going to stay undocumented, but fixes PEBCAK where people write
399 UPEX4C_macros
="${UPEX4C_macros}$(file2macros $UE4CC)"
401 UPEX4C_macros
="${UPEX4C_macros}##############################################\n"
403 case "${dc_use_split_config}" in
405 for i
in ${UPEX4C_sections} ; do
406 echo "# begin processing $i #####"
407 cat_parts
"${UPEX4C_confd}/$i"
408 echo "# end of $i #####"
411 |
sed "s|^\(UPEX4CmacrosUPEX4C.*\)$|\1\n$UPEX4C_macros|" \
412 >> "${UPEX4C_outputfile}.tmp"
413 RELEVANTTEMPLATE
="$UPEX4C_confd"
416 if [ ! -r "$TEMPLATEFILE" ] ; then
417 echo "Error: Unsplit config selected and $TEMPLATEFILE missing ... exiting" 1>&2
421 if [ -e "/etc/exim4/exim4.conf.localmacros" ]; then
422 LOCALMACROS
="${UPEX4C_confdir}/exim4.conf.localmacros"
424 cat "${LOCALMACROS:-/dev/null}" "${TEMPLATEFILE:-/dev/null}" \
426 |
sed "s|^\(UPEX4CmacrosUPEX4C.*\)$|\1\n$UPEX4C_macros|" \
427 >> "${UPEX4C_outputfile}.tmp"
428 RELEVANTTEMPLATE
="$TEMPLATEFILE"
431 errormessage
"Invalid value for dc_use_split_config: \"${dc_use_split_config}\", exiting."
432 rm -f "${UPEX4C_outputfile}.tmp"
437 # check for left-over DEBCONF strings that may cause installation trouble
438 # (fix PEBCAK for people who don't accept conffile changes and don't
440 if grep -qr '^[^#]*DEBCONF[[:lower:]_]\+DEBCONF' $RELEVANTTEMPLATE \
441 && ! grep -qr '^[[:space:]]*DEBCONFstringOK_config_adapted[[:space:]]*=' $RELEVANTTEMPLATE; then
442 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"
445 # check for left-over UPEX4CmacrosUPEX4C comment string that may cause
446 # installation trouble (fix PEBCAK for people who don't accept conffile
447 # changes and don't read docs)
448 if grep -qr '# UPEX4CmacrosUPEX4C' $RELEVANTTEMPLATE \
449 && ! grep -qr '^[[:space:]]*UPEX4CmacrosOK_config_adapted[[:space:]]*=' $RELEVANTTEMPLATE; then
450 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"
454 # test validity if called without -o
455 if [ "${UPEX4C_outputfile}" = "${UPEX4C_autoconfigfile}" ] && \
456 [ -x "${EXIM}" ] ; then
457 if ! "${EXIM}" -C "${UPEX4C_outputfile}.tmp" -bV > /dev
/null
; then
458 # we have an error in the configuration file. Do not install
459 # and activate. However, errors in string expansions inside
460 # the configuration file are not detected by this check!
461 errormessage
"Invalid new configfile ${UPEX4C_outputfile}.tmp, not installing ${UPEX4C_outputfile}.tmp to ${UPEX4C_outputfile}"
466 mv -f "${UPEX4C_outputfile}.tmp" "${UPEX4C_outputfile}"
467 chmod "${CFILEMODE}" "${UPEX4C_outputfile}"