Beispiel #1
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->logLine('Starting folder synchronization');
     $exclude = '';
     $include = '';
     if (isset($options['config-file'])) {
         $configDir = nbConfig::get('nb_plugins_dir') . '/nbFileSystemPlugin/config';
         $configFilename = $options['config-file'];
         $this->checkConfiguration($configDir, $configFilename);
     }
     if (isset($options['exclude-from']) && file_exists($options['exclude-from'])) {
         $exclude = ' --exclude-from \'' . $options['exclude-from'] . '\' ';
     }
     if (isset($options['include-from']) && file_exists($options['include-from'])) {
         $include = ' --include-from \'' . $options['include-from'] . '\' ';
     }
     $doit = isset($options['doit']) ? '' : '--dry-run';
     $delete = isset($options['delete']) ? '--delete' : '';
     // Trailing slash must be added after sanitize dir
     $sourceDir = nbFileSystem::sanitizeDir($arguments['source-dir']) . '/';
     $targetDir = nbFileSystem::sanitizeDir($arguments['target-dir']);
     $cmd = sprintf('rsync -rzChv %s %s %s %s %s %s', $doit, $include, $exclude, $delete, $sourceDir, $targetDir);
     $owner = isset($options['owner']) ? $options['owner'] : null;
     if ($owner) {
         $cmd = sprintf('sudo -u %s %s', $owner, $cmd);
     }
     if (!isset($options['doit'])) {
         $this->logLine('Executing command: ' . $cmd);
     }
     $this->executeShellCommand($cmd);
     $this->logLine('Folders synchronization completed');
     return true;
 }
Beispiel #2
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $timestamp = date('YmdHi', time());
     $sourceDir = nbFileSystem::sanitizeDir($arguments['source-dir']);
     $destinationDir = nbFileSystem::sanitizeDir($arguments['destination-dir']);
     $createDestinationDir = isset($options['create-destination-dir']);
     $archiveName = basename($sourceDir);
     $archiveDir = dirname($sourceDir);
     $filename = isset($options['filename']) ? $options['filename'] : sprintf('%s-%s.tar.gz', $archiveName, $timestamp);
     $this->logLine(sprintf('Archiving %s in %s/%s', $sourceDir, $destinationDir, $filename));
     if (!is_dir($sourceDir)) {
         throw new InvalidArgumentException("Source directory not found: " . $sourceDir);
     }
     if (!is_dir($destinationDir)) {
         if (!$createDestinationDir) {
             throw new InvalidArgumentException("Archive directory not found: " . $destinationDir);
         }
         $this->getFileSystem()->mkdir($destinationDir, true);
     }
     // Options:
     // c: compress
     // v: verbose
     // z: gzip archive
     // f: archive to file
     // C: root dir in the archived file
     $cmd = sprintf('tar -c%szf %s/%s %s -C"%s"', $this->isVerbose() ? 'v' : '', $destinationDir, $filename, $sourceDir, $archiveDir);
     $this->executeShellCommand($cmd, true);
     $this->logLine(sprintf('Directory archived: %s in %s ', $sourceDir, $filename));
     return true;
 }
Beispiel #3
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->logLine('Creating Symfony2 project', nbLogger::INFO);
     $projectBaseDir = nbFileSystem::sanitizeDir($arguments['project-base-dir']);
     // Download Symfony framework
     $cmd = sprintf('composer create-project --no-interaction symfony/framework-standard-edition %s/Symfony 2.1.x-dev', $projectBaseDir);
     $this->executeShellCommand($cmd);
     // TODO: move web to httpdocs
     // TODO: change paths in app.php, app_dev.php, app/config/config.yml
     // TODO: generate the virtual host
     // Permissions on app/cache and app/logs
     $cmd = sprintf('sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx %1$s/Symfony/app/cache %1$s/Symfony/app/logs', $projectBaseDir);
     $this->executeShellCommand($cmd);
     $cmd = sprintf('sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx %1$s/Symfony/app/cache %1$s/Symfony/app/logs', $projectBaseDir);
     $this->executeShellCommand($cmd);
     // Create the database
     $dbName = isset($options['db-name']) ? $options['db-name'] : null;
     $dbUser = isset($options['db-user']) ? $options['db-user'] : null;
     $dbPass = isset($options['db-pass']) ? $options['db-pass'] : null;
     $mysqlUser = isset($options['mysql-user']) ? $options['mysql-user'] : '******';
     $mysqlPass = isset($options['mysql-pass']) ? $options['mysql-pass'] : '******';
     if ($dbName && $dbUser && $dbPass) {
         $cmdLine = sprintf('%s %s %s --username=%s --password=%s', $dbName, $mysqlUser, $mysqlPass, $dbUser, $dbPass);
         $cmd = new nbMysqlCreateCommand();
         $this->executeCommand($cmd, $cmdLine, true, false);
     }
     return true;
 }
Beispiel #4
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $sourceDir = nbFileSystem::sanitizeDir($arguments['source_dir']);
     $this->logLine('Updating bee from ' . $sourceDir, nbLogger::COMMENT);
     $this->executeShellCommand('cd ' . $sourceDir . ' && git pull');
     $this->logLine('Bee successfully updated', nbLogger::COMMENT);
 }
Beispiel #5
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->checkBeeProject();
     $this->logLine('Initialising website', nbLogger::INFO);
     $verbose = isset($options['verbose']);
     $files = nbFileFinder::create('file')->add('website-*')->remove('.')->remove('..')->in('.bee');
     foreach ($files as $file) {
         $backupDir = dirname($file);
         $backupFile = 'backup_' . basename($file);
         $this->getFileSystem()->copy($file, sprintf('%s/%s', $backupDir, $backupFile), true);
     }
     // Enable required plugins for website:deploy
     $cmd = new nbEnablePluginCommand();
     $cmdLine = 'nbFileSystemPlugin --no-configuration';
     $this->executeCommand($cmd, $cmdLine, true, $verbose);
     $cmdLine = 'nbMysqlPlugin --no-configuration';
     $this->executeCommand($cmd, $cmdLine, true, $verbose);
     $cmdLine = 'nbWebsitePlugin -f';
     $this->executeCommand($cmd, $cmdLine, true, $verbose);
     // Makes web directory
     $deployDir = isset($arguments['deploy-dir']) ? nbFileSystem::sanitizeDir($arguments['deploy-dir']) : null;
     if ($deployDir) {
         $webDir = isset($options['change-web-dir']) ? $options['change-web-dir'] : 'httpdocs';
         $webDir = sprintf('%s/%s', $deployDir, $webDir);
         $this->logLine('Creating/Checking dir: ' . $webDir, nbLogger::COMMENT);
         if (!is_dir($webDir)) {
             $this->getFileSystem()->mkdir($webDir, true);
         }
     }
     // Creates the database
     $dbName = isset($options['db-name']) ? $options['db-name'] : null;
     $dbUser = isset($options['db-user']) ? $options['db-user'] : null;
     $dbPass = isset($options['db-pass']) ? $options['db-pass'] : null;
     $mysqlUser = isset($options['mysql-user']) ? $options['mysql-user'] : '******';
     $mysqlPass = isset($options['mysql-pass']) ? $options['mysql-pass'] : '';
     if ($dbName && $dbUser && $dbPass) {
         $cmdLine = sprintf('%s %s %s --username=%s --password=%s', $dbName, $mysqlUser, $mysqlPass, $dbUser, $dbPass);
         $cmd = new nbMysqlCreateCommand();
         $this->executeCommand($cmd, $cmdLine, true, $verbose);
     }
     // Restores the database
     $dbDumpFile = isset($options['db-dump-file']) ? $options['db-dump-file'] : null;
     if (is_file($dbDumpFile)) {
         if (!$dbName) {
             $this->logLine('You must specify the database name (use option: --db-name)', nbLogger::ERROR);
             return false;
         }
         $cmd = new nbMysqlRestoreCommand();
         $cmdLine = sprintf('%s %s %s %s', $dbName, $dbDumpFile, $mysqlUser, $mysqlPass);
         $this->executeCommand($cmd, $cmdLine, true, $verbose);
     }
     $this->logLine('Website initialized successfully', nbLogger::INFO);
     return true;
 }
Beispiel #6
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $timestamp = isset($options['add-timestamp']) ? date('YmdHi', time()) . '-' : null;
     $sources = $arguments['sources'];
     $destination = nbFileSystem::sanitizeDir($arguments['destination']);
     $force = isset($options['force']);
     $archiveName = sprintf('%s%s', $timestamp, basename($destination));
     $archiveDir = dirname($destination);
     $this->logLine(sprintf('Creating archive <comment>%s/%s</comment>...', $archiveDir, $archiveName), nbLogger::INFO);
     foreach ($sources as $key => $source) {
         $sources[$key] = nbFileSystem::sanitizeDir($source);
         if (!is_dir($sources[$key])) {
             if (!is_file($sources[$key])) {
                 throw new InvalidArgumentException("Source not found: " . $sources[$key]);
             }
         }
     }
     if (!is_dir($archiveDir)) {
         if (!$force) {
             throw new InvalidArgumentException("Destination directory not found: " . $archiveDir);
         }
         $this->getFileSystem()->mkdir($archiveDir, true);
     }
     // Options:
     // c: compress
     // v: verbose
     // z: gzip archive
     // f: archive to file
     // C: root dir in the archived file
     $cmd = sprintf('tar -czf %s/%s %s', $archiveDir, $archiveName, implode(' ', $sources));
     $this->executeShellCommand($cmd, true);
     if ($this->isVerbose()) {
         $logLine = sprintf("Directories/Files <comment>\n - %s\n</comment>archived in \n <comment>%s/%s</comment>", implode("\n - ", $sources), $archiveDir, $archiveName);
     } else {
         $logLine = sprintf("Directories/Files archived in <comment>%s/%s</comment>", $archiveDir, $archiveName);
     }
     $this->logLine($logLine, nbLogger::INFO);
     return true;
 }
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->logLine('Starting remote folder synchronization');
     $exclude = '';
     $include = '';
     // Trailing slash must be added after sanitize dir
     $sourceDir = nbFileSystem::sanitizeDir($arguments['source-dir']) . '/*';
     $remoteUser = $arguments['remote-user'];
     $remoteServer = $arguments['remote-server'];
     $remotePath = nbFileSystem::sanitizeDir($arguments['remote-dir']);
     if (isset($options['exclude-from']) && file_exists($options['exclude-from'])) {
         $exclude = ' --exclude-from \'' . $options['exclude-from'] . '\' ';
     }
     if (isset($options['include-from']) && file_exists($options['include-from'])) {
         $include = ' --include-from \'' . $options['include-from'] . '\' ';
     }
     $doit = isset($options['doit']) ? '' : '--dry-run';
     $delete = isset($options['delete']) ? '--delete' : '';
     $cmd = sprintf('rsync -rzChv %s %s %s %s %s -e ssh %s@%s:%s', $doit, $include, $exclude, $delete, $sourceDir, $remoteUser, $remoteServer, $remotePath);
     $this->executeShellCommand($cmd);
     $this->logLine('Remote folder synchronization completed');
 }
Beispiel #8
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     if (nbConfig::has('project_type') and nbConfig::get('project_type') == 'symfony') {
         $symfonyExecutable = sprintf('%s/%s', nbFileSystem::sanitizeDir(nbConfig::get('project_symfony_exec-path')), 'symfony');
         $symfonyTestEnviroment = nbConfig::get('project_symfony_test-enviroment');
         $this->logLine(sprintf('Launching all test for %s enviroment', $symfonyTestEnviroment));
         if ($symfonyTestEnviroment == 'lime') {
             $cmd = sprintf('php %s test:all', $symfonyExecutable);
             $this->executeShellCommand($cmd);
         } else {
             if ($symfonyTestEnviroment == 'phpunit') {
                 $cmd = sprintf('php %s phpunit:test-all', $symfonyExecutable);
                 $this->executeShellCommand($cmd);
             } else {
                 return false;
             }
         }
         return true;
     } else {
         throw new Exception('This isn\'t a symfony project');
     }
 }
Beispiel #9
0
<?php

require_once dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new lime_test(32);
$fs = nbFileSystem::getInstance();
$sourceDir = nbConfig::get('filesystem_dir-transfer_source-dir');
$targetDir = nbFileSystem::sanitizeDir(nbConfig::get('filesystem_dir-transfer_target-dir'));
$fileToSync = $targetDir . '/' . nbConfig::get('filesystem_test_file-to-sync');
$folderToExclude = $targetDir . '/' . nbConfig::get('filesystem_test_folder-to-exclude');
$fileToExclude = $targetDir . '/' . nbConfig::get('filesystem_test_file-to-exclude');
$fileToInclude = $targetDir . '/' . nbConfig::get('filesystem_test_file-to-include');
$otherFileToSync = $targetDir . '/' . nbConfig::get('filesystem_test_other-file-to-sync');
$fileToDelete = $targetDir . '/fileToDelete';
$excludeFile = nbConfig::get('filesystem_dir-transfer_exclude-from');
$includeFile = nbConfig::get('filesystem_dir-transfer_include-from');
$cmd = new nbDirTransferCommand();
$fs->touch($fileToDelete);
$commandLine = sprintf('--delete %s %s', $sourceDir, $targetDir);
$t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'Command nbDirTransfer called successfully dry run');
$t->ok(!file_exists($fileToSync), 'fileToSync wasn\'t synchronized in the target site because doit option was not set');
$t->ok(!file_exists($otherFileToSync), 'otherFileToSyn wasn\'t synchronized in the target folder');
$t->ok(!file_exists($folderToExclude), 'folderToExclude wasn\'t synchronized in the target folder');
$t->ok(!file_exists($fileToExclude), 'fileToExclude wasn\'t synchronized in the target folder');
$t->ok(!file_exists($fileToInclude), 'fileToInclude wasn\'t synchronized in the target folder');
$t->ok(file_exists($fileToDelete), 'fileToDelete wasn\'t deleted in the target folder');
$t->ok($cmd->run(new nbCommandLineParser(), '--doit ' . $commandLine), 'Command nbDirTransfer called successfully doit option set');
$t->ok(file_exists($fileToSync), 'fileToSync was synchronized in the target folder');
$t->ok(file_exists($otherFileToSync), 'otherFileToSync was synchronized in the target folder');
$t->ok(file_exists($folderToExclude), 'folderToExclude was synchronized in the target folder');
$t->ok(file_exists($fileToExclude), 'fileToEclude was synchronized in the target folder');
$t->ok(file_exists($fileToInclude), 'fileToInclude was synchronized in the target folder');
Beispiel #10
0
Datei: bee.php Projekt: nubee/bee
<?php

require_once dirname(__FILE__) . '/lib/core/autoload/nbAutoload.php';
$autoload = nbAutoload::getInstance();
$autoload->register();
$autoload->addDirectory(dirname(__FILE__) . '/lib/', '*.php', true);
$autoload->addDirectory(dirname(__FILE__) . '/vendor/', '*.php', true);
$beeDir = nbFileSystem::sanitizeDir(dirname(__FILE__));
nbConfig::set('nb_bee_dir', $beeDir);
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
    nbConfig::set('nb_user_dir', getenv('APPDATA') . '/.bee');
} else {
    nbConfig::set('nb_user_dir', getenv('HOME') . '/.bee');
}
nbConfig::set('nb_user_config', nbConfig::get('nb_user_dir') . '/config.yml');
$yaml = new nbYamlConfigParser();
$yaml->parseFile(nbConfig::get('nb_bee_dir') . '/config/config.yml', '', true);
if (file_exists(nbConfig::get('nb_user_config'))) {
    $yaml->parseFile(nbConfig::get('nb_user_config'), '', true);
}
if (file_exists('.bee/config.yml')) {
    $yaml->parseFile('.bee/config.yml', '', true);
}
if (file_exists('./.bee/' . nbConfig::get('nb_project_config'))) {
    $projectConfigurationFile = './.bee/' . nbConfig::get('nb_project_config');
} else {
    if (file_exists('./' . nbConfig::get('nb_project_config'))) {
        $projectConfigurationFile = './' . nbConfig::get('nb_project_config');
    } else {
        if (file_exists(nbConfig::get('nb_bee_dir') . '/' . nbConfig::get('nb_project_config'))) {
            $projectConfigurationFile = nbConfig::get('nb_bee_dir') . '/' . nbConfig::get('nb_project_config');