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=`/usr/share/gforge/bin/forge_get_config noreply_to_bitbucket`
20 if [ "$noreply_to_bitbucket" = "true" ] ; 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=`/usr/share/gforge/bin/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 chomp($domain_name=`/usr/share/gforge/bin/forge_get_config web_host`);
47 last if l =~ /^\s*mydestination/) ;
51 $l .= ", users.$domain_name" unless ($l =~ /^[^#]*users.$domain_name/);
53 while ($l = <>) { print $l; };
54 ' < /etc/postfix/main.cf.gforge-new > $tmp1
55 grep -q '^[[:space:]]*relay_domains' $tmp1 || echo 'relay_domains = $mydestination' >>$tmp1
57 chomp($sys_lists_host=`/usr/share/gforge/bin/forge_get_config lists_host`);
59 while (($l = <>) !~ /^\s*relay_domains/) { print $l; };
61 $l .= ", $sys_lists_host" unless ($l =~ /^[^#]*$sys_lists_host/);
63 while ($l = <>) { print $l; };
65 tmp2=$(mktemp /tmp/$pattern)
66 # Second, insinuate our forwarding rules in the directors section
68 chomp($domain_name=`/usr/share/gforge/bin/forge_get_config web_host`);
69 chomp($sys_dbuser=`/usr/share/gforge/bin/forge_get_config database_user`);
70 chomp($sys_dbname=`/usr/share/gforge/bin/forge_get_config database_name`);
76 my $seen_transport_maps;
78 $gf_block = qq{### BEGIN GFORGE BLOCK -- DO NOT EDIT ###
79 # You may move this block around to accomodate your local needs as long as you
80 # keep it in an appropriate position, where \"appropriate\" is defined by you.
82 pgsql_gforge_users_hosts = unix:/var/run/postgresql
83 pgsql_gforge_users_user = ${sys_dbuser}_mta
84 pgsql_gforge_users_password = ${sys_dbuser}_mta
85 pgsql_gforge_users_dbname = $sys_dbname
86 pgsql_gforge_users_domain = users.$domain_name
87 pgsql_gforge_users_query = SELECT email FROM mta_users WHERE login = '\''%u'\''
89 ### END GFORGE BLOCK ###
93 $seen_transport_maps = 0;
95 if ($l =~ /^\s*virtual_alias_maps/) {
97 $l .= ", pgsql:pgsql_gforge_users" unless ($l =~ /^[^#]*pgsql:pgsql_gforge_users/);
98 $l =~ s/pgsql:pgsql_gforge_lists, // ;
99 $l =~ s/, pgsql:pgsql_gforge_lists// ;
101 $seen_alias_maps = 1;
102 } elsif ($l =~ /^\s*transport_maps/) {
104 $l .= ", hash:/var/lib/gforge/etc/postfix-transport" unless ($l =~ /^[^#]*hash:\/var\/lib\/gforge\/etc\/postfix-transport/);
106 $seen_transport_maps = 1;
107 } elsif ($l =~ /^\s*\#\#\# BEGIN GFORGE BLOCK \-\- DO NOT EDIT \#\#\#/) {
109 while ($l !~ /^\s*\#\#\# END GFORGE BLOCK \#\#\#/) {
113 } elsif ($l =~ /^### GFORGE ADDITION - The following line can be moved and this line removed ###/) {
114 # Ignore that old line
115 } elsif ($l =~ /^\s*virtual_maps = pgsql:pgsql_gforge_users, pgsql:pgsql_gforge_lists$/) {
116 # Ignore that one too
117 } elsif ($l =~ /^\s*virtual_maps = .*pgsql:pgsql_gforge_users, pgsql:pgsql_gforge_lists/) {
119 $l =~ s/, pgsql:pgsql_gforge_users// ;
120 $l =~ s/, pgsql:pgsql_gforge_lists// ;
121 $l =~ s/pgsql:pgsql_gforge_users, // ;
122 $l =~ s/pgsql:pgsql_gforge_lists, // ;
129 if ($seen_gf_block == 0) {
133 if ($seen_alias_maps == 0) {
134 print "### GFORGE ADDITION - The following virtual_alias_maps line can be moved and this line removed ###\n";
135 print "virtual_alias_maps = pgsql:pgsql_gforge_users\n";
137 if ($seen_transport_maps == 0) {
138 print "### GFORGE ADDITION - The following transport_maps line can be moved and this line removed ###\n";
139 print "transport_maps = hash:/var/lib/gforge/etc/postfix-transport\n";
143 cat $tmp2 > /etc/postfix/main.cf.gforge-new
148 [ -x /usr/bin/newaliases ] && newaliases
149 echo "`/usr/share/gforge/bin/forge_get_config lists_host` mailman:" > /var/lib/gforge/etc/postfix-transport
150 postmap /var/lib/gforge/etc/postfix-transport
154 pattern=$(basename $0).XXXXXX
155 tmp1=$(mktemp /tmp/$pattern)
156 cp -a /etc/aliases /etc/aliases.gforge-new
157 # Redirect "noreply" mail to the bit bucket (if need be)
158 noreply_to_bitbucket=`/usr/share/gforge/bin/forge_get_config noreply_to_bitbucket`
159 if [ "$noreply_to_bitbucket" = "true" ] ; then
160 grep -v "^noreply:" /etc/aliases.gforge-new > $tmp1
161 cat $tmp1 > /etc/aliases.gforge-new
165 cp -a /etc/postfix/main.cf /etc/postfix/main.cf.gforge-new
167 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
169 tmp1=$(mktemp /tmp/$pattern)
170 # First, replace the list of local domains
172 chomp($domain_name=`/usr/share/gforge/bin/forge_get_config web_host`);
173 chomp($sys_lists_host=`/usr/share/gforge/bin/forge_get_config lists_host`);
175 last if l =~ /^\s*mydestination/) ;
179 if ($l =~ /^(\s*mydestination\s*=\s*)(\S.*)/) {
182 $dests =~ s/, users.$domain_name// ;
183 $dests =~ s/, $sys_lists_host// ;
184 $l = $head . $dests ;
187 while ($l = <>) { print $l; };
188 ' < /etc/postfix/main.cf.gforge-new > $tmp1
189 grep -q '^[[:space:]]*relay_domains' $tmp1 && perl -i -e '
190 chomp($sys_lists_host=`/usr/share/gforge/bin/forge_get_config lists_host`);
191 while (($l = <>) !~ /^\s*relay_domains/) {
195 $l =~ /^(\s*relay_domains\s*=\s*)(\S.*)/ ;
198 $dests =~ s/, $sys_lists_host// ;
199 $l = $head . $dests ;
201 while ($l = <>) { print $l; };
203 tmp2=$(mktemp /tmp/$pattern)
204 # Second, kill our forwarding rules
208 if ($l =~ /^### BEGIN GFORGE BLOCK -- DO NOT EDIT ###/) {
211 print $l unless $in_sf_block ;
212 $in_sf_block = 0 if ($l =~ /^### END GFORGE BLOCK ###/) ;
215 while ($l = <>) { print $l; };
218 cat $tmp2 > /etc/postfix/main.cf.gforge-new
226 echo "Usage: $0 {configure|configure-files|purge|purge-files}"