# $Id: Portfile 62587 2010-01-11 18:34:48Z markd@macports.org $

PortSystem	1.0

name			cacti
version			0.8.7e
revision		1
categories		net
maintainers		markd
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/:cacti
use_zip			yes

distfiles		${distname}${extract.suffix}:cacti
checksums		${distname}${extract.suffix} md5 b5eb2f5c512959417d51535f37d4e97c

depends_lib		path:bin/mysql_config5:mysql5 \
			port:rrdtool

use_configure   no
build {}

set cactiversion 0.8.7e
set pluginversion 2.6
set cactidir ${prefix}/share/cacti

variant plugins description {The Plugin Architecture for Cacti} {
	master_sites-append http://mirror.cactiusers.org/downloads/plugins:plugins
	distfiles-append cacti-plugin-${cactiversion}-PA-v${pluginversion}${extract.suffix}:plugins
	checksums-append cacti-plugin-${version}-PA-v${pluginversion}${extract.suffix} md5 b337a2d569f8b387786fafc9f3d83a3f
}

destroot {
# Copy Cacti files
	file mkdir ${destroot}${cactidir}
	system "cp -R ${worksrcpath}/* ${destroot}${cactidir}"

# Copy PA architecture files
	if { [variant_isset plugins] } {
#	system "cd ${worksrcpath} && patch -p1 -N -F 3 < ${workpath}/cacti-plugin-${version}-PA-v${pluginversion}.diff"
	system "cp -R ${workpath}/cacti-plugin-arch/files-${version}/* ${destroot}${cactidir}"
	}
}

post-activate {

ui_msg "\n **** To complete the Cacti 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 and MySQL 5 (not covered).  These instructions assume MySQL 5 was
   installed from MacPorts.

   Check to make sure the PHP variable \"mysql.default_socket\" is set to path
   ${prefix}/var/run/mysql5/mysqld.sock by viewing the output of this terminal command:
	php -i

   If not, locate the php.ini file for your version of PHP and type the path there.


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.macports.mysql5.plist

   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:
	*/5 * * * * ${prefix}/bin/php ${cactidir}/poller.php > /dev/null 2>&1


8) If you installed Cacti with the 'plugins' variant for Cacti Plugin Architecture support,
   you must perform these additional steps.

   a) Import the PA schema.
	cd ${cactidir}
	sudo cat ${cactidir}/pa.sql | mysql5 -u root -p cacti (cacti is the db name)

   b) Download the particular Cacti plugin(s) you want and copy their folders to ${cactidir}/plugins/<plugin-dir>/.
      For example:
	${cactidir}/plugins/weathermap/

   c) Edit ${cactidir}/include/global.php - modify the url_path to reflect Cacti's default URL
      and add an entry to load each plugin you install; the weathermap plugin is an example:

	\$config\['url_path'\] = '/cacti/';

	\$plugins = array();
	\$plugins[] = 'weathermap';

   d) Enable the plugin in the Cacti web interface; this creates a top-level tab for the plugin in the Cacti interface
	Console -> User Management  (select a Cacti user and check the 'View Weathermaps' checkboxes)


7) Go to http://localhost/cacti/install/index.php.
	The default user/password is admin/admin.  Select 'New Install', enter
	the paths for SNMP / RRDtool / PHP (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: ${prefix}/bin/php (if not using MacPorts PHP, use appropriate path)

\n"

}
