sdsphinx/configure.php
2012-04-23 08:50:51 +00:00

98 lines
2.2 KiB
PHP

#!/usr/bin/php
<?php
// Paramètres
if ( count($argv)<1 || in_array($argv[1], array('--help', '-help', '-h', '-?')) ) {
?>
Utilisation : <?php echo $argv[0]; ?> [actions]
Installation :
- install list
- install version
Configuration :
- config initscript
- config logrotate
- config list
- config server *.conf
<?php
exit;
}
$hostname = exec('echo $HOSTNAME');
$SPHINX_VERSION = array(
'0.9.9' => array('archive'=>'sphinx-0.9.9.tar.gz', 'dir'=>'sphinx-0.9.9'),
'1.10' => array('archive'=>'sphinx-1.10-beta.tar.gz', 'dir'=>'sphinx-1.10-beta'),
'2.0.2' => array('archive'=>'sphinx-2.0.2-beta.tar.gz', 'dir'=>'sphinx-2.0.2-beta'),
'2.0.3' => array('archive'=>'sphinx-2.0.3-release.tar.gz', 'dir'=>'sphinx-2.0.3-release'),
'2.0.4' => array('archive'=>'sphinx-2.0.4-release.tar.gz', 'dir'=>'sphinx-2.0.4-release'),
);
/**
* Nécessaire :
* ============
* GCC : gcc g++
* MySQL : libmysqld-dev
*
* tree
*
*/
if ($argv[1]=='install')
{
//Version
if (!array_key_exists($argv[2], $SPHINX_VERSION)){
exit;
}
$version = $argv[2];
//Vérification nécessaires
//Compilation
$cmd = array();
$cmd[] = "tar xzvf ".$SPHINX_VERSION[$version]['archive'];
$cmd[] = "cp libstemmer_c.tgz ".$SPHINX_VERSION[$version]['dir']."/";
$cmd[] = "cd ".$SPHINX_VERSION[$version]['dir']."/";
$cmd[] = "tar xzvf libstemmer_c.tgz";
$cmd[] = "./configure --with-libstemmer --prefix=/usr/local/sphinx";
$cmd[] = "make";
$cmd[] = "make install";
foreach($cmd as $c){
passthru($c);
}
}
if ($argv[1]=='config')
{
//Initscript
if ($argv[2]=='initscript') {
exec("cp -v initscript/sphinxsearch /etc/init.d/");
exit;
}
//Logrotate
if ($argv[2]=='logrotate') {
echo exec("which logrotate");
exec("cp -v logrotate/searchd /etc/logrotate.d/");
exit;
}
//Liste des configuration
if ($argv[2]=='list') {
echo passthru("tree config/".$hostname."/");
exit;
}
//Configuration
if (!file_exists("config/".$hostname."/".$argv[2])){
echo "Erreur\n"; exit;
}
$server = $argv[2];
$concat = '';
for($i=3;$i<count($argv);$i++){
$concat.= " config/".$hostname."/".$server."/".$argv[$i];
}
//@todo :
exec("cat config/".$hostname."/".$server."/sphinx.conf".$concat." > /usr/local/sphinx/etc/sphinx.conf");
}