Location: PHPKode > projects > GForge > gforge-as-571-src/check-deps.php
#!/usr/bin/php -f
<?php
/**
 * GForge Installation Dependencies Check
 *
 * Copyright (c) 2005-2008 GForge, LLC
 *
 * May not be modified or redistributed without written permission of GForge Group
 *
 */

define ('GREEN', "\033[01;32m" );
define ('NORMAL', "\033[00m" );
define ('RED', "\033[01;31m" );

$notfound = array();

$binaries = array('cvs', 'psql', 'svn', 'ssh', 'wget', 'pdftotext', 'wvText');
$functions = array('PostgreSQL'=>'pg_query', 'GD'=>'imagecreate', 'LDAP'=>'ldap_connect', 'MultiByte'=>'mb_eregi');
$classes = array('DOMDocument');
$pmodules = array('URI');

$mailman = array('/usr/lib/mailman', '/var/lib/mailman', '/usr/local/mailman', '/usr/lib/cgi-bin/mailman');
$apache = array('/etc/init.d/httpd', '/etc/init.d/httpd2', '/etc/init.d/apache2', '/etc/init.d/cswapache2');

show("-=# GForge Dependencies Checker #=-\n");

show('Checking PHP version... ', false);
if (substr(phpversion(), 0, 1) == 5) {
	echo 'Ok (' . phpversion() . ")\n";
} else {
	echo 'Too old (' . phpversion() . ")\n";
	exit(1);
}

// Checking for binaries
foreach ($binaries as $bin) {
	show('Checking... '. $bin);
	if (!which($bin)) {
		echo RED."Not Found".NORMAL."\n";
		$notfound[] = $bin;
	}
}

// Checking for Mailman
/*
$found_mailman = '';
show('Checking... mailman');
foreach ($mailman as $file) {
	if (file_exists($file)) {
		$found_mailman = $file;
		break;
	}
}
if ($found_mailman == '') {
	echo RED."Not Found".NORMAL."\n";
	$notfound[] = 'Mailman';
} else {
	echo "$found_mailman\n";
}
*/

// Checking for Apache
$found_apache = '';
show('Checking... apache');
foreach ($apache as $file) {
	if (file_exists($file)) {
		$found_apache = $file;
		break;
	}
}
if ($found_apache == '') {
	echo RED."Not Found".NORMAL."\n";
	$notfound[] = 'Apache';
} else {
	echo "$found_apache\n";
}

// Checking for needed PHP functions
foreach ($functions as $name => $fnc) {
	show('Checking PHP support for... '. $name);
	if (!function_exists($fnc)) {
		echo RED."Not Found".NORMAL."\n";
		$notfound[] = 'PHP '.$name;
	} else {
		echo "Found\n";
	}
}

// Checking for needed PHP classes
foreach ($classes as $cls) {
	show('Checking classes... '. $cls);
	if (!class_exists($cls)) {
		echo RED."Not Found".NORMAL."\n";
		$notfound[] = 'PHP-Class '.$cls;
	} else {
		echo "Found\n";
	}
}


/*foreach ($pmodules as $mod) {
	show('Checking Perl module... '. $mod);
	if (!run("perl -m{$mod} /dev/null &> /dev/null", true)) {
		$notfound[] = 'Perl-module '.$mod;
	}
}*/


/*
foreach ($pkgs as $pkg) {
	show('Checking... '. $pkg);
	if (!run('rpm -qa | grep ' . $pkg . '-')) {
		$notfound[] = $pkg;
	}
}
*/

if (count($notfound) > 0) {
	show("\nThe following dependencies were not found: " . implode(', ', $notfound));
	exit(1);
} else {
	show("\nAll dependencies seem to be installed");
	exit(0);
}

function show($text, $newLine = true) {
	$text = GREEN.$text .NORMAL;
	if ($newLine) {
		$text .= "\n";
	}
	echo $text;
}

function which($program, $show=false) {
	$out = array();
	$ret = '';
	exec("which $program", $out, $ret);
	if ($ret != 0) {
		return false;
	} else {
		if (isset($out[0])) {
			$err = strtolower("no $program in");
			$errLen = strlen($err);
			if (strtolower(substr($out[0], 0, $errLen)) == $err) {
				return false;
			} else {
				echo $out[0]."\n";
				return true;
			}
		} else {
			return false;
		}
	}
}

function run($command, $show=false) {
	$ret = '';
	system($command, $ret);
	var_dump($ret);
	echo "\n";
	if ($ret != 0) {
		if ($show) echo RED."Not Found".NORMAL."\n";
		return false;
	} else {
		if ($show) echo "Found\n";
		return true;
	}
}
?>
Return current item: GForge