/** * Run the operation */ public function execute() { $this->status(Phase::ENVIRONMENT()); $this->shell_type = $this->shell->getShellType(); $this->logger->debug("Remote shell is identifying as " . $this->shell_type->value()); foreach ($this->variables as $key => $value) { switch ($this->shell_type) { // Bourne-shell compatibles default: $cmd = 'export ' . $key . '="' . $value . '"'; break; // C-shell compatibles // C-shell compatibles case ShellType::CSH(): case ShellType::TCSH(): $cmd = 'set ' . $key . '="' . $value . '"'; } $this->output($this->shell->sendSmartCommand($cmd, false)); } }
/** * Bake the host * * @param Schema $schema * @param int $terminal_width */ public function bake(Schema $schema, $terminal_width = 180) { // Connect to host $con = $this->connect(); if (!$con) { throw new ConnectionException("Unable to connect to bakery host"); } // Get an SSH stream $this->status(Phase::ENVIRONMENT(), 0, 0, 'Configuring environment'); $shell = $con->getShell(new Terminal($terminal_width, 25, TerminalUnit::CHARACTERS)); $shell->setSmartConsole(); // Traverse operations $total = $schema->getOperationCount(); /** @var OperationInterface $operation */ foreach ($schema as $pos => $operation) { $this->status(Phase::OPERATION(), $pos + 1, $total, 'Executing ' . $this->getOperationName($operation)); $operation->setLogger($this->output); $operation->setCallback($this->status_callback); $operation->setPackagerType($schema->getPackagerType()); $operation->setShell($shell); $operation->setConnection($con); try { $operation->execute(); } catch (\Exception $e) { $this->status(Phase::ERROR(), $pos + 1, $total, 'Operation failed (' . $e->getMessage() . ')'); $con->disconnectChain(); throw $e; } } $con->disconnectChain(); }