/** * Run user update * * @param InputInterface $input Input instance * @param OutputInterface $output Output instance * * @return int|null|void */ protected function userUpdate(InputInterface $input, OutputInterface $output) { // GIT pulls and other stuff // ################## // SSH Git repo update // ################## $reposDirectory = $this->getApplication()->getConfigValue('config', 'ssh_conf_path', '/opt/conf/ssh'); if (is_dir($reposDirectory) && is_dir($reposDirectory . '/.git')) { // SSH Git repo exists, update now $originalCwd = getcwd(); \CliTools\Utility\PhpUtility::chdir($reposDirectory); try { // Update git repository $this->outputBlock($output, 'Running git update of ' . $reposDirectory); $command = new CommandBuilder('git', 'pull'); $command->executeInteractive(); $command = new \CliTools\Shell\CommandBuilder\SelfCommandBuilder(); $command->addArgument('user:rebuildsshconfig'); $command->executeInteractive(); } catch (\RuntimeException $e) { $msg = 'Running git update of ' . $reposDirectory . '... FAILED'; $output->writeln('<error>' . $msg . '</error>'); } \CliTools\Utility\PhpUtility::chdir($originalCwd); } }
/** * Setup banner */ protected function setupBanner() { $command = new SelfCommandBuilder(); $command->addArgument('system:banner'); $output = $command->execute()->getOutputString(); // escape special chars for /etc/issue $outputIssue = addcslashes($output, '\\'); file_put_contents('/etc/issue', $outputIssue); file_put_contents('/etc/motd', $output); UnixUtility::reloadTtyBanner('tty1'); }
/** * Create mysql backup command * * @param string $database Database name * @param string $dumpFile MySQL dump file * @param null|string $filter Filter name * * @return SelfCommandBuilder */ protected function createMysqlBackupCommand($database, $dumpFile, $filter = null) { $command = new SelfCommandBuilder(); $command->addArgumentTemplate('mysql:backup %s %s', $database, $dumpFile); if ($filter !== null) { $command->addArgumentTemplate('--filter=%s', $filter); } return $command; }
/** * Execute command * * @param InputInterface $input Input instance * @param OutputInterface $output Output instance * * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { $runningCallback = function ($process, $status) { static $domainFound = false; if ($domainFound) { return; } $pid = $status['pid']; exec('pgrep -P ' . (int) $pid . ' | xargs ps -o command=', $output); if (!empty($output)) { foreach ($output as $line) { if (preg_match('/register\\.vagrantshare\\.com/', $line)) { if (preg_match('/-name ([^\\s]+)/', $line, $matches)) { $domainName = $matches[1]; $typo3Domain = new SelfCommandBuilder(); $typo3Domain->addArgument('typo3:domain')->addArgumentTemplate('--remove=%s', '*.vagrantshare.com')->addArgumentTemplate('--duplicate=%s', $domainName . '.vagrantshare.com')->execute(); $domainFound = true; } } } } }; $cleanupCallback = function () { $typo3Domain = new SelfCommandBuilder(); $typo3Domain->addArgument('typo3:domain')->addArgumentTemplate('--remove=%s', '*.vagrantshare.com')->execute(); }; $this->getApplication()->registerTearDown($cleanupCallback); $opts = array('runningCallback' => $runningCallback); $vagrant = new CommandBuilder('vagrant', 'share'); // Share name if ($input->getOption('name')) { $vagrant->addArgumentTemplate('--name %s', $input->getOption('name')); } elseif ($input->getArgument('name')) { $vagrant->addArgumentTemplate('--name %s', $input->getArgument('name')); } // HTTP port if ($input->getOption('http')) { $vagrant->addArgumentTemplate('--http %s', $input->getOption('http')); } else { $vagrant->addArgumentTemplate('--http %s', 80); } // HTTPS port if ($input->getOption('https')) { $vagrant->addArgumentTemplate('--http %s', $input->getOption('https')); } else { $vagrant->addArgumentTemplate('--https %s', 443); } // SSH stuff if ($input->getOption('ssh')) { $vagrant->addArgument('--ssh'); } if ($input->getOption('ssh-no-password')) { $vagrant->addArgument('--ssh-no-password'); } if ($input->getOption('ssh-port')) { $vagrant->addArgumentTemplate('--ssh-port %s', $input->getOption('ssh-port')); } if ($input->getOption('ssh-once')) { $vagrant->addArgument('--ssh-once'); } $vagrant->executeInteractive($opts); }
/** * Build and startup docker instance * * @param string $path Path */ protected function startDockerInstance($path) { $this->setTerminalTitle('Start docker'); $this->output->writeln('<comment>Building docker containers "' . $path . '"</comment>'); PhpUtility::chdir($path); $command = new SelfCommandBuilder(); $command->addArgument('docker:up'); $command->executeInteractive(); }