X-Git-Url: http://git.hcoop.net/hcoop/debian/exim4.git/blobdiff_plain/493d55f6840d04ef186778724fc67530b1600113..01e60269815612fced0df2994079cb2081f8ff0b:/debian/debconf/update-exim4.conf diff --git a/debian/debconf/update-exim4.conf b/debian/debconf/update-exim4.conf index fac2d9c..084af7f 100644 --- a/debian/debconf/update-exim4.conf +++ b/debian/debconf/update-exim4.conf @@ -29,12 +29,13 @@ $0 - Generate exim4 configuration files --removecomments - Remove comment lines -o|--output file - write output to file instead of ${UPEX4C_outputfile} -d|--confdir directory - read input from given directory instead of ${UPEX4C_confdir} + --check - Test generated file for validity and remove it again. EOF } ## Parse commandline TEMP=$(getopt -n update-exim4.conf \ - -l keepcomments,removecomments,output:,confdir:,help,verbose -- \ + -l check,keepcomments,removecomments,output:,confdir:,help,verbose -- \ +o:d:vh "$@") if test "$?" != 0; then @@ -58,6 +59,9 @@ while test "$1" != "--"; do --removecomments) UPEX4C_comments=no ;; + --check) + UPEX4C_check=yes + ;; -o|--output) shift UPEX4C_outputfile="$1" @@ -97,6 +101,14 @@ else exit 1 fi + +UPEX4C_autoconfigfile=/var/lib/exim4/config.autogenerated +if [ "$(dirname ${UPEX4C_outputfile})" = "/var/lib/exim4" ] ; then + UPEX4C_tmp="${UPEX4C_outputfile}.tmp" +else + UPEX4C_tmp="$(tempfile -m600 -p ex4)" +fi + lowerpipe() { tr 'A-Z' 'a-z' } @@ -152,9 +164,6 @@ dc_other_hostnames="$(lowercase $dc_other_hostnames | check_ascii_pipe)" local_domains="$(echo @:localhost:"${dc_other_hostnames}" | \ sed -e 's/[;: ]*$//' -e 's/ *//' -e 's/;/:/g')" -UPEX4C_internal_tmp="$(tempfile -m600 -p ex4)" - -trap "rm -f ${UPEX4C_internal_tmp}" EXIT INT TERM # run-parts emulation, stolen from Branden's /etc/X11/Xsession # Addition: Use file.rul instead if file if it exists. @@ -213,19 +222,19 @@ cat_parts() { } gentmpconf() { - rm -f "${UPEX4C_outputfile}.tmp" - touch "${UPEX4C_outputfile}.tmp" + rm -f "${UPEX4C_tmp}" + touch "${UPEX4C_tmp}" # this can be removed by the end of 2007 #chown --reference=${TEMPLATEFILE} \ - # ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile} + # ${UPEX4C_tmp} ${UPEX4C_outputfile} #chmod --reference=${TEMPLATEFILE} \ - # ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile} + # ${UPEX4C_tmp} ${UPEX4C_outputfile} if [ "$(id -u)" = "0" ]; then - chown root:Debian-exim "${UPEX4C_outputfile}.tmp" + chown root:Debian-exim "${UPEX4C_tmp}" [ -e "${UPEX4C_outputfile}" ] && \ chown root:Debian-exim "${UPEX4C_outputfile}" fi - chmod 640 "${UPEX4C_outputfile}.tmp" + chmod 640 "${UPEX4C_tmp}" if [ -e "${UPEX4C_outputfile}" ]; then chmod 640 "${UPEX4C_outputfile}" fi @@ -241,7 +250,7 @@ removecomments(){ gentmpconf -cat << EOF >> "${UPEX4C_outputfile}.tmp" +cat << EOF >> "${UPEX4C_tmp}" ######### # WARNING WARNING WARNING # WARNING WARNING WARNING @@ -252,17 +261,17 @@ cat << EOF >> "${UPEX4C_outputfile}.tmp" EOF if [ "${dc_use_split_config}" = "true" ] ; then -cat << EOF >> "${UPEX4C_outputfile}.tmp" +cat << EOF >> "${UPEX4C_tmp}" # split config files in the $UPEX4C_confd/ directory. EOF else -cat << EOF >> "${UPEX4C_outputfile}.tmp" +cat << EOF >> "${UPEX4C_tmp}" # non-split config ($UPEX4C_confdir/exim4.conf.localmacros # and $UPEX4C_confdir/exim4.conf.template). EOF fi -cat << EOF >> "${UPEX4C_outputfile}.tmp" +cat << EOF >> "${UPEX4C_tmp}" # The config files are supplemented with package installation/configuration # settings managed by debconf. This data is stored in # $UPEX4C_confdir/update-exim4.conf.conf @@ -319,7 +328,7 @@ case "$dc_eximconfig_configtype" in cat_parts "${UPEX4C_confd}/$i" done | \ removecomments \ - >> "${UPEX4C_outputfile}.tmp" + >> "${UPEX4C_tmp}" else LOCALMACROS="" if [ -e "/etc/exim4/exim4.conf.localmacros" ]; then @@ -327,9 +336,9 @@ case "$dc_eximconfig_configtype" in fi cat "${LOCALMACROS:-/dev/null}" "${TEMPLATEFILE:-/dev/null}" | \ removecomments \ - >> "${UPEX4C_outputfile}.tmp" + >> "${UPEX4C_tmp}" fi - mv -f "${UPEX4C_outputfile}.tmp" "${UPEX4C_outputfile}" + mv -f "${UPEX4C_tmp}" "${UPEX4C_outputfile}" chmod "${CFILEMODE}" "${UPEX4C_outputfile}" [ "${UPEX4C_verbose}" = "yes" ] && \ echo "Not substituting variables since conftype is none (or other)" @@ -344,7 +353,7 @@ UPEX4C_macros="${UPEX4C_macros}# dynamically by $0\n" preprocess_macro() { macroname="${1:-}" shift - contents="$(lowercase ${@:-empty} | check_ascii_pipe)" + contents="$(lowercase ${@} | check_ascii_pipe)" printf "%s" ".ifndef $macroname\n$macroname=$contents\n.endif\n" } @@ -409,7 +418,7 @@ true) done \ | removecomments \ | sed "s|^\(UPEX4CmacrosUPEX4C.*\)$|\1\n$UPEX4C_macros|" \ - >> "${UPEX4C_outputfile}.tmp" + >> "${UPEX4C_tmp}" RELEVANTTEMPLATE="$UPEX4C_confd" ;; false) @@ -424,12 +433,12 @@ false) cat "${LOCALMACROS:-/dev/null}" "${TEMPLATEFILE:-/dev/null}" \ | removecomments \ | sed "s|^\(UPEX4CmacrosUPEX4C.*\)$|\1\n$UPEX4C_macros|" \ - >> "${UPEX4C_outputfile}.tmp" + >> "${UPEX4C_tmp}" RELEVANTTEMPLATE="$TEMPLATEFILE" ;; *) errormessage "Invalid value for dc_use_split_config: \"${dc_use_split_config}\", exiting." - rm -f "${UPEX4C_outputfile}.tmp" + rm -f "${UPEX4C_tmp}" exit 1 ;; esac @@ -451,19 +460,25 @@ if grep -qr '# UPEX4CmacrosUPEX4C' $RELEVANTTEMPLATE \ fi -# test validity if called without -o -if [ "${UPEX4C_outputfile}" = "${UPEX4C_autoconfigfile}" ] && \ - [ -x "${EXIM}" ] ; then - if ! "${EXIM}" -C "${UPEX4C_outputfile}.tmp" -bV > /dev/null ; then - # we have an error in the configuration file. Do not install - # and activate. However, errors in string expansions inside - # the configuration file are not detected by this check! - errormessage "Invalid new configfile ${UPEX4C_outputfile}.tmp, not installing ${UPEX4C_outputfile}.tmp to ${UPEX4C_outputfile}" - exit 1 +# test validity if called without -o or if --check was supplied +if [ "${UPEX4C_outputfile}" = "${UPEX4C_autoconfigfile}" ] || \ + [ "x${UPEX4C_check}" = "xyes" ]; then + if [ -x "${EXIM}" ] ; then + if ! "${EXIM}" -C "${UPEX4C_tmp}" -bV > /dev/null ; then + # we have an error in the configuration file. Do not install + # and activate. However, errors in string expansions inside + # the configuration file are not detected by this check! + errormessage "Invalid new configfile ${UPEX4C_tmp}, not installing ${UPEX4C_tmp} to ${UPEX4C_outputfile}" + exit 1 + fi fi fi +if [ "x${UPEX4C_check}" = "xyes" ]; then + rm -f "${UPEX4C_tmp}" + exit 0 +fi -mv -f "${UPEX4C_outputfile}.tmp" "${UPEX4C_outputfile}" +mv -f "${UPEX4C_tmp}" "${UPEX4C_outputfile}" chmod "${CFILEMODE}" "${UPEX4C_outputfile}" # end of file