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 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 chomp($sys_lists_host=`/usr/share/gforge/bin/forge_get_config lists_host`);
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 chomp($domain_name=`/usr/share/gforge/bin/forge_get_config web_host`);
73 chomp($sys_dbuser=`/usr/share/gforge/bin/forge_get_config database_user`);
74 chomp($sys_dbname=`/usr/share/gforge/bin/forge_get_config database_name`);
80 my $seen_transport_maps;
82 $gf_block = qq{### BEGIN GFORGE BLOCK -- DO NOT EDIT ###
83 # You may move this block around to accomodate your local needs as long as you
84 # keep it in an appropriate position, where \"appropriate\" is defined by you.
86 pgsql_gforge_users_hosts = unix:/var/run/postgresql
87 pgsql_gforge_users_user = ${sys_dbuser}_mta
88 pgsql_gforge_users_password = ${sys_dbuser}_mta
89 pgsql_gforge_users_dbname = $sys_dbname
90 pgsql_gforge_users_domain = users.$domain_name
91 pgsql_gforge_users_query = SELECT email FROM mta_users WHERE login = '\''%u'\''
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 "`/usr/share/gforge/bin/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=`/usr/share/gforge/bin/forge_get_config noreply_to_bitbucket`
163 if [ "$noreply_to_bitbucket" = "true" ] ; 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 chomp($domain_name=`/usr/share/gforge/bin/forge_get_config web_host`);
177 chomp($sys_lists_host=`/usr/share/gforge/bin/forge_get_config lists_host`);
179 last if l =~ /^\s*mydestination/) ;
183 if ($l =~ /^(\s*mydestination\s*=\s*)(\S.*)/) {
186 $dests =~ s/, users.$domain_name// ;
187 $dests =~ s/, $sys_lists_host// ;
188 $l = $head . $dests ;
191 while ($l = <>) { print $l; };
192 ' < /etc/postfix/main.cf.gforge-new > $tmp1
193 grep -q '^[[:space:]]*relay_domains' $tmp1 && perl -i -e '
194 chomp($sys_lists_host=`/usr/share/gforge/bin/forge_get_config lists_host`);
195 while (($l = <>) !~ /^\s*relay_domains/) {
199 $l =~ /^(\s*relay_domains\s*=\s*)(\S.*)/ ;
202 $dests =~ s/, $sys_lists_host// ;
203 $l = $head . $dests ;
205 while ($l = <>) { print $l; };
207 tmp2=$(mktemp /tmp/$pattern)
208 # Second, kill our forwarding rules
212 if ($l =~ /^### BEGIN GFORGE BLOCK -- DO NOT EDIT ###/) {
215 print $l unless $in_sf_block ;
216 $in_sf_block = 0 if ($l =~ /^### END GFORGE BLOCK ###/) ;
219 while ($l = <>) { print $l; };
222 cat $tmp2 > /etc/postfix/main.cf.gforge-new
230 echo "Usage: $0 {configure|configure-files|purge|purge-files}"