Browse Source

refractor variable replacement

tags/v1.0.0
Robin Thoni 7 years ago
parent
commit
609001b843

+ 4
- 0
dovecot/Dockerfile View File

@@ -26,6 +26,10 @@ RUN rm -rf /var/log/* &&\
26 26
 
27 27
 COPY ./sieve/ /etc/dovecot/sieve/
28 28
 
29
+COPY ./vars-vars /etc/vars-vars
30
+
31
+COPY ./vars-files /etc/vars-files
32
+
29 33
 COPY ./run.sh /run.sh
30 34
 
31 35
 VOLUME ["/var/email"]

+ 1
- 1
dovecot/config/dovecot-pgsql.conf View File

@@ -1,5 +1,5 @@
1 1
 driver = pgsql
2
-connect = host=localhost dbname=postfixadmin user=postfixadmin password=fNzBE6acH5ZNLuLc
2
+connect = host=POSTGRES_HOST dbname=POSTGRES_DB user=POSTGRES_USER password=POSTGRES_PASSWORD
3 3
 default_pass_scheme = MD5-CRYPT
4 4
 user_query = SELECT '/var/email/%d/%n' as home, 7788 AS uid, 7788 AS gid FROM mailbox WHERE username = '%u'
5 5
 password_query = SELECT password FROM mailbox WHERE username = '%u'

+ 20
- 12
dovecot/run.sh View File

@@ -1,22 +1,30 @@
1
-#! /usr/bin/env sh
1
+#! /usr/bin/env bash
2 2
 
3
-replace_vars()
3
+replace_var()
4 4
 {
5 5
   file="${1}"
6
-  sed -e "s/DOVECOT_LMTP_PORT/${DOVECOT_LMTP_PORT}/" -i "${file}"
7
-  sed -e "s/DOVECOT_SASL_PORT/${DOVECOT_SASL_PORT}/" -i "${file}"
8
-  sed -e "s/EXIM_SMARTHOST_HOST/${EXIM_SMARTHOST_HOST}/" -i "${file}"
9
-  sed -e "s/EXIM_SMARTHOST_USER/${EXIM_SMARTHOST_USER}/" -i "${file}"
10
-  sed -e "s/EXIM_SMARTHOST_PASSWORD/${EXIM_SMARTHOST_PASSWORD}/" -i "${file}"
6
+  var="${2}"
7
+  sed -e "s?${var}?${!var}?g" -i "${file}"
11 8
 }
12 9
 
13
-sed -e "s/connect *=.*/connect = host=${POSTGRES_HOST} dbname=${POSTGRES_DB} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD}/g" -i /etc/dovecot/dovecot-pgsql.conf
14
-
10
+replace_vars()
11
+{
12
+  file="${1}"
13
+  for var in $(cat /etc/vars-vars)
14
+  do
15
+    replace_var "${file}" "${var}"
16
+  done
17
+}
15 18
 
16
-replace_vars /etc/dovecot/dovecot.conf
17
-replace_vars /etc/exim4/update-exim4.conf.conf
18
-replace_vars /etc/exim4/passwd.client
19
+replace_files()
20
+{
21
+  for file in $(cat /etc/vars-files)
22
+  do
23
+    replace_vars "${file}"
24
+  done
25
+}
19 26
 
27
+replace_files
20 28
 
21 29
 rm -f /var/run/dovecot/master.pid &&
22 30
 rm -f /var/run/exim4/exim.pid &&

+ 4
- 0
dovecot/vars-files View File

@@ -0,0 +1,4 @@
1
+/etc/dovecot/dovecot.conf
2
+/etc/dovecot/dovecot-pgsql.conf
3
+/etc/exim4/update-exim4.conf.conf
4
+/etc/exim4/passwd.client

+ 20
- 0
dovecot/vars-vars View File

@@ -0,0 +1,20 @@
1
+POSTGRES_HOST
2
+POSTGRES_USER
3
+POSTGRES_PASSWORD
4
+POSTGRES_DB
5
+
6
+MAIL_DOMAIN
7
+MAIL_HOSTNAME
8
+
9
+DOVECOT_HOST
10
+DOVECOT_SASL_PORT
11
+DOVECOT_LMTP_PORT
12
+
13
+POSTFIX_HOST
14
+
15
+OPENDKIM_HOST
16
+OPENDKIM_PORT
17
+
18
+EXIM_SMARTHOST_HOST
19
+EXIM_SMARTHOST_USER
20
+EXIM_SMARTHOST_PASSWORD

+ 4
- 0
opendkim/Dockerfile View File

@@ -22,6 +22,10 @@ COPY ./config /etc/opendkim/
22 22
 
23 23
 RUN chown -R opendkim:opendkim /etc/opendkim
24 24
 
25
+COPY ./vars-vars /etc/vars-vars
26
+
27
+COPY ./vars-files /etc/vars-files
28
+
25 29
 COPY ./run.sh /run.sh
26 30
 
27 31
 VOLUME ["/etc/opendkim/keys"]

+ 26
- 7
opendkim/run.sh View File

@@ -1,11 +1,30 @@
1
-#! /usr/bin/env sh
1
+#! /usr/bin/env bash
2 2
 
3
-sed -e "s/POSTGRES_HOST/${POSTGRES_HOST}/" -i /etc/opendkim/opendkim.conf
4
-sed -e "s/POSTGRES_USER/${POSTGRES_USER}/" -i /etc/opendkim/opendkim.conf
5
-sed -e "s/POSTGRES_PASSWORD/${POSTGRES_PASSWORD}/" -i /etc/opendkim/opendkim.conf
6
-sed -e "s/POSTGRES_DB/${POSTGRES_DB}/" -i /etc/opendkim/opendkim.conf
7
-sed -e "s/OPENDKIM_PORT/${OPENDKIM_PORT}/" -i /etc/opendkim/opendkim.conf
8
-sed -e "s/MAIL_DOMAIN/${MAIL_DOMAIN}/" -i /etc/opendkim/KeyTable
3
+replace_var()
4
+{
5
+  file="${1}"
6
+  var="${2}"
7
+  sed -e "s?${var}?${!var}?g" -i "${file}"
8
+}
9
+
10
+replace_vars()
11
+{
12
+  file="${1}"
13
+  for var in $(cat /etc/vars-vars)
14
+  do
15
+    replace_var "${file}" "${var}"
16
+  done
17
+}
18
+
19
+replace_files()
20
+{
21
+  for file in $(cat /etc/vars-files)
22
+  do
23
+    replace_vars "${file}"
24
+  done
25
+}
26
+
27
+replace_files
9 28
 
10 29
 if [ ! -e /etc/opendkim/keys/dkim.private ]
11 30
 then

+ 2
- 0
opendkim/vars-files View File

@@ -0,0 +1,2 @@
1
+/etc/opendkim/opendkim.conf
2
+/etc/opendkim/KeyTable

+ 20
- 0
opendkim/vars-vars View File

@@ -0,0 +1,20 @@
1
+POSTGRES_HOST
2
+POSTGRES_USER
3
+POSTGRES_PASSWORD
4
+POSTGRES_DB
5
+
6
+MAIL_DOMAIN
7
+MAIL_HOSTNAME
8
+
9
+DOVECOT_HOST
10
+DOVECOT_SASL_PORT
11
+DOVECOT_LMTP_PORT
12
+
13
+POSTFIX_HOST
14
+
15
+OPENDKIM_HOST
16
+OPENDKIM_PORT
17
+
18
+EXIM_SMARTHOST_HOST
19
+EXIM_SMARTHOST_USER
20
+EXIM_SMARTHOST_PASSWORD

+ 4
- 0
postfix/Dockerfile View File

@@ -26,6 +26,10 @@ COPY ./config/ /etc/postfix/
26 26
 
27 27
 COPY ./certs/ /etc/ssl/private/
28 28
 
29
+COPY ./vars-vars /etc/vars-vars
30
+
31
+COPY ./vars-files /etc/vars-files
32
+
29 33
 COPY ./run.sh /run.sh
30 34
 
31 35
 EXPOSE 25 587

+ 6
- 6
postfix/config/main.cf View File

@@ -20,8 +20,8 @@ readme_directory = no
20 20
 # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
21 21
 # information on enabling SSL in the smtp client.
22 22
 
23
-mydomain = example.org
24
-myhostname = mail.example.org
23
+mydomain = MAIL_DOMAIN
24
+myhostname = MAIL_HOSTNAME
25 25
 alias_maps = hash:/etc/aliases
26 26
 alias_database = hash:/etc/aliases
27 27
 myorigin = $mydomain
@@ -44,7 +44,7 @@ relay_domains = pgsql:/etc/postfix/pgsql_relay_domains.cf
44 44
 virtual_minimum_uid=100
45 45
 virtual_uid_maps=static:7788
46 46
 virtual_gid_maps=static:7788
47
-virtual_transport=dovecot_24
47
+virtual_transport=lmtp:inet:DOVECOT_HOST:DOVECOT_LMTP_PORT
48 48
 dovecot_destination_recipient_limit = 1
49 49
 
50 50
 
@@ -65,7 +65,7 @@ queue_directory=/var/spool/postfix
65 65
 
66 66
 
67 67
 smtpd_sasl_type=dovecot
68
-smtpd_sasl_path=dovecot_12345
68
+smtpd_sasl_path=inet:DOVECOT_HOST:DOVECOT_SASL_PORT
69 69
 smtpd_sasl_auth_enable=yes
70 70
 broken_sasl_auth_clients=yes
71 71
 smtpd_sasl_security_options=noanonymous
@@ -83,8 +83,8 @@ message_size_limit = 0
83 83
 
84 84
 milter_default_action = accept
85 85
 milter_protocol = 6
86
-smtpd_milters = opendkim_12345
87
-non_smtpd_milters = opendkim_12345
86
+smtpd_milters = inet:OPENDKIM_HOST:OPENDKIM_PORT
87
+non_smtpd_milters = inet:OPENDKIM_HOST:OPENDKIM_PORT
88 88
 smtpd_relay_restrictions = permit_mynetworks,
89 89
         permit_sasl_authenticated,
90 90
         reject_unknown_recipient_domain,

+ 4
- 4
postfix/config/pgsql_recipient_bcc.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT bcc FROM recipient_bcc WHERE recipient='%s'

+ 4
- 4
postfix/config/pgsql_relay_domains.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT domain FROM domain WHERE domain='%s' and backupmx = true

+ 4
- 4
postfix/config/pgsql_transport.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT transport FROM transport WHERE domain='%s'

+ 4
- 4
postfix/config/pgsql_virtual_alias_maps.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT goto FROM alias WHERE address='%s' AND active = true AND is_regexp = false

+ 4
- 4
postfix/config/pgsql_virtual_alias_maps_alias.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT goto FROM alias WHERE address=((regexp_split_to_array('%s', '\+|@'))[1]) || '@' || split_part('%s', '@', 2) AND active = true AND is_regexp = false

+ 4
- 4
postfix/config/pgsql_virtual_alias_maps_regexp.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT goto FROM alias WHERE '%s' ILIKE CONCAT('^',address,'$') AND SUBSTRING(address,1,1) != '@' AND is_regexp = true

+ 4
- 4
postfix/config/pgsql_virtual_mailbox_domains.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT domain FROM domain WHERE domain='%s' and backupmx = false and active = true

+ 4
- 4
postfix/config/pgsql_virtual_mailbox_maps.cf View File

@@ -1,5 +1,5 @@
1
-hosts = 127.0.0.1
2
-user = postfixadmin
3
-password = pg_password
4
-dbname = postfixadmin
1
+hosts = POSTGRES_HOST
2
+user = POSTGRES_USER
3
+password = POSTGRES_PASSWORD
4
+dbname = POSTGRES_DB
5 5
 query = SELECT maildir FROM mailbox WHERE username='%s' AND active = true

+ 27
- 8
postfix/run.sh View File

@@ -1,17 +1,36 @@
1
-#! /usr/bin/env sh
1
+#! /usr/bin/env bash
2
+
3
+replace_var()
4
+{
5
+  file="${1}"
6
+  var="${2}"
7
+  sed -e "s?${var}?${!var}?g" -i "${file}"
8
+}
9
+
10
+replace_vars()
11
+{
12
+  file="${1}"
13
+  for var in $(cat /etc/vars-vars)
14
+  do
15
+    replace_var "${file}" "${var}"
16
+  done
17
+}
18
+
19
+replace_files()
20
+{
21
+  for file in $(cat /etc/vars-files)
22
+  do
23
+    replace_vars "${file}"
24
+  done
25
+}
26
+
27
+replace_files
2 28
 
3 29
 sed -e "s/hosts *=.*/hosts = ${POSTGRES_HOST}/g" -i /etc/postfix/pgsql_*
4 30
 sed -e "s/user *=.*/user = ${POSTGRES_USER}/g" -i /etc/postfix/pgsql_*
5 31
 sed -e "s/password *=.*/password = ${POSTGRES_PASSWORD}/g" -i /etc/postfix/pgsql_*
6 32
 sed -e "s/dbname *=.*/dbname = ${POSTGRES_DB}/g" -i /etc/postfix/pgsql_*
7 33
 
8
-postconf -e mydomain="${MAIL_DOMAIN}"
9
-postconf -e myhostname="${MAIL_HOSTNAME}"
10
-postconf -e smtpd_sasl_path="inet:${DOVECOT_HOST}:${DOVECOT_SASL_PORT}"
11
-postconf -e virtual_transport="lmtp:inet:${DOVECOT_HOST}:${DOVECOT_LMTP_PORT}"
12
-postconf -e smtpd_milters="inet:${OPENDKIM_HOST}:${OPENDKIM_PORT}"
13
-postconf -e non_smtpd_milters="inet:${OPENDKIM_HOST}:${OPENDKIM_PORT}"
14
-
15 34
 rm -f /var/run/rsyslogd.pid
16 35
 service rsyslog start &&
17 36
 service postfix start &&

+ 9
- 0
postfix/vars-files View File

@@ -0,0 +1,9 @@
1
+/etc/postfix/main.cf
2
+/etc/postfix/pgsql_recipient_bcc.cf
3
+/etc/postfix/pgsql_relay_domains.cf
4
+/etc/postfix/pgsql_transport.cf
5
+/etc/postfix/pgsql_virtual_alias_maps_alias.cf
6
+/etc/postfix/pgsql_virtual_alias_maps.cf
7
+/etc/postfix/pgsql_virtual_alias_maps_regexp.cf
8
+/etc/postfix/pgsql_virtual_mailbox_domains.cf
9
+/etc/postfix/pgsql_virtual_mailbox_maps.cf

+ 20
- 0
postfix/vars-vars View File

@@ -0,0 +1,20 @@
1
+POSTGRES_HOST
2
+POSTGRES_USER
3
+POSTGRES_PASSWORD
4
+POSTGRES_DB
5
+
6
+MAIL_DOMAIN
7
+MAIL_HOSTNAME
8
+
9
+DOVECOT_HOST
10
+DOVECOT_SASL_PORT
11
+DOVECOT_LMTP_PORT
12
+
13
+POSTFIX_HOST
14
+
15
+OPENDKIM_HOST
16
+OPENDKIM_PORT
17
+
18
+EXIM_SMARTHOST_HOST
19
+EXIM_SMARTHOST_USER
20
+EXIM_SMARTHOST_PASSWORD

+ 4
- 0
postfixadmin/Dockerfile View File

@@ -32,6 +32,10 @@ COPY ./postfixadmin-3.0/ /var/www/html/
32 32
 
33 33
 RUN chmod -R 777 /var/www/html/templates_c
34 34
 
35
+COPY ./vars-vars /etc/vars-vars
36
+
37
+COPY ./vars-files /etc/vars-files
38
+
35 39
 COPY ./run.sh /run.sh
36 40
 
37 41
 EXPOSE 80

+ 26
- 2
postfixadmin/run.sh View File

@@ -1,6 +1,30 @@
1
-#!/bin/bash
1
+#! /usr/bin/env bash
2 2
 
3
-sed -e "s/POSTFIX_HOST/${POSTFIX_HOST}/" -i /var/www/html/config.inc.php
3
+replace_var()
4
+{
5
+  file="${1}"
6
+  var="${2}"
7
+  sed -e "s?${var}?${!var}?g" -i "${file}"
8
+}
9
+
10
+replace_vars()
11
+{
12
+  file="${1}"
13
+  for var in $(cat /etc/vars-vars)
14
+  do
15
+    replace_var "${file}" "${var}"
16
+  done
17
+}
18
+
19
+replace_files()
20
+{
21
+  for file in $(cat /etc/vars-files)
22
+  do
23
+    replace_vars "${file}"
24
+  done
25
+}
26
+
27
+replace_files
4 28
 
5 29
 rm -f /run/apache2/apache2.pid
6 30
 exec /usr/sbin/apache2ctl -D FOREGROUND

+ 1
- 0
postfixadmin/vars-files View File

@@ -0,0 +1 @@
1
+/var/www/html/config.inc.php

+ 20
- 0
postfixadmin/vars-vars View File

@@ -0,0 +1,20 @@
1
+POSTGRES_HOST
2
+POSTGRES_USER
3
+POSTGRES_PASSWORD
4
+POSTGRES_DB
5
+
6
+MAIL_DOMAIN
7
+MAIL_HOSTNAME
8
+
9
+DOVECOT_HOST
10
+DOVECOT_SASL_PORT
11
+DOVECOT_LMTP_PORT
12
+
13
+POSTFIX_HOST
14
+
15
+OPENDKIM_HOST
16
+OPENDKIM_PORT
17
+
18
+EXIM_SMARTHOST_HOST
19
+EXIM_SMARTHOST_USER
20
+EXIM_SMARTHOST_PASSWORD

+ 7
- 0
update_vars.sh View File

@@ -0,0 +1,7 @@
1
+#! /usr/bin/env sh
2
+
3
+vars=$(cat env | cut -d= -f1)
4
+for docker in dovecot opendkim postfix postfixadmin
5
+do
6
+  echo "${vars}" > "./${docker}/vars-vars"
7
+done

Loading…
Cancel
Save