Commit | Line | Data |
---|---|---|
de45f55a AM |
1 | #!/bin/sh |
2 | # update-exim4defaults(8): manage entries in /etc/default/exim4 | |
3 | # per script | |
4 | ||
5 | if [ -n "$EX4DEBUG" ]; then | |
6 | echo "now debugging $0 $@" | |
7 | set -x | |
8 | fi | |
9 | ||
10 | unset LC_ALL | |
11 | export LC_CTYPE=C | |
12 | ||
13 | defaultfile=/etc/default/exim4 | |
14 | ||
15 | EX4DEF_INIT=false | |
16 | EX4DEF_FORCE=false | |
17 | ||
18 | ||
19 | if [ -r ${defaultfile} ]; then | |
20 | . ${defaultfile} | |
21 | fi | |
22 | ||
23 | ||
24 | # initialize variables | |
25 | EX4DEF_QUEUERUNNER="${QUEUERUNNER}" | |
26 | EX4DEF_QUEUEINTERVAL="${QUEUEINTERVAL}" | |
27 | EX4DEF_COMMONOPTIONS="${COMMONOPTIONS}" | |
28 | EX4DEF_QUEUERUNNEROPTIONS="${QUEUERUNNEROPTIONS}" | |
29 | EX4DEF_QFLAGS="${QFLAGS}" | |
30 | EX4DEF_SMTPLISTENEROPTIONS="${SMTPLISTENEROPTIONS}" | |
31 | ||
32 | EX4DEF_FLAGOPTIONS=false | |
33 | EX4DEF_FLAGREMOVE=false | |
34 | ||
35 | ex4def_usage () | |
36 | { | |
37 | echo "update-exim4defaults: manage entries in /etc/default/exim4" | |
38 | echo " usage: update-exim4defaults [[--queuerunner combined|separate|queueonly|ppp|no|nodaemon]" | |
39 | echo " [--qflags flags ] [--queuetime time] [--commonoptions options]" | |
40 | echo " [--queuerunneroptions options] [--smtplisteneroptions options]]" | |
41 | echo " [--remove-common options] [--remove-queue options]" | |
42 | echo " [--remove-smtp options]" | |
43 | echo " [--force|-f] [--help|-h]" | |
44 | echo " [--init]" | |
45 | } | |
46 | ||
47 | ||
48 | # used for initialzing and with --force. | |
49 | ex4def_write(){ | |
50 | EX4DEF_TMP="$(tempfile -m 600 -p ex4)" | |
51 | cat << EOF > "${EX4DEF_TMP}" | |
52 | # /etc/default/exim4 | |
53 | EX4DEF_VERSION='${EX4DEF_VERSION}' | |
54 | ||
55 | # 'combined' - one daemon running queue and listening on SMTP port | |
56 | # 'no' - no daemon running the queue | |
57 | # 'separate' - two separate daemons | |
58 | # 'ppp' - only run queue with /etc/ppp/ip-up.d/exim4. | |
59 | # 'nodaemon' - no daemon is started at all. | |
60 | # 'queueonly' - only a queue running daemon is started, no SMTP listener. | |
61 | # setting this to 'no' will also disable queueruns from /etc/ppp/ip-up.d/exim4 | |
62 | QUEUERUNNER='${EX4DEF_QUEUERUNNER}' | |
63 | # how often should we run the queue | |
64 | QUEUEINTERVAL='${EX4DEF_QUEUEINTERVAL}' | |
65 | # options common to quez-runner and listening daemon | |
66 | COMMONOPTIONS='${EX4DEF_COMMONOPTIONS}' | |
67 | # more options for the daemon/process running the queue (applies to the one | |
68 | # started in /etc/ppp/ip-up.d/exim4, too. | |
69 | QUEUERUNNEROPTIONS='${EX4DEF_QUEUERUNNEROPTIONS}' | |
70 | # special flags given to exim directly after the -q. See exim(8) | |
71 | QFLAGS='${EX4DEF_QFLAGS}' | |
72 | # Options for the SMTP listener daemon. By default, it is listening on | |
73 | # port 25 only. To listen on more ports, it is recommended to use | |
0baa7b9d | 74 | # -oX 25:587:10025 -oP /run/exim4/exim.pid |
de45f55a AM |
75 | SMTPLISTENEROPTIONS='${EX4DEF_SMTPLISTENEROPTIONS}' |
76 | EOF | |
77 | cat "${EX4DEF_TMP}" > "${defaultfile}" | |
78 | rm -f "${EX4DEF_TMP}" | |
79 | } | |
80 | ||
81 | ## Parse commandline | |
82 | TEMP=$(getopt -n update-exim4defaults \ | |
83 | -l qflags:,queuerunner:,queuetime:,commonoptions:,queuerunneroptions:,smtplisteneroptions:,remove-common:,remove-queue:,remove-smtp:,force,help,init -- \ | |
84 | +fh "$@") | |
85 | ||
86 | if test "$?" != 0; then | |
87 | echo "Terminating..." >&2 | |
88 | exit 1 | |
89 | fi | |
90 | ||
91 | eval set -- ${TEMP} | |
92 | while test "$1" != "--"; do | |
93 | case $1 in | |
94 | -f|--force) | |
95 | EX4DEF_FORCE=true | |
96 | ;; | |
97 | -h|--help) | |
98 | ex4def_usage | |
99 | exit 0 | |
100 | ;; | |
101 | --qflags) | |
102 | shift | |
103 | EX4DEF_QFLAGS="$1" | |
104 | ;; | |
105 | --queuerunner) | |
106 | shift | |
107 | EX4DEF_QUEUERUNNER="$1" | |
108 | if ! expr match "${EX4DEF_QUEUERUNNER}" '\(ppp\|no\|combined\|nodaemon\|queueonly\|separate\)$' >/dev/null ; then | |
109 | echo "invalid argument ${EX4DEF_QUEUERUNNER} for --queuerunner" 1>&2 | |
110 | exit 1 | |
111 | fi | |
112 | ;; | |
113 | --queuetime) | |
114 | shift | |
115 | EX4DEF_QUEUEINTERVAL="$1" | |
116 | ;; | |
117 | --commonoptions) | |
118 | shift | |
119 | EX4DEF_COMMONOPTIONS="$1" | |
120 | EX4DEF_FLAGOPTIONS=true | |
121 | ;; | |
122 | --queuerunneroptions) | |
123 | shift | |
124 | EX4DEF_QUEUERUNNEROPTIONS="$1" | |
125 | EX4DEF_FLAGOPTIONS=true | |
126 | ;; | |
127 | --smtplisteneroptions) | |
128 | shift | |
129 | EX4DEF_SMTPLISTENEROPTIONS="$1" | |
130 | EX4DEF_FLAGOPTIONS=true | |
131 | ;; | |
132 | --remove-common) | |
133 | shift | |
134 | EX4DEF_REMOVECOMMON="$1" | |
135 | EX4DEF_FLAGREMOVE=true | |
136 | ;; | |
137 | --remove-queue) | |
138 | shift | |
139 | EX4DEF_REMOVEQUEUE="$1" | |
140 | EX4DEF_FLAGREMOVE=true | |
141 | ;; | |
142 | --remove-smtp) | |
143 | shift | |
144 | EX4DEF_REMOVESMTP="$1" | |
145 | EX4DEF_FLAGREMOVE=true | |
146 | ;; | |
147 | --init) | |
148 | EX4DEF_INIT=true | |
149 | ;; | |
150 | esac | |
151 | shift | |
152 | done | |
153 | shift | |
154 | ||
155 | # No non-option arguments allowed. | |
156 | if [ "$#" -ne 0 ]; then | |
157 | echo "No non option arguments allowed" >&2 | |
158 | ex4def_usage >&2 | |
159 | exit 1 | |
160 | fi | |
161 | ||
162 | if [ "${EX4DEF_FLAGREMOVE}" = "true" ] && [ "${EX4DEF_FLAGOPTIONS}" = "true" ] ; then | |
163 | echo "Cannot use --remove-something together with --somethingoptions" >&2 | |
164 | ex4def_usage >&2 | |
165 | exit 1 | |
166 | fi | |
167 | ||
168 | #if [ ! -r ${defaultfile} ]; then | |
169 | # echo "Cannot read ${defaultfile}, terminating" >&2 | |
170 | # exit 1 | |
171 | #fi | |
172 | ||
173 | if "${EX4DEF_INIT}" = "true" ] ; then | |
174 | [ -e "${defaultfile}" ] && [ "${EX4DEF_FORCE}" != "true" ] && exit 0 | |
175 | # Reset to default values | |
176 | EX4DEF_QUEUERUNNER='combined' | |
177 | EX4DEF_QUEUEINTERVAL='30m' | |
178 | EX4DEF_COMMONOPTIONS='' | |
179 | EX4DEF_QUEUERUNNEROPTIONS='' | |
180 | EX4DEF_QFLAGS='' | |
181 | EX4DEF_SMTPLISTENEROPTIONS='' | |
182 | ||
183 | ex4def_write | |
184 | exit 0 | |
185 | fi | |
186 | ||
187 | #Try removing | |
188 | if [ "${EX4DEF_FLAGREMOVE}" = "true" ] ; then | |
189 | EX4DEF_REMOVEERROR="false" | |
190 | if [ ! -z "${EX4DEF_REMOVECOMMON}" ] ; then | |
191 | EX4DEF_COMMONOPTIONS=$(echo "${COMMONOPTIONS}" | \ | |
192 |