/**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $options['username'] = isset($options['username']) ? $options['username'] . '@' : '';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath() . '/';
     if (!is_dir($configurationPath)) {
         return;
     }
     $configurations = glob($configurationPath . '*');
     $commands = array();
     foreach ($configurations as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         if ($node->isLocalhost()) {
             $commands[] = "mkdir -p '{$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "cp {$configuration} {$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         } else {
             $username = $options['username'];
             $hostname = $node->getHostname();
             $sshPort = $node->hasOption('port') ? '-p ' . escapeshellarg($node->getOption('port')) : '';
             $scpPort = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
             $commands[] = "ssh {$sshPort} {$username}{$hostname} 'mkdir -p {$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "scp {$scpPort} {$configuration} {$username}{$hostname}:{$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $options['username'] = isset($options['username']) ? $options['username'] . '@' : '';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath() . '/';
     if (!is_dir($configurationPath)) {
         return;
     }
     $encryptedConfiguration = glob($configurationPath . '*.yaml.encrypted');
     if (count($encryptedConfiguration) > 0) {
         throw new \TYPO3\Surf\Exception\TaskExecutionException('You have sealed configuration files, please open the configuration for "' . $deployment->getName() . '"', 1317229449);
     }
     $configurations = glob($configurationPath . '*.yaml');
     $commands = array();
     foreach ($configurations as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         if ($node->isLocalhost()) {
             $commands[] = "mkdir -p '{$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "cp {$configuration} {$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         } else {
             $username = $options['username'];
             $hostname = $node->getHostname();
             $sshPort = $node->hasOption('port') ? '-p ' . escapeshellarg($node->getOption('port')) : '';
             $scpPort = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
             $commands[] = "ssh {$sshPort} {$username}{$hostname} 'mkdir -p {$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "scp {$scpPort} {$configuration} {$username}{$hostname}:{$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
Exemple #3
0
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $configurationFileExtension = isset($options['configurationFileExtension']) ? $options['configurationFileExtension'] : 'yaml';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath();
     if (!is_dir($configurationPath)) {
         return;
     }
     $commands = array();
     $configurationFiles = Files::readDirectoryRecursively($configurationPath, $configurationFileExtension);
     foreach ($configurationFiles as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         $escapedSourcePath = escapeshellarg($configuration);
         $escapedTargetPath = escapeshellarg(Files::concatenatePaths(array($targetReleasePath, 'Configuration', $targetConfigurationPath)) . '/');
         if ($node->isLocalhost()) {
             $commands[] = 'mkdir -p ' . $escapedTargetPath;
             $commands[] = 'cp ' . $escapedSourcePath . ' ' . $escapedTargetPath;
         } else {
             $username = isset($options['username']) ? $options['username'] . '@' : '';
             $hostname = $node->getHostname();
             $sshPort = isset($options['port']) ? '-p ' . escapeshellarg($options['port']) . ' ' : '';
             $scpPort = isset($options['port']) ? '-P ' . escapeshellarg($options['port']) . ' ' : '';
             $createDirectoryCommand = '"mkdir -p ' . $escapedTargetPath . '"';
             $commands[] = "ssh {$sshPort}{$username}{$hostname} {$createDirectoryCommand}";
             $commands[] = "scp {$scpPort}{$escapedSourcePath} {$username}{$hostname}:\"{$escapedTargetPath}\"";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
Exemple #4
0
 /**
  * Simulate a command by just outputting what would be executed
  *
  * @param string $command
  * @param Node|NULL $node
  * @param Deployment $deployment
  * @return bool
  */
 public function simulate($command, Node $node, Deployment $deployment)
 {
     if ($node->isLocalhost()) {
         $command = $this->prepareCommand($command);
         $deployment->getLogger()->debug('... (localhost): "' . $command . '"');
     } else {
         $command = $this->prepareCommand($command);
         $deployment->getLogger()->debug('... $' . $node->getName() . ': "' . $command . '"');
     }
     return true;
 }
 /**
  * Executes this task
  *
  * @param Node $node
  * @param Application $application
  * @param Deployment $deployment
  * @param array $options
  * @throws TaskExecutionException
  * @return void
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     if ($node->isLocalhost()) {
         $deployment->getLogger()->log('node seems not to be a remote node', LOG_DEBUG);
     } else {
         $username = $node->hasOption('username') ? $node->getOption('username') : NULL;
         if (!empty($username)) {
             $username = $username . '@';
         }
         $hostname = $node->getHostname();
         $sshOptions = array('-A', '-q', '-o BatchMode=yes');
         if ($node->hasOption('port')) {
             $sshOptions[] = '-p ' . escapeshellarg($node->getOption('port'));
         }
         $command = 'ssh ' . implode(' ', $sshOptions) . ' ' . escapeshellarg($username . $hostname) . ' exit;';
         $this->shell->execute($command, $deployment->getNode('localhost'), $deployment);
         $deployment->getLogger()->log('SSH connection successfully established', LOG_DEBUG);
     }
 }
Exemple #6
0
 /**
  * @param Node $node
  * @param string $file
  * @return string
  */
 protected function getArgument(Node $node, $file)
 {
     if ($node->isLocalhost() === TRUE) {
         return $file;
     }
     $argument = '';
     if ($node->hasOption('port')) {
         $port = $node->getOption('port');
         if (!empty($port)) {
             $argument .= '-P ' . $port . ' ';
         }
     }
     if ($node->hasOption('username')) {
         $username = $node->getOption('username');
         if (!empty($username)) {
             $argument .= $username . '@';
         }
     }
     $argument .= $node->getHostname() . ':';
     $argument .= $file;
     return $argument;
 }
Exemple #7
0
 /**
  * @param Node $node
  * @param string $path
  * @return string
  */
 protected function getFullPath(Node $node, $path)
 {
     $hostArgument = '';
     if ($node->isLocalhost() === FALSE) {
         if ($node->hasOption('username')) {
             $hostArgument .= $node->getOption('username') . '@';
         }
         $hostArgument .= $node->getHostname() . ':';
     }
     return escapeshellarg($hostArgument . rtrim($path, '/') . '/');
 }