Browse Source

[email_account] Adapt to new mail config on adagio

Remove useless code from email_account considering the change of
configuration for the mail system on adagio:
* No need to twiddle cyrus and restart it to connect to cyradm, just
  stop using --auth
* No default domain anymore (thus no special casing for it)
* No file listing current valid emails
master
Thomas Preud'homme 6 years ago
parent
commit
3110ed1288
1 changed files with 21 additions and 111 deletions
  1. 21
    111
      email_account/email_account

+ 21
- 111
email_account/email_account View File

@@ -31,7 +31,7 @@ usage ()
31 31
 	echo "$progname emailaccount [emailalias]"
32 32
 	echo "$progname -h"
33 33
 	echo
34
-	echo "Fist form adds an email account named emailaccount if it doesn't already exist"
34
+	echo "First form adds an email account named emailaccount if it doesn't already exist"
35 35
 	echo "and creates an alias named emailalias for this email account if specified."
36 36
 	echo
37 37
 	echo "Second form prints this help."
@@ -145,21 +145,6 @@ try_sudo ()
145 145
 	exit $ret
146 146
 }
147 147
 
148
-# Warn user that cyrus will need to restart twice and postfix will have
149
-# to reload its configuration once and ask him if he is ok for that
150
-test_ready_for_restarts ()
151
-{
152
-	local - first_ask next_ask
153
-	first_ask="Be aware that you'll need to restart cyrus twice and to make postfix reload its configuration once. Are you ready?"
154
-	next_ask="Incorrect answer. Are you ready to restart cyrus and make postfix reload its configuration?"
155
-	ask_user_default_no "$first_ask" "$next_ask"
156
-	if [ $? -eq 1 ]
157
-	then
158
-		echo "Ok, exiting…"
159
-		exit 1
160
-	fi
161
-}
162
-
163 148
 # Test cyrus password is OK.
164 149
 test_cyrus_admin ()
165 150
 {
@@ -169,25 +154,6 @@ test_cyrus_admin ()
169 154
 	testsaslauthd -u $cyruser -p $cyrpwd > /dev/null || { echo "Error! Password for main cyrus admin has changed but has not been modified in /root/" >&2 && exit 1 ; }
170 155
 }
171 156
 
172
-# Save cyrus state and make it cyradm ready, that is save and change
173
-# allowplaintext and virtdomain and make it listen on localhost:imap
174
-# instead of *:imap
175
-save_cyrus_state_and_become_cyradm_ready ()
176
-{
177
-	local -
178
-	sed -r -i "s/^(.*cmd=\"imapd.* listen=\")(imap\".*)$/\1localhost:\2/" /etc/cyrus.conf
179
-	sed -r -i "s/^([[:blank:]]*allowplaintext:.*)$/#\1\nallowplaintext: 1/" /etc/imapd.conf
180
-	sed -r -i "s/^([[:blank:]]*virtdomains:.*)$/#\1\nvirtdomains: userid/" /etc/imapd.conf
181
-	invoke-rc.d --quiet cyrus2.2 restart
182
-	if [ ! $? -eq 0 ]
183
-	then
184
-		echo "Error! Restarting cyrus failed. The requested action coudn't be performed." >&2
185
-		echo "Look at the logs and restart Cyrus manually." >&2
186
-		return 1
187
-	fi
188
-	return 0
189
-}
190
-
191 157
 # Ask a password to the user and create the entry in sasldb database.
192 158
 ask_and_create_password ()
193 159
 {
@@ -246,23 +212,15 @@ create_sasldb_password ()
246 212
 update_virtual_domains ()
247 213
 {
248 214
 	local -
249
-	grep "defaultdomain:" /etc/imapd.conf | grep "$emaildomain" > /dev/null
215
+	grep "loginrealms:" /etc/imapd.conf | grep "$emaildomain" > /dev/null
250 216
 	if [ ! $? -eq 0 ]
251 217
 	then
252
-		grep "loginrealms:" /etc/imapd.conf | grep "$emaildomain" > /dev/null
253
-		if [ ! $? -eq 0 ]
254
-		then
255
-			sed -r -i "s/^([[:blank:]]*loginrealms): ?(.*)$/\1: $emaildomain \2/" /etc/imapd.conf
256
-		fi
218
+		sed -r -i "s/^([[:blank:]]*loginrealms): ?(.*)$/\1: $emaildomain \2/" /etc/imapd.conf
257 219
 	fi
258
-	grep -E "mydomain[[:blank:]]*=" /etc/postfix/main.cf | grep "$emaildomain" > /dev/null
220
+	grep -E "virtual_mailbox_domains[[:blank:]]*=" /etc/postfix/main.cf | grep "$emaildomain" /dev/null
259 221
 	if [ ! $? -eq 0 ]
260 222
 	then
261
-		grep -E "virtual_mailbox_domains[[:blank:]]*=" /etc/postfix/main.cf | grep "$emaildomain" /dev/null
262
-		if [ ! $? -eq 0 ]
263
-		then
264
-			sed -r -i "s/^([[:blank:]]*virtual_mailbox_domains[[:blank:]]*)= ?(.*)$/\1= $emaildomain \2/" /etc/postfix/main.cf
265
-		fi
223
+		sed -r -i "s/^([[:blank:]]*virtual_mailbox_domains[[:blank:]]*)= ?(.*)$/\1= $emaildomain \2/" /etc/postfix/main.cf
266 224
 	fi
267 225
 }
268 226
 
@@ -282,26 +240,6 @@ echo_with_tabs ()
282 240
 	echo "$2"
283 241
 }
284 242
 
285
-# Add requested email to postfix virtual_mailbox_maps.
286
-update_postfix_email_account ()
287
-{
288
-	local -
289
-	grep -E "^[[:blank:]]*$emailuser@$emaildomain" /etc/postfix/vmailbox > /dev/null
290
-	if [ ! $? -eq 0 ]
291
-	then
292
-		echo_with_tabs "$emailuser@$emaildomain" "whatever" 4 >> /etc/postfix/vmailbox
293
-	fi
294
-	if [ ! $# -eq 0 ]
295
-	then
296
-		grep -E "^[[:blank:]]*$aliasuser@$aliasdomain" /etc/postfix/vmailbox > /dev/null
297
-		if [ ! $? -eq 0 ]
298
-		then
299
-			echo_with_tabs "$aliasuser@$aliasdomain" "whatever" 4 >> /etc/postfix/vmailbox
300
-		fi
301
-	fi
302
-	postmap /etc/postfix/vmailbox
303
-}
304
-
305 243
 # Add requested alias to postfix virtual_alias_maps.
306 244
 update_email_aliases ()
307 245
 {
@@ -357,37 +295,20 @@ display_infos ()
357 295
 	echo "."
358 296
 }
359 297
 
360
-# Restore cyrus state as it was before making it cyradm ready, that is
361
-# restore allowplaintext, virtdomain and make it listen on *:imap
362
-# instead of localhost:imap
363
-restore_cyrus_state ()
298
+# Ask Postfix and Cyrus to reload their configuration
299
+reload_config ()
364 300
 {
365 301
 	local -
366
-	sed -r -i "s/^(.*cmd=\"imapd.* listen=\")localhost:(imap\".*)$/\1\2/" /etc/cyrus.conf
367
-	# OK, let's explain the following sed line.
368
-	# First you must understand that for each line, all the commands inside
369
-	# the {} block and separated by ; are executed.
370
-	# When the allowplaintext commented line is found, the # is removed by
371
-	# a s/pattern/replacement/ command. Then, as this substitution is
372
-	# successful, we jump at success which copy the substituted line in
373
-	# the hold space, get the next line in the pattern space and replace
374
-	# it by the substituted line. We've just deleted the next line. Then,
375
-	# we print the line in the pattern space. If from the beginning we
376
-	# have a non allowplaintext line, then T makes us jump to fail and
377
-	# print the line in the pattern space (that is the current line).
378
-	sed -r -n -i "{s/^#([[:blank:]]*allowplaintext:.*)$/\1/;t success;T fail;: success;h;n;g;: fail;p}" /etc/imapd.conf
379
-	# Same as above for virtdomains
380
-	sed -r -n -i "{s/^#([[:blank:]]*virtdomains:.*)$/\1/;t success;T fail;: success;h;n;g;: fail;p}" /etc/imapd.conf
381
-	invoke-rc.d --quiet cyrus2.2 restart
302
+	invoke-rc.d --quiet cyrus2.2 reload
382 303
 	if [ ! $? -eq 0 ]
383 304
 	then
384
-		echo "Error! Restarting cyrus failed." >&2
305
+		echo "Error! Cyrus failed to reload its configuration." >&2
385 306
 		exit 1
386 307
 	fi
387 308
 	invoke-rc.d --quiet postfix reload
388 309
 	if [ ! $? -eq 0 ]
389 310
 	then
390
-		echo "Error! Reloading postfix failed." >&2
311
+		echo "Error! Postfix failed to reload its configuration." >&2
391 312
 		exit 1
392 313
 	fi
393 314
 }
@@ -396,11 +317,11 @@ restore_cyrus_state ()
396 317
 create_mail_account ()
397 318
 {
398 319
 	local - nblines
399
-	nblines=$(echo "listmailbox user/$emailuser@$emaildomain" | cyradm --user $cyruser --auth login --pass $cyrpwd localhost | wc -l)
320
+	nblines=$(echo "listmailbox user/$emailuser@$emaildomain" | cyradm --user $cyruser --pass $cyrpwd localhost | wc -l)
400 321
 	if [ $nblines -eq 0 ]
401 322
 	then
402 323
 		echo "Mailbox for $emailuser@$emaildomain doesn't exist, creating it…"
403
-		echo "createmailbox user/$emailuser@$emaildomain" | cyradm --user $cyruser --auth login --pass $cyrpwd localhost
324
+		echo "createmailbox user/$emailuser@$emaildomain" | cyradm --user $cyruser --pass $cyrpwd localhost
404 325
 	fi
405 326
 
406 327
 }
@@ -408,7 +329,6 @@ create_mail_account ()
408 329
 main ()
409 330
 {
410 331
 	local - ret
411
-	ret=0
412 332
 	# This test should be useless if rights on this file are corrects
413 333
 	# (that is 770 for root:gt owner)
414 334
 	test_args "$@"
@@ -416,28 +336,18 @@ main ()
416 336
 	then
417 337
 		try_sudo "$@"
418 338
 	fi
419
-	test_ready_for_restarts
420 339
 	test_cyrus_admin
421
-	save_cyrus_state_and_become_cyradm_ready
422
-	if [ $? -eq 0 ]
340
+	create_sasldb_password
341
+	update_virtual_domains
342
+	aliasuser="${aliasuser:-""}"
343
+	if [ -n "$aliasuser" ]
423 344
 	then
424
-		create_sasldb_password
425
-		update_virtual_domains
426
-		aliasuser="${aliasuser:-""}"
427
-		if [ -n "$aliasuser" ]
428
-		then
429
-			update_postfix_email_account 1
430
-			update_email_aliases
431
-		else
432
-			update_postfix_email_account
433
-		fi
434
-		create_mail_account
435
-		display_infos
436
-	else
437
-		ret=1
345
+		update_email_aliases
438 346
 	fi
439
-	restore_cyrus_state
440
-	return $ret
347
+	create_mail_account
348
+	display_infos
349
+	reload_config
350
+	return 0
441 351
 }
442 352
 
443 353
 main "${@:-""}"

Loading…
Cancel
Save