# $Id: Portfile,v 1.3 2006/06/02 20:07:06 markd Exp $

PortSystem	1.0

name			cacti
version			0.8.6h
revision		1
categories		net
maintainers		markd@opendarwin.org
platforms		darwin

description		Cacti is a complete RRDtool network graphing solution.

long_description	Cacti is a complete network graphing solution designed \
                        to harness the power of RRDtool's data storage and \
                        graphing functions.

homepage		http://www.cacti.net					
master_sites		http://www.cacti.net/downloads/ \
			sourceforge:cacti

checksums		${distname}${extract.suffix} md5 5f6100b525b5b29e81f43cc7c55f4000 \
			fix_search_session_clear_issue.patch md5 20dd3bd4688e95490d649768e9191f3a \
			fix_sql_syntax_related_to_default_rra_id.patch md5 4ab874541b292e07eacbbce6dc505717 \
			mysql_5x_strict.patch md5 f5ed4305cc0b388e18be4e85b2534f1a \
			nth_percentile_empty_return_set_issue.patch md5 b64160dd736d404eb1b2537e9c80199d

patchfiles		fix_search_session_clear_issue.patch \
			fix_sql_syntax_related_to_default_rra_id.patch \
			mysql_5x_strict.patch \
			nth_percentile_empty_return_set_issue.patch

depends_lib		port:mysql5 \
			port:rrdtool

use_configure   no
build {}
set cactidir ${prefix}/share/cacti

pre-fetch {
        ui_msg "\n

                   ************************************************
	           **** It is recommended that you pre-install ****
	           **** MySQL with the +server variant so    ****
	           **** MySQL will start at system boot.  To   ****
	           **** do so:				       ****

	              1) Cancel this install now with Cntrl-C.
	              2) Type \"port install mysql5 +server\"
	              3) Re-run the Cacti port install
	           ************************************************\n"
}

destroot {
	xinstall -m 755 -d ${destroot}${cactidir}
	system "cp -R ${worksrcpath}/* ${destroot}${cactidir}"
}

post-activate {
                
ui_msg "\n **** To complete the Cacti OS X installation ****
                
To complete the Cacti installation follow the steps below.  Read the documentation
at http://www.cacti.net/documentation.php for operational instructions.


1) Install PHP (not covered) including command line interface (CLI) support.
	After PHP is installed, make sure that your httpd.conf file has these
	lines uncommented for CLI support.

	'LoadModule php4_module ...'	(Apache 1 & 2)
	'AddModule mod_php4.c'		(Apache 1)

   Set mysql.default_socket path to ${prefix}/var/run/mysql5/mysqld.sock in file:
        ./phpx/lib/php.ini (in /usr/local, ${prefix}, or /Library depending on PHP package)


2) Set Cacti permissions.
   sudo chown -R <cacti-user>:<cacti-group> ${prefix}/share/${name}/

3) Setup MySQL and prepare it for Cacti.
   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.darwinports.mysql5.plist

   NOTE: MySQL must have been installed with the +server variant in order to
      use launchctl to run MySQL at system boot.

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

   Create a cacti MySQL user and cacti database.
	mysql5 -u root -p (login with new root password when prompted)
        mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti@localhost;
        mysql> grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti;
        mysql> SET PASSWORD FOR cacti@localhost = OLD_PASSWORD('<cactidb-pwd>');
	mysql> create database cacti;
	mysql> exit;

   Import the cacti database.
	sudo cat ${cactidir}/cacti.sql | mysql5 -u root -p cacti (cacti is the db name)

   Verify the Cacti Database.
	mysql5 -u root -p
	mysql> use cacti;
	mysql> show tables;
	mysql> exit;

4) Edit ${cactidir}/include/config.php to match your MySQL information.

	\$database_type = \"mysql\";
	\$database_default = \"cacti\";
	\$database_hostname = \"localhost\";
	\$database_username = \"cacti\";
	\$database_password = \"<my-cacti-password>\";

5) Place a symlink for Cacti inside your Apache document root.

	ln -s ${cactidir}  <Apache-docroot>/cacti

6) Edit the Cacti user's crontab file.
	sudo -u <cactiuser> crontab -e

  Insert the crontab entry below:
	0,5,10,15,20,25,30,35,40,45,50,55 * * * * ${cactidir}/poller.php > /dev/null 2>&1

7) Go to http://localhost/cacti/install/index.php.
	The default login information is admin/admin.  Select 'New Install' and
	then enter the SNMP and RRDtool paths (see below) and click 'Finish'.
	You may now use Cacti at http://localhost/cacti/index.php.

Paths:
	snmpwalk binary path: /usr/bin/snmpwalk
	snmpget binary path: /usr/bin/snmpget

	RRDtool binary path: ${prefix}/bin/rrdtool
	PHP binary path: /usr/bin/php (or appropriate PHP path)


\n"

}
