コード例 #1
0
ファイル: UpdateCommand.php プロジェクト: jousch/clitools
 /**
  * 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);
     }
 }
コード例 #2
0
ファイル: RestoreCommand.php プロジェクト: jousch/clitools
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $database = $input->getArgument('db');
     $dumpFile = $input->getArgument('file');
     if (!is_file($dumpFile) || !is_readable($dumpFile)) {
         $output->writeln('<p-error>File is not readable</p-error>');
         return 1;
     }
     $dumpFileType = PhpUtility::getMimeType($dumpFile);
     $output->writeln('<h2>Restoring dump "' . $dumpFile . '" into database "' . $database . '"</h2>');
     if (DatabaseConnection::databaseExists($database)) {
         // Dropping
         $output->writeln('<p>Dropping database</p>');
         $query = 'DROP DATABASE IF EXISTS ' . DatabaseConnection::sanitizeSqlDatabase($database);
         DatabaseConnection::exec($query);
     }
     // Creating
     $output->writeln('<p>Creating database</p>');
     $query = 'CREATE DATABASE ' . DatabaseConnection::sanitizeSqlDatabase($database);
     DatabaseConnection::exec($query);
     // Inserting
     putenv('USER='******'MYSQL_PWD=' . DatabaseConnection::getDbPassword());
     $commandMysql = new CommandBuilder('mysql', '--user=%s %s --one-database', array(DatabaseConnection::getDbUsername(), $database));
     // Set server connection details
     if ($input->getOption('host')) {
         $commandMysql->addArgumentTemplate('-h %s', $input->getOption('host'));
     }
     if ($input->getOption('port')) {
         $commandMysql->addArgumentTemplate('-P %s', $input->getOption('port'));
     }
     $commandFile = new CommandBuilder();
     $commandFile->addArgument($dumpFile);
     $commandFile->addPipeCommand($commandMysql);
     switch ($dumpFileType) {
         case 'application/x-bzip2':
             $output->writeln('<p>Using BZIP2 decompression</p>');
             $commandFile->setCommand('bzcat');
             break;
         case 'application/gzip':
         case 'application/x-gzip':
             $output->writeln('<p>Using GZIP decompression</p>');
             $commandFile->setCommand('gzcat');
             break;
         case 'application/x-lzma':
         case 'application/x-xz':
             $output->writeln('<p>Using LZMA decompression</p>');
             $commandFile->setCommand('xzcat');
             break;
         default:
             $output->writeln('<p>Using plaintext (no decompression)</p>');
             $commandFile->setCommand('cat');
             break;
     }
     $output->writeln('<p>Reading dump</p>');
     $commandFile->executeInteractive();
     $output->writeln('<h2>Database "' . $database . '" restored</h2>');
     return 0;
 }
コード例 #3
0
ファイル: UpCommand.php プロジェクト: jousch/clitools
 /**
  * Stop last docker containers from previous run
  *
  * @param string $path Path
  */
 protected function stopContainersFromPrevRun($path)
 {
     $currentPath = getcwd();
     try {
         $this->output->writeln('<p>Trying to stop last running docker container in "' . $path . '"</p>');
         // Jump into last docker dir
         \CliTools\Utility\PhpUtility::chdir($path);
         // Stop docker containers
         $command = new CommandBuilder(null, 'stop');
         $this->executeDockerCompose($command);
         // Jump back
         \CliTools\Utility\PhpUtility::chdir($currentPath);
     } catch (\Exception $e) {
     }
 }
コード例 #4
0
ファイル: MakeCommand.php プロジェクト: jousch/clitools
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $paramList = $this->getFullParameterList();
     $path = UnixUtility::findFileInDirectortyTree('Makefile');
     if (!empty($path)) {
         $path = dirname($path);
         $this->output->writeln('<comment>Found Makefile directory: ' . $path . '</comment>');
         // Switch to directory of docker-compose.yml
         PhpUtility::chdir($path);
         $command = new CommandBuilder('make');
         if (!empty($paramList)) {
             $command->setArgumentList($paramList);
         }
         $command->executeInteractive();
     } else {
         $this->output->writeln('<error>No Makefile found in tree</error>');
         return 1;
     }
     return 0;
 }
コード例 #5
0
ファイル: InitCommand.php プロジェクト: jousch/clitools
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  * @throws \Exception
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $cliSyncFilePath = getcwd() . '/' . AbstractCommand::CONFIG_FILE;
     if (file_exists($cliSyncFilePath)) {
         $this->output->writeln('<p-error>Configuration file ' . AbstractCommand::CONFIG_FILE . ' already exists</p-error>');
         return 1;
     }
     // fetch example
     $content = PhpUtility::fileGetContents(CLITOOLS_ROOT_FS . '/conf/clisync.yml');
     // store in current working dir
     PhpUtility::filePutContents($cliSyncFilePath, $content);
     // Start editor with file (if $EDITOR is set)
     try {
         $editor = new EditorCommandBuilder();
         $editor->addArgument($cliSyncFilePath)->executeInteractive();
     } catch (\Exception $e) {
         $this->output->writeln('<p-error>' . $e->getMessage() . '</p-error>');
     }
     $this->output->writeln('<info>Successfully created ' . AbstractCommand::CONFIG_FILE . ' </info>');
 }
コード例 #6
0
ファイル: ComposerCommand.php プロジェクト: jousch/clitools
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $composerCmd = $this->getApplication()->getConfigValue('bin', 'composer');
     $paramList = $this->getFullParameterList();
     $composerJsonPath = UnixUtility::findFileInDirectortyTree('composer.json');
     if (!empty($composerJsonPath)) {
         $path = dirname($composerJsonPath);
         $this->output->writeln('<comment>Found composer.json directory: ' . $path . '</comment>');
         // Switch to directory of docker-compose.yml
         PhpUtility::chdir($path);
         $command = new CommandBuilder();
         $command->parse($composerCmd);
         if (!empty($paramList)) {
             $command->setArgumentList($paramList);
         }
         $command->executeInteractive();
     } else {
         $this->output->writeln('<error>No composer.json found in tree</error>');
         return 1;
     }
     return 0;
 }
コード例 #7
0
ファイル: SelfUpdateService.php プロジェクト: jousch/clitools
 /**
  * Download file
  */
 protected function downloadUpdate()
 {
     $output = $this->output;
     // Progress counter
     $progress = function ($downloadTotal, $downoadProgress) use($output) {
         static $counter = 0;
         if ($counter % 30 === 0) {
             $output->write('<info>.</info>');
         }
         $counter++;
     };
     $data = \CliTools\Utility\PhpUtility::curlFetch($this->updateUrl, $progress);
     $tmpFile = tempnam(sys_get_temp_dir(), 'ct');
     file_put_contents($tmpFile, $data);
     $this->cliToolsUpdatePath = $tmpFile;
 }
コード例 #8
0
ファイル: AbstractCommand.php プロジェクト: jousch/clitools
 /**
  * Execute docker compose run
  *
  * @param  string          $containerName Container name
  * @param  CommandBuilderInterface  $command       Command
  *
  * @return int|null|void
  */
 protected function executeDockerComposeRun($containerName, CommandBuilderInterface $command)
 {
     // Search updir for docker-compose.yml
     $path = $this->getDockerPath();
     if (!empty($path)) {
         // Switch to directory of docker-compose.yml
         PhpUtility::chdir($path);
         $this->output->writeln('<info>Executing "' . $command->getCommand() . '" in docker container "' . $containerName . '" ...</info>');
         $dockerCommand = new CommandBuilder('docker-compose', 'run --rm %s', array($containerName));
         $dockerCommand->append($command, false);
         $dockerCommand->executeInteractive();
     } else {
         $this->output->writeln('<p-error>No docker-compose.yml found in tree</p-error>');
         return 1;
     }
     return 0;
 }
コード例 #9
0
ファイル: AbstractCommand.php プロジェクト: jousch/clitools
 /**
  * Add exclude (pattern) list to rsync command
  *
  * @param CommandBuilder $command  Rsync Command
  * @param array          $list     List of excludes
  */
 protected function rsyncAddExcludeList(CommandBuilder $command, $list)
 {
     $rsyncFilter = $this->tempDir . '/.rsync-exclude';
     PhpUtility::filePutContents($rsyncFilter, implode("\n", $list));
     $command->addArgumentTemplate('--exclude-from=%s', $rsyncFilter);
     // cleanup rsync file
     $command->getExecutor()->addFinisherCallback(function () use($rsyncFilter) {
         unlink($rsyncFilter);
     });
 }
コード例 #10
0
ファイル: CreateCommand.php プロジェクト: jousch/clitools
 /**
  * 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();
 }