1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#! /bin/sh
#
# $Id: install-postfix.sh 5604 2006-07-21 13:07:52Z lo-lan-do $
#
# Configure Postfix for GForge
# Julien Goodwin
# Based of install-exim.sh by: Christian Bayle, Roland Mas, debian-sf (GForge for Debian)
set -e
if [ $(id -u) != 0 ] ; then
echo "You must be root to run this, please enter passwd"
exec su -c "$0 $1"
fi
case "$1" in
configure-files)
cp -a /etc/aliases /etc/aliases.gforge-new
# Redirect "noreply" mail to the bit bucket (if need be)
noreply_to_bitbucket=$(perl -e'require "/etc/gforge/local.pl"; print "$noreply_to_bitbucket\n";')
if [ "$noreply_to_bitbucket" = "true" ] ; then
if ! grep -q "^noreply:" /etc/aliases.gforge-new ; then
echo "### Next line inserted by GForge install" >> /etc/aliases.gforge-new
echo "noreply: /dev/null" >> /etc/aliases.gforge-new
fi
fi
# Redirect "gforge" mail to the site admin
server_admin=$(perl -e'require "/etc/gforge/local.pl"; print "$server_admin\n";')
if ! grep -q "^gforge:" /etc/aliases.gforge-new ; then
echo "### Next line inserted by GForge install" >> /etc/aliases.gforge-new
echo "gforge: $server_admin" >> /etc/aliases.gforge-new
fi
cp -a /etc/postfix/main.cf /etc/postfix/main.cf.gforge-new
perl -pi -e's/SOURCEFORGE_DOMAINS/GFORGE_DOMAINS/;' \
-e's/BEGIN SOURCEFORGE BLOCK -- DO NOT EDIT/BEGIN GFORGE BLOCK -- DO NOT EDIT/;' \
-e's/END SOURCEFORGE BLOCK/END GFORGE BLOCK/;' /etc/postfix/main.cf.gforge-new
pattern=$(basename $0).XXXXXX
tmp1=$(mktemp /tmp/$pattern)
# First, get the list of local domains right - add gforge domains to 'mydestination'
perl -e '
require ("/etc/gforge/local.pl") ;
my $l;
while (($l = <>) !~ /^\s*mydestination/) { print $l; };
chomp $l;
$l .= ", users.$domain_name" unless ($l =~ /^[^#]*users.$domain_name/);
$l .= ", $sys_lists_host" unless ($l =~ /^[^#]*$sys_lists_host/);
print "$l\n";
while ($l = <>) { print $l; };
' < /etc/postfix/main.cf.gforge-new > $tmp1
tmp2=$(mktemp /tmp/$pattern)
# Second, insinuate our forwarding rules in the directors section
perl -e '
require ("/etc/gforge/local.pl") ;
my $gf_block;
my $l;
my $seen_gf_block;
my $seen_virtual_maps;
$gf_block = "### BEGIN GFORGE BLOCK -- DO NOT EDIT ###
#You may move this block around to accomodate your local needs as long as you
# keep it in an appropriate position, where \"appropriate\" is defined by you.
pgsql_gforge_users_hosts = $sys_dbhost
pgsql_gforge_users_user = gforge_mta
pgsql_gforge_users_password =
pgsql_gforge_users_dbname = $sys_dbname
pgsql_gforge_users_domain = users.$domain_name
pgsql_gforge_users_select_field = email
pgsql_gforge_users_table = mta_users
pgsql_gforge_users_where_field = login
pgsql_gforge_lists_hosts = $sys_dbhost
pgsql_gforge_lists_user = gforge_mta
pgsql_gforge_lists_password =
pgsql_gforge_lists_dbname = $sys_dbname
pgsql_gforge_lists_domain = lists.$domain_name
pgsql_gforge_lists_select_field = post_address
pgsql_gforge_lists_table = mta_lists
pgsql_gforge_lists_where_field = list_name
### END GFORGE BLOCK ###
";
$seen_gf_block = 0;
$seen_vritual_maps = 0;
while ($l = <>) {
if ($l =~ /^\s*virtual_maps/) {
chomp $l;
$l .= ", pgsql:pgsql_gforge_users" unless ($l =~ /^[^#]*pgsql:pgsql_gforge_users/);
$l .= ", pgsql:pgsql_gforge_lists" unless ($l =~ /^[^#]*pgsql:pgsql_gforge_lists/);
print "$l\n";
$seen_virtual_maps = 1;
} else {
if ($l =~ /^\s*\#\#\# BEGIN GFORGE BLOCK \-\- DO NOT EDIT \#\#\#/) {
$seen_gf_block = 1;
} else {
print $l;
};
};
};
if ($seen_gf_block == 0) {
print $gf_block;
};
if ($seen_virtual_maps == 0) {
print "### GFORGE ADDITION - The following line can be moved and this line removed ###\n";
print "virtual_maps = pgsql:pgsql_gforge_users, pgsql:pgsql_gforge_lists\n";
};
' < $tmp1 > $tmp2
rm $tmp1
cat $tmp2 > /etc/postfix/main.cf.gforge-new
rm $tmp2
;;
configure)
[ -x /usr/bin/newaliases ] && newaliases
;;
purge-files)
pattern=$(basename $0).XXXXXX
tmp1=$(mktemp /tmp/$pattern)
cp -a /etc/aliases /etc/aliases.gforge-new
# Redirect "noreply" mail to the bit bucket (if need be)
noreply_to_bitbucket=$(perl -e'require "/etc/gforge/local.pl"; print "$noreply_to_bitbucket\n";')
if [ "$noreply_to_bitbucket" = "true" ] ; then
grep -v "^noreply:" /etc/aliases.gforge-new > $tmp1
cat $tmp1 > /etc/aliases.gforge-new
fi
rm -f $tmp1
cp -a /etc/postfix/main.cf /etc/postfix/main.cf.gforge-new
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
tmp1=$(mktemp /tmp/$pattern)
# First, replace the list of local domains
perl -e '
require ("/etc/gforge/local.pl") ;
while (($l = <>) !~ /^\s*mydestination/) {
print $l;
};
chomp $l ;
$l =~ /^(\s*mydestination\s*=\s*)(\S.*)/ ;
$head = $1 ;
$dests = $2 ;
$dests =~ s/, users.$domain_name// ;
$dests =~ s/, $sys_lists_host// ;
$l = $head . $dests ;
print "$l\n" ;
while ($l = <>) { print $l; };
' < /etc/postfix/main.cf.gforge-new > $tmp1
tmp2=$(mktemp /tmp/$pattern)
# Second, kill our forwarding rules
perl -e '
$in_sf_block = 0 ;
while ($l = <>) {
if ($l =~ /^### BEGIN GFORGE BLOCK -- DO NOT EDIT ###/) {
$in_sf_block = 1 ;
}
print $l unless $in_sf_block ;
$in_sf_block = 0 if ($l =~ /^### END GFORGE BLOCK ###/) ;
};
print $l ;
while ($l = <>) { print $l; };
' < $tmp1 > $tmp2
rm $tmp1
cat $tmp2 > /etc/postfix/main.cf.gforge-new
rm $tmp2
;;
purge)
;;
*)
echo "Usage: $0 {configure|configure-files|purge|purge-files}"
exit 1
;;
esac
|