3 # Configure Postfix for GForge
5 # Based of install-exim.sh by: Christian Bayle, Roland Mas, debian-sf (GForge for Debian)
10 if [ $(id -u) != 0 ] ; then
11 echo "You must be root to run this, please enter passwd"
17 cp -a /etc/aliases /etc/aliases.gforge-new
18 # Redirect "noreply" mail to the bit bucket (if need be)
19 noreply_to_bitbucket=$(forge_get_config noreply_to_bitbucket)
20 if [ "$noreply_to_bitbucket" != "no" ] ; then
21 if ! grep -q "^noreply:" /etc/aliases.gforge-new ; then
22 echo "### Next line inserted by GForge install" >> /etc/aliases.gforge-new
23 echo "noreply: /dev/null" >> /etc/aliases.gforge-new
27 # Redirect "gforge" mail to the site admin
28 server_admin=$(forge_get_config admin_email)
29 if ! grep -q "^gforge:" /etc/aliases.gforge-new ; then
30 echo "### Next line inserted by GForge install" >> /etc/aliases.gforge-new
31 echo "gforge: $server_admin" >> /etc/aliases.gforge-new
34 cp -a /etc/postfix/main.cf /etc/postfix/main.cf.gforge-new
36 perl -pi -e's/SOURCEFORGE_DOMAINS/GFORGE_DOMAINS/;' \
37 -e's/BEGIN SOURCEFORGE BLOCK -- DO NOT EDIT/BEGIN GFORGE BLOCK -- DO NOT EDIT/;' \
38 -e's/END SOURCEFORGE BLOCK/END GFORGE BLOCK/;' /etc/postfix/main.cf.gforge-new
40 pattern=$(basename $0).XXXXXX
41 tmp1=$(mktemp /tmp/$pattern)
42 # First, get the list of local domains right - add gforge domains to 'mydestination'
44 require ("/usr/share/gforge/lib/include.pl") ;
47 last if l =~ /^\s*mydestination/ ;
51 if ($l =~ /^(\s*mydestination\s*=\s*)(\S.*)/) {
52 $l .= ", users.$domain_name" unless ($l =~ /users.$domain_name/);
54 $l = "mydestination = users.$domain_name"
57 while ($l = <>) { print $l; };
58 ' < /etc/postfix/main.cf.gforge-new > $tmp1
59 grep -q '^[[:space:]]*relay_domains' $tmp1 || echo 'relay_domains = $mydestination' >>$tmp1
61 require ("/usr/share/gforge/lib/include.pl") ;
63 while (($l = <>) !~ /^\s*relay_domains/) { print $l; };
65 $l .= ", $sys_lists_host" unless ($l =~ /^[^#]*$sys_lists_host/);
67 while ($l = <>) { print $l; };
69 tmp2=$(mktemp /tmp/$pattern)
70 # Second, insinuate our forwarding rules in the directors section
72 require ("/usr/share/gforge/lib/include.pl") ;
78 my $seen_transport_maps;
80 $gf_block = qq{### BEGIN GFORGE BLOCK -- DO NOT EDIT ###
81 # You may move this block around to accomodate your local needs as long as you
82 # keep it in an appropriate position, where \"appropriate\" is defined by you.
84 pgsql_gforge_users_hosts = unix:/var/run/postgresql
85 pgsql_gforge_users_user = ${sys_dbuser}_mta
86 pgsql_gforge_users_password = ${sys_dbuser}_mta
87 pgsql_gforge_users_dbname = $sys_dbname
88 pgsql_gforge_users_domain = users.$domain_name
89 pgsql_gforge_users_query = SELECT email FROM mta_users WHERE login = '\''%u'\''
91 mailman_destination_recipient_limit = 1
93 ### END GFORGE BLOCK ###
97 $seen_transport_maps = 0;
99 if ($l =~ /^\s*virtual_alias_maps/) {
101 $l .= ", pgsql:pgsql_gforge_users" unless ($l =~ /^[^#]*pgsql:pgsql_gforge_users/);
102 $l =~ s/pgsql:pgsql_gforge_lists, // ;
103 $l =~ s/, pgsql:pgsql_gforge_lists// ;
105 $seen_alias_maps = 1;
106 } elsif ($l =~ /^\s*transport_maps/) {
108 $l .= ", hash:/var/lib/gforge/etc/postfix-transport" unless ($l =~ /^[^#]*hash:\/var\/lib\/gforge\/etc\/postfix-transport/);
110 $seen_transport_maps = 1;
111 } elsif ($l =~ /^\s*\#\#\# BEGIN GFORGE BLOCK \-\- DO NOT EDIT \#\#\#/) {
113 while ($l !~ /^\s*\#\#\# END GFORGE BLOCK \#\#\#/) {
117 } elsif ($l =~ /^### GFORGE ADDITION - The following line can be moved and this line removed ###/) {
118 # Ignore that old line
119 } elsif ($l =~ /^\s*virtual_maps = pgsql:pgsql_gforge_users, pgsql:pgsql_gforge_lists$/) {
120 # Ignore that one too
121 } elsif ($l =~ /^\s*virtual_maps = .*pgsql:pgsql_gforge_users, pgsql:pgsql_gforge_lists/) {
123 $l =~ s/, pgsql:pgsql_gforge_users// ;
124 $l =~ s/, pgsql:pgsql_gforge_lists// ;
125 $l =~ s/pgsql:pgsql_gforge_users, // ;
126 $l =~ s/pgsql:pgsql_gforge_lists, // ;
133 if ($seen_gf_block == 0) {
137 if ($seen_alias_maps == 0) {
138 print "### GFORGE ADDITION - The following virtual_alias_maps line can be moved and this line removed ###\n";
139 print "virtual_alias_maps = pgsql:pgsql_gforge_users\n";
141 if ($seen_transport_maps == 0) {
142 print "### GFORGE ADDITION - The following transport_maps line can be moved and this line removed ###\n";
143 print "transport_maps = hash:/var/lib/gforge/etc/postfix-transport\n";
147 cat $tmp2 > /etc/postfix/main.cf.gforge-new
152 [ -x /usr/bin/newaliases ] && newaliases
153 echo "$(forge_get_config lists_host) mailman:" > /var/lib/gforge/etc/postfix-transport
154 postmap /var/lib/gforge/etc/postfix-transport
158 pattern=$(basename $0).XXXXXX
159 tmp1=$(mktemp /tmp/$pattern)
160 cp -a /etc/aliases /etc/aliases.gforge-new
161 # Redirect "noreply" mail to the bit bucket (if need be)
162 noreply_to_bitbucket=$(forge_get_config noreply_to_bitbucket)
163 if [ "$noreply_to_bitbucket" != "no" ] ; then
164 grep -v "^noreply:" /etc/aliases.gforge-new > $tmp1
165 cat $tmp1 > /etc/aliases.gforge-new
169 cp -a /etc/postfix/main.cf /etc/postfix/main.cf.gforge-new
171 perl -pi -e's/SOURCEFORGE_DOMAINS/GFORGE_DOMAINS/ ; s/BEGIN SOURCEFORGE BLOCK -- DO NOT EDIT/BEGIN GFORGE BLOCK -- DO NOT EDIT/ ; s/END SOURCEFORGE BLOCK/END GFORGE BLOCK/' /etc/postfix/main.cf.gforge-new
173 tmp1=$(mktemp /tmp/$pattern)
174 # First, replace the list of local domains
176 require ("/usr/share/gforge/lib/include.pl") ;
178 last if l =~ /^\s*mydestination/ ;
182 if ($l =~ /^(\s*mydestination\s*=\s*)(\S.*)/) {
185 $dests =~ s/, users.$domain_name// ;
186 $dests =~ s/, $sys_lists_host// ;
187 $l = $head . $dests ;
190 while ($l = <>) { print $l; };
191 ' < /etc/postfix/main.cf.gforge-new > $tmp1
192 grep -q '^[[:space:]]*relay_domains' $tmp1 && perl -i -e '
193 require ("/usr/share/gforge/lib/include.pl") ;
194 while (($l = <>) !~ /^\s*relay_domains/) {
198 $l =~ /^(\s*relay_domains\s*=\s*)(\S.*)/ ;
201 $dests =~ s/, $sys_lists_host// ;
202 $l = $head . $dests ;
204 while ($l = <>) { print $l; };
206 tmp2=$(mktemp /tmp/$pattern)
207 # Second, kill our forwarding rules
211 if ($l =~ /^### BEGIN GFORGE BLOCK -- DO NOT EDIT ###/) {
214 print $l unless $in_sf_block ;
215 $in_sf_block = 0 if ($l =~ /^### END GFORGE BLOCK ###/) ;
218 while ($l = <>) { print $l; };
221 cat $tmp2 > /etc/postfix/main.cf.gforge-new
229 echo "Usage: $0 {configure|configure-files|purge|purge-files}"