protected function executeScript($script, $envVars = [], $type)
{
if (empty($script)) {
return;
}
if (!is_string($script)) {
throw new \InvalidArgumentException('Script must be a string');
}
if ($this->output && !$this->output->isQuiet()) {
$this->output->writeln("Running scripts ({$type})");
}
$envVars = array_merge(["BLUEPRINT=" . $this->blueprint->getName(), "STACKNAME=" . $this->blueprint->getStackName(), "CWD=" . CWD], $envVars);
if ($this->blueprint->getProfile()) {
$envVars = array_merge($envVars, $this->profileManager->getEnvVarsFromProfile($this->blueprint->getProfile()));
}
$basePath = $this->blueprint->getBasePath();
$tmpfile = tempnam(sys_get_temp_dir(), 'script_');
file_put_contents($tmpfile, $script);
$command = "cd {$basePath} && " . implode(' ', $envVars) . " /usr/bin/env bash -ex {$tmpfile}";
passthru($command, $returnVar);
unlink($tmpfile);
if ($returnVar !== 0) {
throw new \Exception('Error executing script');
}
}