Imported Debian patch 4.84-8
[hcoop/debian/exim4.git] / debian / debconf / update-exim4.conf.template
1 #!/bin/bash
2
3 set -e
4
5 CONFDIR="${CONFDIR:-/etc/exim4}"
6 DONOTRUN='true'
7
8 UPEX4CT_outputfile="${CONFDIR}/exim4.conf.template"
9
10 usage() {
11 cat <<EOF
12 $0 - Generate exim4 configuration file template
13 Options:
14 -n|--nobackup - Overwrite old template, do not take backup.
15 -o|--output file - write output to file instead of ${UPEX4CT_outputfile}
16 -h|--help - This message.
17 -r|--run - Actually do something
18 EOF
19 }
20
21 ## Parse commandline
22 TEMP=$(getopt -n update-exim4.conf.template \
23 -l nobackup,output:,help,run -- \
24 +no:hr "$@")
25
26 if test "$?" != 0; then
27 echo "Terminating..." >&2
28 exit 1
29 fi
30
31 eval set -- ${TEMP}
32 while test "$1" != "--"; do
33 case $1 in
34 -h|--help)
35 usage
36 exit 0
37 ;;
38 -o|--output)
39 shift
40 UPEX4CT_outputfile="$1"
41 ;;
42 -n|--nobackup)
43 NOBACKUP=1
44 ;;
45 -r|--run)
46 DONOTRUN='false'
47 ;;
48 esac
49 shift
50 done
51 shift
52
53 # No non-option arguments allowed.
54 if [ "$#" -ne 0 ]; then
55 echo "No non option arguments ($@) allowed" >&2
56 usage >&2
57 exit 1
58 fi
59
60 # run-parts emulation, stolen from Branden's /etc/X11/Xsession
61 # Addition: Use file.rul instead if file if it exists.
62 run_parts () {
63 # reset LC_COLLATE
64 unset LANG LC_COLLATE LC_ALL
65
66 if [ -z "$1" ]; then
67 errormessage "$0: internal run_parts called without an argument"
68 fi
69 if [ ! -d "$1" ]; then
70 errormessage "$0: internal run_parts called, but $1 does not exist or is not a directory."
71 fi
72 for F in $(ls $1 | grep -v /.svn); do
73 if expr "$F" : '[[:alnum:]_-]\+$' > /dev/null 2>&1; then
74 if [ -f "$1/$F" ] ; then
75 if [ -f "$1/${F}.rul" ] ; then
76 echo "$1/${F}.rul"
77 else
78 echo "$1/$F"
79 fi
80 fi
81 fi
82 done;
83 }
84 # also from Branden
85 errormessage () {
86 # pretty-print messages of arbitrary length (no trailing newline)
87 echo "$*" | fold -s -w ${COLUMNS:-80} >&2;
88 }
89
90 cat_parts() {
91 if [ -z "$1" ]; then
92 errormessage "$0: internal cat_parts called without an argument"
93 fi
94 if [ ! -d "$1" ]; then
95 errormessage "$0: internal cat_parts called, but $1 does not exist or is not a directory."
96 fi
97 for file in $(run_parts $1); do
98 echo "#####################################################"
99 echo "### $file"
100 echo "#####################################################"
101 cat $file
102 echo "#####################################################"
103 echo "### end $file"
104 echo "#####################################################"
105 done
106 }
107
108 if [ "$DONOTRUN" = "true" ]; then
109 errormessage "This program overwrites conffiles. Do not run unless you have consulted the manpage." >&2
110 echo "Terminating..." >&2
111 exit 1
112 fi
113
114
115 if [ -e "${UPEX4CT_outputfile}" ] && [ -z "$NOBACKUP" ]; then
116 if [ -e "${UPEX4CT_outputfile}.bak.$$" ]; then
117 echo >&2 "ERR: ${UPEX4CT_outputfile}.bak.$$ already exists, aborting"
118 exit 1
119 fi
120 fi
121
122 NEWTEMPLATE=$(tempfile -m644 -p ex4)
123 if [ -f "${UPEX4CT_outputfile}" ] ; then
124 chmod --reference="${UPEX4CT_outputfile}" "$NEWTEMPLATE"
125 fi
126
127 # generate .template. Ugly - better alternative?
128 SAVEWD="$(pwd)"
129 cd ${CONFDIR}/conf.d
130 for i in main acl router transport retry rewrite auth ; do
131 cat_parts $i
132 done > "$NEWTEMPLATE"
133 cd "$SAVEWD"
134
135 if [ -e "${UPEX4CT_outputfile}" ] && [ -z "$NOBACKUP" ] ; then
136 mv "${UPEX4CT_outputfile}" \
137 "${UPEX4CT_outputfile}.bak.$$"
138 fi
139 mv "$NEWTEMPLATE" "${UPEX4CT_outputfile}"