extranet/scripts/build/configure.php
2016-01-14 11:06:51 +00:00

131 lines
4.2 KiB
PHP

<?php
// --- Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../../application'));
// --- Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// --- Composer autoload
require_once realpath(__DIR__ . '/../../vendor/autoload.php');
try {
$opts = new Zend_Console_Getopt(
//Options
array(
'help|?' => "Affiche les informations d'utilisation",
'install=s' => "Installe et configure",
'incron' => "Create incron file",
'cron' => "Create cron file",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if(isset($opts->help))
{
echo $opts->getUsageMessage();
exit;
}
if(isset($opts->install))
{
echo date('Y-m-d H:i:s')." - Démarrage de la configuration.\n";
// --- Copy configuration
$configDir = realpath(dirname(__FILE__)).'/profil';
$appconfigDir = APPLICATION_PATH.'/configs';
$profil = $opts->install;
if ($profil == 'local') {
echo date('Y-m-d H:i:s')." - Local dev, copie scripts/build/profil/local/application.ini to application/configs/.\n";
} else {
$result = copy($configDir.'/'.$profil.'/application.ini', $appconfigDir.'/application.ini');
if ($result !== true) {
echo date('Y-m-d H:i:s')." - Impossible de copier la configuration.\n";
exit(1);
}
}
// --- Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$c = new Zend_Config($application->getOptions());
//Create data directory and all his children
$dirToCreate = array(
APPLICATION_PATH.'/../data',
APPLICATION_PATH.'/../data/cache',
APPLICATION_PATH.'/../data/cache/giant',
APPLICATION_PATH.'/../data/files',
APPLICATION_PATH.'/../data/infogreffe',
APPLICATION_PATH.'/../data/log',
APPLICATION_PATH.'/../data/rss',
APPLICATION_PATH.'/../data/sessions',
APPLICATION_PATH.'/../data/wsdl',
);
foreach ($dirToCreate as $dir) {
if ( !file_exists($dir) ) {
mkdir($dir);
}
}
if ( substr(strtoupper(PHP_OS),0,3) == 'WIN' ) {
echo "Windows OS : Créer les liens symboliques pour l'impression. Voir script.";
echo "\n";
} else {
//Création des liens symboliques pour l'impression
passthru('ln -vsf '.APPLICATION_PATH.'/../public/themes/default/images '.$c->profil->path->pages.'/themes/default/images');
passthru('ln -vsf '.APPLICATION_PATH.'/../public/themes/default/scripts '.$c->profil->path->pages.'/themes/default/scripts');
passthru('ln -vsf '.APPLICATION_PATH.'/../data/pages/imgcache'.' '.$c->profil->path->pages.'/fichier/imgcache');
passthru('ln -vsf '.$c->profil->path->data.'/logos '.$c->profil->path->pages.'/fichier/logo');
//Modification des permissions
passthru('chown -R www-data: '.APPLICATION_PATH.'/../');
}
echo date('Y-m-d H:i:s')." - End.\n";
}
if ( $opts->incron ) {
echo "Création configuration incron.\n";
if ( !file_exist('/etc/incron.d') ) {
echo "incron is not install !\n";
exit;
}
//Send bilanclient
file_put_contents('/etc/incron.d/bilanclient', $c->profil->path->data . "/bilanclient IN_CLOSE_WRITE php /home/vhosts/extranet/scripts/jobs/sendBilanClient.php --file $#");
echo "Don't forget to restart incron. sudo service incron restart.\n";
echo "Fin de la configuration.\n";
}
if ( $opts->cron ) {
echo "Création configuration cron.\n";
if ( !file_exist('/etc/cron.d') ) {
echo "cron is not install !\n";
exit;
}
//AltiScore
file_put_contents('/etc/cron.d/altiscore', "# AltiScore");
file_put_contents('/etc/cron.d/altiscore', "00 04 * * 1-5 www-data php /home/vhosts/extranet/scripts/jobs/getAltiScore.php --cron >> /home/vhosts/data/log/altiscore.log", FILE_APPEND);
echo "Don't forget to restart cron. sudo service cron restart.";
echo "End.\n";
}