# $Id: Portfile 58230 2009-09-24 16:45:22Z ryandesign@macports.org $

PortSystem	1.0

name			sympa
version			5.4.7
categories		mail
maintainers		markd
platforms		darwin

description		Sympa - Mailing List Manager with LDAP support

long_description	An advanced perl-based mail list manager with a web interface \
			that supports LDAP authentication and LDAP extraction of \
			list subscribers and owners.

homepage		http://www.sympa.org

master_sites		http://www.sympa.org/distribution/ \
			http://www.sympa.org/distribution/old/

checksums		md5 74fb5b0c972919a2813cd6aca2d9224f
default_variants	+server

patchfiles		patch-configure.in \
			patch-Makefile.in \
			patch-sympa.generic \
			patch-src_alias_manager.pl

depends_lib		path:bin/mysql_config5:mysql5 \
			port:apache2 \
			port:mod_fcgid \
			port:openssl \
			port:postfix \
			port:p5-libwww-perl \
			port:p5-archive-zip \
			port:p5-convert-asn1 \
			port:p5-pathtools \
			port:p5-dbi \
			port:p5-dbd-mysql \
			port:p5-mailtools \
			port:p5-io-stringy \
			port:p5-mime-tools \
			port:p5-mime-charset \
			port:p5-mime-encwords \
			port:p5-crypt-openssl-x509 \
			port:p5-fcgi \
			port:p5-libintl-perl \
			port:p5-template-toolkit \
			port:p5-crypt-ciphersaber \
			port:p5-mhonarc \
			port:p5-regexp-common \
			port:p5-xml-libxml \
			port:p5-io-socket-ssl \
			port:p5-soap-lite \
			port:p5-perl-ldap \
			port:p5-html-format \
			port:p5-html-stripscripts-parser

configure.args		--with-bindir=${prefix}/bin/${name} \
                        --with-sbindir=${prefix}/bin/${name} \
                        --with-libexecdir=${prefix}/libexec/${name} \
                        --with-libdir=${prefix}/lib/${name} \
\
                        --with-cgidir=${prefix}/share/${name}/cgi-bin \
                        --with-localedir=${prefix}/share/locale \
                        --with-scriptdir=${prefix}/share/${name}/script \
                        --with-sampledir=${prefix}/share/${name}/sample \
                        --with-docdir=${prefix}/share/doc/${name} \
			--with-datadir=${prefix}/share/${name} \
\
                        --with-confdir=${prefix}/etc/${name} \
                        --with-etcdir=${prefix}/etc/${name} \
                        --with-initdir=${prefix}/share/${name} \
\
                        --with-expldir=${prefix}/var/${name}/expl \
                        --with-piddir=${prefix}/var/${name} \
                        --with-lockdir=${prefix}/var/${name}/lock \
                        --with-spooldir=${prefix}/var/${name}/spool \
\
                        --with-mandir=${prefix}/man \
                        --with-perl=${prefix}/bin/perl \
                        --with-openssl=${prefix}/bin/openssl \
\
                        --with-user=www \
                        --with-group=www \
                        --with-sendmail_aliases=${prefix}/etc/${name}/sympa_aliases \
                        --with-virtual_aliases=${prefix}/etc/${name}/sympa_virtual \
                        --with-newaliases=${prefix}/bin/newaliases \
                        --with-postmap=${prefix}/sbin/postmap

variant postgresql {
    depends_lib-append      port:p5-dbd-pg
    depends_lib-delete      port:p5-dbd-mysql
}

variant server  {
# This variant doesn't do anything in this port, it only exists to trigger the server
# variant in the mysql5 port.
}

# Create a startupitem to start/stop the server
    startupitem.create    yes
    startupitem.start    "${prefix}/share/${name}/sympa"
    startupitem.stop     "${prefix}/share/${name}/sympa"


pre-destroot {
# Use sympa.generic startup script and fix paths
        reinplace "s|PATH=/usr/bin:/bin:/usr/sbin:/sbin|PATH=${prefix}/bin:${prefix}/sbin:/usr/bin:/bin:/usr/sbin:/sbin|g" \
                "${worksrcpath}/src/etc/script/sympa.generic"

	reinplace "s|/dist/sympa/run|${prefix}/var/${name}|g" \
                "${worksrcpath}/src/etc/script/sympa.generic"

	system "mv ${worksrcpath}/src/etc/script/sympa.generic ${worksrcpath}/src/etc/script/sympa"
}

post-destroot {
# Flag wwsympa.fcgi as executable
	system "chmod ug+x ${destroot}${prefix}/share/sympa/cgi-bin/wwsympa.fcgi"
# Create empty directories named in sympa.conf & wwsympa.conf not created by Sympa install
	xinstall -m 755 -d ${destroot}${prefix}/var/${name}/expl
	xinstall -m 755 -d ${destroot}${prefix}/var/log/${name}
   # Incoming spool directories
	xinstall -m 755 -d ${destroot}${prefix}/var/${name}/spool/msg
	xinstall -m 755 -d ${destroot}${prefix}/var/${name}/spool/bounce
   # Storage directories
	xinstall -m 755 -d ${destroot}${prefix}/var/${name}/arc
	xinstall -m 755 -d ${destroot}${prefix}/var/${name}/bounce

# Create sympa.log and sympa_aliases files
	system "touch ${destroot}${prefix}/var/log/${name}/${name}.log"
	system "touch ${destroot}${prefix}/etc/${name}/sympa_aliases"
	system "chown www:www ${destroot}${prefix}/bin/${name}/*"
	system "chown www:www ${destroot}${prefix}/etc/${name}/*"

# Fix alias_manager.pl since the alias_wrapper seems not to work
	reinplace "s|${prefix}/bin/${name}/aliaswrapper|${prefix}/bin/newaliases|g" \
                "${destroot}${prefix}/bin/${name}/alias_manager.pl"

# Keep these empty directories
	destroot.keepdirs \
		${destroot}${prefix}/var/${name}/expl \
		${destroot}${prefix}/var/log/${name} \
		${destroot}${prefix}/var/${name}/spool/msg \
		${destroot}${prefix}/var/${name}/spool/bounce \
		${destroot}${prefix}/var/${name}/arc \
		${destroot}${prefix}/var/${name}/bounce

# Fix permissions for arc directory
	system "chown www:www ${destroot}${prefix}/var/${name}/arc"

# Set sympa.conf variables (this file uses tabs as separators)
	reinplace "s|#openssl	/usr/local/bin/openssl|openssl	${prefix}/bin/openssl|g" \
                "${destroot}${prefix}/etc/sympa/sympa.conf"

        reinplace "s|#db_type	mysql|db_type	mysql|g" \
                "${destroot}${prefix}/etc/sympa/sympa.conf"

        reinplace "s|#db_name	sympa|db_name	sympa|g" \
                "${destroot}${prefix}/etc/sympa/sympa.conf"

        reinplace "s|#db_host	localhost|db_host	localhost|g" \
                "${destroot}${prefix}/etc/sympa/sympa.conf"

        reinplace "s|#db_user	sympa|db_user	sympa|g" \
                "${destroot}${prefix}/etc/sympa/sympa.conf"

	system "echo 'db_options  mysql_socket=${prefix}/var/run/mysql5/mysqld.sock' >> ${destroot}${prefix}/etc/sympa/sympa.conf"

# Set wwsympa.conf variables
	reinplace "s|${prefix}/arc|${prefix}/var/${name}/arc|g" \
                "${destroot}${prefix}/etc/${name}/wwsympa.conf"

	reinplace "s|${prefix}/bounce|${prefix}/var/${name}/bounce|g" \
                "${destroot}${prefix}/etc/${name}/wwsympa.conf"

	reinplace "s|/usr/bin/mhonarc|${prefix}/bin/mhonarc|g" \
                "${destroot}${prefix}/etc/${name}/wwsympa.conf"

	reinplace "s|#openssl	/usr/local/bin/openssl|openssl	${prefix}/bin/openssl|g" \
                "${destroot}${prefix}/etc/${name}/wwsympa.conf"
}

post-activate {

# get rid of .turd files created by destroot.keepdirs because they cause problems in Sympa queues
        system "rm ${prefix}/var/${name}/spool/msg/.turd_sympa"
        system "rm ${prefix}/var/${name}/spool/bounce/.turd_sympa"
        system "rm ${prefix}/var/${name}/bounce/.turd_sympa"
        system "rm ${prefix}/var/${name}/arc/.turd_sympa"

ui_msg "\n **** To complete Sympa installation ****

You must read the documentation at ${prefix}/share/doc/${name}/index.html for full
Sympa configuration information, however the installation steps are roughly as shown below.


1) Setup MySQL and prepare it for Sympa (for PostgreSQL, see documentation)
   Configure MySQL (new MySQL installs)
	sudo -u mysql ${prefix}/lib/mysql5/bin/mysql_install_db

   Start MySQL:
        sudo ${prefix}/share/mysql5/mysql/mysql.server start

   Set MySQL to start at system boot (optional)
	sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

   Set a MySQL root password:
	Follow the instructions that were given after you executed 'mysql_install_db' above.

   Create a Sympa MySQL user ...
	mysql5 -u root -p (login with new root password when prompted)
	mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on sympa.* to sympa@localhost;
        mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on sympa.* to sympa;
	mysql> quit;

   Create the Sympa database:
	cat ${prefix}/share/sympa/script/create_db.mysql | mysql5 -u root -p sympa

   Verify Sympa DB:
	mysql5 -u root -p
	mysql> use sympa;
	mysql> show tables;
	mysql> exit;

   NOTE: MySQL must start before Apache because of wwsympa.fcgi


2) Setup Apache 2 & FastCGI
	cd ${prefix}/apache2/conf
	sudo cp httpd.conf.sample httpd.conf

   Modify the ${prefix}/apache2/conf/httpd.conf file

   Add directives and ScriptAlias:
        IPCCommTimeout 120
        MaxProcessCount 2

        <Location /sympa>
          SetHandler fcgid-script
        </Location>

	ScriptAlias /sympa ${prefix}/share/sympa/cgi-bin/wwsympa.fcgi

   Start Apache 2: (Turn off personal web sharing first!)
	sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist


   NOTE: The Apache user and group must be the same as the file wwsympa.fcgi.
	 Sympa files are owned by user/group 'www' so the apache user and group
	 must be www unless you chown Sympa files to something else.


3) Enable Postfix (not covered), setup Sympa robot aliases, & list alias config
   Robot aliases:
	sympa: \"| ${prefix}/bin/sympa/queue sympa@mydomain.org\"
	listmaster: \"| ${prefix}/bin/sympa/queue listmaster@mydomain.org\"
	bounce+*: \"| ${prefix}/bin/sympa/bouncequeue sympa@mydomain.org\"
	sympa-request: <sympa administrator's address>
	sympa-owner: <sympa administrator's address>

   Activate the robot aliases with the command \"sudo newaliases\"

   List alias config: (automatic list aliases)
   Add these statements to /etc/postfix/main.cf
	alias_maps = hash:/etc/aliases,hash:${prefix}/etc/${name}/sympa_aliases
	alias_database = hash:/etc/aliases,hash:${prefix}/etc/${name}/sympa_aliases

   Activate the new configuration with the command \"sudo postfix reload\"


4) Edit ${prefix}/etc/sympa/sympa.conf variables
	domain
	listmaster
	email
	db_password
	wwsympa_url


5) Edit ${prefix}/etc/sympa/wwsympa.conf variables
	title
	default_home


6) Add a statement to OS X's syslog.conf file to support Sympa log files

	local1.*       ${prefix}/var/log/sympa/sympa.log


7) Start the Sympa daemon
	sudo launchctl load -w /Library/LaunchDaemons/org.macports.sympa.plist


8) Have Sympa generate a listmaster password
	Go to http://localhost/sympa. Click the \"First login ?\" link, then
	enter the listmaster address you set in the sympa.conf file, and
	click \"Send me my password\" and retrieve the password in your inbox.


9) Login to WWSympa at http://localhost/sympa with the listmaster address
   and then change the password and setup your lists.

-------------------------------------------------
File Locations:

Executable files -> ${prefix}/bin/${name}
CGI directory -> ${prefix}/share/${name}/cgi-bin
Configuration files -> ${prefix}/etc/${name}
Sample files -> ${prefix}/share/${name}/sample
Documentation directory -> ${prefix}/share/doc/${name}
Expl (also spool/pid/bounce/archive) directories -> ${prefix}/var/${name}
\n"

}
