/** * Generate a new Job script to be executed under a separate PHP process * * @param null|string $mutantFile * @param array $args * @param string $bootstrap * @param null|string $replacingFile * @return string */ public static function generate($mutantFile = null, $bootstrap = '', $replacingFile = null) { if ('phar:' === substr(__FILE__, 0, 5)) { $humbugBootstrap = \Phar::running() . '/bootstrap.php'; } else { $humbugBootstrap = realpath(__DIR__ . '/../../../bootstrap.php'); } $file = sys_get_temp_dir() . '/humbug.phpunit.bootstrap.php'; if (!is_null($mutantFile)) { $mutantFile = addslashes($mutantFile); $replacingFile = addslashes($replacingFile); $prepend = <<<PREPEND <?php require_once '{$humbugBootstrap}'; use Humbug\\StreamWrapper\\IncludeInterceptor; IncludeInterceptor::intercept('{$replacingFile}', '{$mutantFile}'); IncludeInterceptor::enable(); PREPEND; if (!empty($bootstrap)) { $buffer = $prepend . "\nrequire_once '{$bootstrap}';"; } else { $buffer = $prepend; } file_put_contents($file, $buffer); } else { if (!empty($bootstrap)) { $buffer = "<?php\nrequire_once '{$humbugBootstrap}';\nrequire_once '{$bootstrap}';"; } else { $buffer = "<?php\nrequire_once '{$humbugBootstrap}';"; } file_put_contents($file, $buffer); } }
/** * Initializes all components used by phpDocumentor. * * @param ClassLoader $autoloader * @param array $values */ public function __construct($autoloader = null, array $values = array()) { $this->defineIniSettings(); self::$VERSION = strpos('@package_version@', '@') === 0 ? trim(file_get_contents(__DIR__ . '/../../VERSION')) : '@package_version@'; parent::__construct('phpDocumentor', self::$VERSION, $values); $this['kernel.timer.start'] = time(); $this['kernel.stopwatch'] = function () { return new Stopwatch(); }; $this['autoloader'] = $autoloader; $this->register(new JmsSerializerServiceProvider()); $this->register(new Configuration\ServiceProvider()); $this->addEventDispatcher(); $this->addLogging(); $this->register(new ValidatorServiceProvider()); $this->register(new Translator\ServiceProvider()); $this->register(new Descriptor\ServiceProvider()); $this->register(new Parser\ServiceProvider()); $this->register(new Partials\ServiceProvider()); $this->register(new Transformer\ServiceProvider()); $this->register(new Plugin\ServiceProvider()); $this->addCommandsForProjectNamespace(); if (\Phar::running()) { $this->addCommandsForPharNamespace(); } }
protected function execute(InputInterface $input, OutputInterface $output) { $manifest = $input->getOption('manifest') ?: 'https://platform.sh/cli/manifest.json'; $currentVersion = $input->getOption('current-version') ?: $this->getApplication()->getVersion(); if (extension_loaded('Phar') && !($localPhar = \Phar::running(false))) { $this->stdErr->writeln('This instance of the CLI was not installed as a Phar archive.'); if (file_exists(CLI_ROOT . '/../../autoload.php')) { $this->stdErr->writeln('Update using: <info>composer global update</info>'); } return 1; } $manager = new Manager(Manifest::loadFile($manifest)); if (isset($localPhar)) { $manager->setRunningFile($localPhar); } $onlyMinor = !$input->getOption('major'); $updated = $manager->update($currentVersion, $onlyMinor); if ($updated) { $this->stdErr->writeln("Successfully updated"); $localPhar = $manager->getRunningFile(); passthru('php ' . escapeshellarg($localPhar) . ' --version'); } else { $this->stdErr->writeln("No updates found. The Platform.sh CLI is up-to-date."); } return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $application = $this->getApplication(); $manifest = $input->getOption('manifest') ?: 'http://drupalconsole.com/manifest.json'; $currentVersion = $input->getOption('current-version') ?: $application->getVersion(); $major = $input->getOption('major'); if (!extension_loaded('Phar') || !\Phar::running(false)) { $io->error($this->trans('commands.self-update.messages.not-phar')); $io->block($this->trans('commands.self-update.messages.instructions')); return 1; } $io->info(sprintf($this->trans('commands.self-update.messages.check'), $currentVersion)); $updater = new Updater(null, false); $strategy = new ManifestStrategy($currentVersion, $major, $manifest); $updater->setStrategyObject($strategy); if (!$updater->hasUpdate()) { $io->info(sprintf($this->trans('commands.self-update.messages.current-version'), $currentVersion)); return 0; } $oldVersion = $updater->getOldVersion(); $newVersion = $updater->getNewVersion(); if (!$io->confirm(sprintf($this->trans('commands.self-update.questions.update'), $oldVersion, $newVersion), true)) { return 1; } $io->comment(sprintf($this->trans('commands.self-update.messages.update'), $newVersion)); $updater->update(); $io->success(sprintf($this->trans('commands.self-update.messages.success'), $oldVersion, $newVersion)); // Errors appear if new classes are instantiated after this stage // (namely, Symfony's ConsoleTerminateEvent). This suggests PHP // can't read files properly from the overwritten Phar, or perhaps it's // because the autoloader's name has changed. We avoid the problem by // terminating now. exit; }
function selfupdate($argv, $inPhar) { $opts = ['http' => ['method' => 'GET', 'header' => "User-agent: phpfmt fmt.phar selfupdate\r\n"]]; $context = stream_context_create($opts); // current release $releases = json_decode(file_get_contents('https://api.github.com/repos/phpfmt/fmt/tags', false, $context), true); $commit = json_decode(file_get_contents($releases[0]['commit']['url'], false, $context), true); $files = json_decode(file_get_contents($commit['commit']['tree']['url'], false, $context), true); foreach ($files['tree'] as $file) { if ('fmt.phar' == $file['path']) { $phar_file = base64_decode(json_decode(file_get_contents($file['url'], false, $context), true)['content']); } if ('fmt.phar.sha1' == $file['path']) { $phar_sha1 = base64_decode(json_decode(file_get_contents($file['url'], false, $context), true)['content']); } } if (!isset($phar_sha1) || !isset($phar_file)) { fwrite(STDERR, 'Could not autoupdate - not release found' . PHP_EOL); exit(255); } if ($inPhar && !file_exists($argv[0])) { $argv[0] = dirname(Phar::running(false)) . DIRECTORY_SEPARATOR . $argv[0]; } if (sha1_file($argv[0]) != $phar_sha1) { copy($argv[0], $argv[0] . '~'); file_put_contents($argv[0], $phar_file); chmod($argv[0], 0777 & ~umask()); fwrite(STDERR, 'Updated successfully' . PHP_EOL); exit(0); } fwrite(STDERR, 'Up-to-date!' . PHP_EOL); exit(0); }
/** * CodeSniffer alternative for realpath. * * Allows for PHAR support. * * @param string $path The path to use. * * @return mixed */ public static function realpath($path) { // Support the path replacement of ~ with the user's home directory. if (substr($path, 0, 2) === '~/') { $homeDir = getenv('HOME'); if ($homeDir !== false) { $path = $homeDir . substr($path, 1); } } // No extra work needed if this is not a phar file. if (self::isPharFile($path) === false) { return realpath($path); } // Before trying to break down the file path, // check if it exists first because it will mostly not // change after running the below code. if (file_exists($path) === true) { return $path; } $phar = \Phar::running(false); $extra = str_replace('phar://' . $phar, '', $path); $path = realpath($phar); if ($path === false) { return false; } $path = 'phar://' . $path . $extra; if (file_exists($path) === true) { return $path; } return false; }
/** * Running from Phar or not? * * @return bool */ public static function isPhar() { if (!empty(\Phar::running())) { self::$pharPath = \Phar::running(); return true; } return false; }
function phargui_autoloader($class_name) { $file = str_replace('\\', '/', $class_name) . '.php'; if (Phar::running()) { include 'phar://phar-gui.phar/lib/' . $file; } else { include __DIR__ . '/' . $file; } }
public function getRoot($external = false) { if ($external && \Phar::running(false) != "") { return dirname(\Phar::running(false)); } if (!$this->root && !defined('MANIALIB_APP_PATH')) { throw new \Exception(); } return $this->root ?: MANIALIB_APP_PATH; }
public function __construct() { parent::__construct('Feather', self::VERSION); $this->add(new Command\RunCommand()); if (\Phar::running()) { $command = new AmendCommand('self-update'); $command->setManifestUri('http://zroger.github.io/feather/manifest.json'); $this->getHelperSet()->set(new AmendHelper()); $this->add($command); } }
protected function execute(InputInterface $input, OutputInterface $output) { if (ini_get('allow_url_fopen') !== '1') { throw new \RuntimeException('`allow_url_fopen` must be enabled in your php.ini to use the `self-update` command.'); } $phar = preg_replace('/^phar:\\/\\//', '', \Phar::running()); $output->writeln('Overwriting ' . $phar); if (!is_writable($phar)) { throw new \RuntimeException('The Phar path is not writable. Ensure permissions are set to allow the file to be written to.'); } $latest = file_get_contents('http://mongrate.com/download?self-update&from=' . MONGRATE_VERSION); file_put_contents($phar, $latest); }
protected function getDefaultCommands() { $commands = parent::getDefaultCommands(); $commands[] = new Command\ValidateCommand(); $commands[] = new Command\ConvertCommand(); $commands[] = new Command\ReleaseCommand(); $commands[] = new Command\InstallerCommand(); $commands[] = new Command\InfoCommand(); if (\Phar::running() !== '') { $commands[] = new Command\SelfUpdateCommand(); } return $commands; }
function curdir() { $trace = debug_backtrace(0, 1); $dir = dirname($trace[0]['file']); $phar = \Phar::running(false); if (empty($phar)) { return $dir; } $dir = str_replace('phar://', '', $dir); $dir = str_replace($phar, '', $dir); $dir = str_replace(dirname($phar), '', $dir); return \Phar::running() . $dir; }
/** * Extract the file from the phar archive to make it accessible for native commands. * * @param string $filePath the absolute file path to extract * @param bool $overwrite * * @return string */ public static function extractFile($filePath, $overwrite = false) { $pharPath = \Phar::running(false); if (empty($pharPath)) { return ''; } $relativeFilePath = substr($filePath, strpos($filePath, $pharPath) + strlen($pharPath) + 1); $tmpDir = sys_get_temp_dir() . '/jolinotif'; $extractedFilePath = $tmpDir . '/' . $relativeFilePath; if (!file_exists($extractedFilePath) || $overwrite) { $phar = new \Phar($pharPath); $phar->extractTo($tmpDir, $relativeFilePath, $overwrite); } return $extractedFilePath; }
/** * Setting up the system, setting parameters. */ public function __construct() { if (function_exists('ini_set') && extension_loaded('xdebug')) { ini_set('xdebug.show_exception_trace', false); ini_set('xdebug.scream', false); } if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) { date_default_timezone_set(@date_default_timezone_get()); } if (stripos(\Phar::running(), 'phar:') !== false) { Config::$path = '/var/phpcron/'; } $this->createPatch(); Config::$sharedId = shm_attach(ftok(__FILE__, 'A')); parent::__construct(strtolower(Config::NAME), Config::VERSION); }
function index(Config $config, OutputInterface $output, \RecursiveIteratorIterator $it2, $stubs = false) { $baseDir = $config->getBasePath(); $symbolTable = $config->getSymbolTable(); $indexer = new SymbolTableIndexer($symbolTable, $output); $traverser1 = new NodeTraverser(); $traverser1->addVisitor(new NameResolver()); $traverser2 = new NodeTraverser(); $traverser2->addVisitor($indexer); $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); $configArr = $config->getConfigArray(); $count = 0; foreach ($it2 as $file) { if (($file->getExtension() == "php" || $file->getExtension() == "inc") && $file->isFile()) { $name = Util::removeInitialPath($baseDir, $file->getPathname()); if (strpos($name, "phar://") === 0) { $name = str_replace(\Phar::running(), "", $name); while ($name[0] == '/') { $name = substr($name, 1); } $name = "phar://" . $name; } try { if (!$stubs && isset($configArr['ignore']) && is_array($configArr['ignore']) && Util::matchesGlobs($baseDir, $file->getPathname(), $configArr['ignore'])) { continue; } ++$count; $output->output(".", " - {$count}:" . $name); // If the $fileName is in our phar then make it a relative path so that files that we index don't // depend on the phar file existing in a particular directory. $fileData = file_get_contents($file->getPathname()); if ($config->shouldReindex()) { $symbolTable->removeFileFromIndex($file->getPathname()); } $indexer->setFilename($name); $stmts = $parser->parse($fileData); if ($stmts) { $traverser1->traverse($stmts); $traverser2->traverse($stmts); } } catch (Error $e) { $output->emitError(__CLASS__, $file, 0, ' Parse Error: ' . $e->getMessage() . "\n"); } } } return $count; }
/** * Determine the correct working directory. * * @return string * * @throws \RuntimeException When the home directory is not /web. */ private function detectHomeDirectory() { // Environment variable COMPOSER points to the composer.json we should use. if (false !== ($home = getenv('COMPOSER'))) { return dirname($home); } if ('' !== \Phar::running()) { // Strip scheme "phar://" prefix and "tenside.phar" suffix. $home = dirname(substr(\Phar::running(), 7)); } else { $home = getcwd(); } if (PHP_SAPI !== 'cli' && substr($home, -4) !== DIRECTORY_SEPARATOR . 'web') { throw new \RuntimeException('Tenside is intended to be run from within the web directory but it appears you are running it from ' . basename($home)); } return dirname($home); }
/** * Constructor. * * If the folder names are not provided, default to * Conf::f('template_folders', null) * If the cache folder name is not provided, it will default to * Conf::f('tmp_folder', '/tmp') * * @param string Template name. * @param string Template folder paths (null) * @param string Cache folder name (null) * @param $options Extra options for the compiler (array()) */ function __construct($template, $folders = null, $cache = null, $options = array()) { $this->tpl = $template; $this->folders = null === $folders ? Conf::f('template_folders') : $folders; $this->cache = null === $cache ? Conf::f('tmp_folder') : $cache; list($tmpl_path, $tmpl_uid) = $this->getCompiledTemplateName(); $this->compiled_template = $tmpl_path; $this->class = 'Template_' . $tmpl_uid; if (!\Phar::running() && !class_exists('\\photon\\template\\compiled\\' . $this->class, false)) { if (!file_exists($this->compiled_template) || Conf::f('debug') || Conf::f('template_force_compilation')) { $this->compiler = new Compiler($this->tpl, $this->folders, $options); $this->getCompiledTemplateContent(); $this->write($this->compiled_template); } include_once $this->compiled_template; } }
/** * {@inheritdoc} */ protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); $this->informationCollector->handleCommandInput($input); $this->getOutput()->writeBigTitle('Welcome to Release Management Tool initialization'); $this->getOutput()->writeEmptyLine(); // Security check for the config $configPath = $this->getApplication()->getConfigFilePath(); if ($configPath !== null && file_exists($configPath) && $input->getOption('force') !== true) { throw new \Exception("A config file already exist ({$configPath}), if you want to regenerate it, use the --force option"); } // Guessing elements path $this->buildPaths($configPath); // disable the creation of the conveniance script when within a phar if (extension_loaded('phar') && \Phar::running()) { $this->informationCollector->setValueFor('configonly', 'y'); } }
/** * @param string $version * @return string */ public function updates($version = self::LATEST) { $tag = $version; if (self::LATEST == $version) { $tag = 'master'; } if (ini_get('phar.readonly') == true) { throw new \RuntimeException('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\''); } if (ini_get('allow_url_fopen') == false) { throw new \RuntimeException('Unable to update the PHAR, allow_url_fopen is not set, use \'-d allow_url_fopen=1\''); } $currentPharLocation = \Phar::running(false); if (!file_exists($currentPharLocation) || strlen($currentPharLocation) == 0) { throw new \LogicException("You're not currently using Phar. If you have installed PhpMetrics with Composer, please updates it using Composer."); } if (!is_writable($currentPharLocation)) { throw new \RuntimeException(sprintf('%s is not writable', $currentPharLocation)); } // downloading $url = sprintf($this->url, $tag); $ctx = stream_context_create(); stream_context_set_params($ctx, array("notification" => array($this, 'stream_notification_callback'))); $content = file_get_contents($url, false, $ctx); // replacing file if (!$content) { throw new \RuntimeException('Download failed'); } // check if all is OK $tmpfile = tempnam(sys_get_temp_dir(), 'phar'); file_put_contents($tmpfile, $content); $output = shell_exec(sprintf('"%s" "%s" --version', PHP_BINARY, $tmpfile)); if (!preg_match('!(v\\d+\\.\\d+\\.\\d+)!', $output, $matches)) { throw new \RuntimeException('Phar is corrupted. Please retry'); } // compare versions $downloadedVersion = $matches[1]; if (self::LATEST !== $version && $downloadedVersion !== $version) { throw new \RuntimeException('Incorrect version. Please retry'); } // at this step, all is ok file_put_contents($currentPharLocation, $content); return $version; }
public function execute(CommandSender $sender, $commandLabel, array $args) { if (!$sender instanceof ConsoleCommandSender) { $sender->sendMessage("Please run this command on console."); return false; } $token = strtoupper(substr(sha1(BOOTUP_RANDOM . ":" . $sender->getServer()->getServerUniqueId() . ":" . self::$executions), 6, 6)); if (!isset($args[0]) or $args[0] !== $token) { $sender->sendMessage("This command will stop the server and start an installer window."); $sender->sendMessage("Type `/wea-config {$token}` then enter, to start the installer."); return false; } foreach ($this->getPlugin()->getServer()->getOnlinePlayers() as $player) { $player->kick("Server stop", false); } exec("start " . PHP_BINARY . " " . \Phar::running(false)); $this->getPlugin()->getServer()->shutdown(); return true; }
private function getPackageVersion() : string { $version = null; $pharFile = \Phar::running(); if ($pharFile) { $metadata = (new \Phar($pharFile))->getMetadata(); $version = $metadata['version'] ?? null; } if (!$version) { $pwd = getcwd(); chdir(realpath(__DIR__ . '/../../../')); $gitVersion = @exec('git describe --tags --dirty=-dev --always 2>&1', $output, $returnValue); chdir($pwd); if ($returnValue === 0) { $version = $gitVersion; } } return $version ?? 'unknown-development'; }
/** * Try to find the magic file copied by phing's build.xml into * lib/data/. * * @return string path to the magic file */ public static function getMagicFile() { $rootdir = __DIR__ . '/../../../../../'; if (file_exists($rootdir . '/lib/PEAR.php')) { if (!\Phar::running()) { return $rootdir . '/lib/data/programming.magic'; } else { //magic file within a .phar does not work: // https://bugs.php.net/bug.php?id=67556 //put it outside $target = '/tmp/phorkie-programming.magic'; if (!file_exists($target)) { copy($rootdir . '/lib/data/programming.magic', $target); } return $target; } } return parent::getMagicFile(); }
public function __construct(\ThreadedLogger $logger, \ClassLoader $loader, $port, $interface = "127.0.0.1") { $this->logger = $logger; $this->interface = $interface; $this->port = (int) $port; if ($port < 1 or $port > 65536) { throw new \Exception("Invalid port range"); } $this->setClassLoader($loader); $this->shutdown = false; $this->externalQueue = new \Threaded(); $this->internalQueue = new \Threaded(); if (\Phar::running(true) !== "") { $this->mainPath = \Phar::running(true); } else { $this->mainPath = \getcwd() . DIRECTORY_SEPARATOR; } $this->start(); }
protected function execute(InputInterface $input, OutputInterface $output) { $manifestUrl = $input->getOption('manifest') ?: 'https://platform.sh/cli/manifest.json'; $currentVersion = $input->getOption('current-version') ?: $this->getApplication()->getVersion(); $allowMajor = $input->getOption('major'); $allowUnstable = $input->getOption('unstable'); if (!extension_loaded('Phar') || !($localPhar = \Phar::running(false))) { $this->stdErr->writeln('This instance of the CLI was not installed as a Phar archive.'); // Instructions for users who are running a global Composer install. if (file_exists(CLI_ROOT . '/../../autoload.php')) { $this->stdErr->writeln("Update using:\n\n composer global update"); $this->stdErr->writeln("\nOr you can switch to a Phar install (<options=bold>recommended</>):\n"); $this->stdErr->writeln(" composer global remove platformsh/cli"); $this->stdErr->writeln(" curl -sS https://platform.sh/cli/installer | php\n"); } return 1; } $this->stdErr->writeln(sprintf('Checking for updates (current version: <info>%s</info>)', $currentVersion)); $updater = new Updater(null, false); $strategy = new ManifestStrategy($currentVersion, $manifestUrl, $allowMajor, $allowUnstable); $updater->setStrategyObject($strategy); if (!$updater->hasUpdate()) { $this->stdErr->writeln('No updates found'); return 0; } $newVersionString = $updater->getNewVersion(); /** @var \Platformsh\Cli\Helper\PlatformQuestionHelper $questionHelper */ $questionHelper = $this->getHelper('question'); if (!$questionHelper->confirm(sprintf('Update to version %s?', $newVersionString), $input, $output)) { return 1; } $this->stdErr->writeln(sprintf('Updating to version %s', $newVersionString)); $updater->update(); $this->stdErr->writeln("Successfully updated to version <info>{$newVersionString}</info>"); // Errors appear if new classes are instantiated after this stage // (namely, Symfony's ConsoleTerminateEvent). This suggests PHP // can't read files properly from the overwritten Phar, or perhaps it's // because the autoloader's name has changed. We avoid the problem by // terminating now. exit; }
/** * Initalized command */ protected function initialize() { parent::initialize(); $arguments = $_SERVER['argv']; if (\Phar::running()) { // running as phar $this->setCommand(array_shift($arguments)); } elseif (!empty($_SERVER['_'])) { if ($_SERVER['argv'][0] !== $_SERVER['_']) { $this->setCommand($_SERVER['_']); $this->addArgument(array_shift($arguments)); } } // Fallback if (!$this->getCommand()) { $this->setCommand('php'); $this->addArgument($_SERVER['PHP_SELF']); } // All other arguments $this->addArgumentList($arguments); }
/** * Initalized command */ protected function initialize() { parent::initialize(); $arguments = $_SERVER['argv']; // Check if command is run inside PHAR if (\Phar::running()) { // PHAR version $this->setCommand(array_shift($arguments)); } elseif (!empty($_SERVER['_'])) { // Plain PHP version if ($_SERVER['argv'][0] !== $_SERVER['_']) { $this->setCommand($_SERVER['_']); $this->addArgument(reset($arguments)); } } // Fallback if (!$this->getCommand()) { $this->setCommand('php'); $this->addArgument($_SERVER['PHP_SELF']); } }
/** * Run the update. * * @param string|null $manifestUrl * @param string|null $currentVersion * * @return false|string * The new version number, or false if there was no update. */ public function update($manifestUrl = null, $currentVersion = null) { $currentVersion = $currentVersion ?: $this->config->get('application.version'); $manifestUrl = $manifestUrl ?: $this->config->get('application.manifest_url'); if (!extension_loaded('Phar') || !($localPhar = \Phar::running(false))) { $this->stdErr->writeln('This instance of the CLI was not installed as a Phar archive.'); // Instructions for users who are running a global Composer install. if (defined('CLI_ROOT') && file_exists(CLI_ROOT . '/../../autoload.php')) { $this->stdErr->writeln("Update using:\n\n composer global update"); $this->stdErr->writeln("\nOr you can switch to a Phar install (<options=bold>recommended</>):\n"); $this->stdErr->writeln(" composer global remove " . $this->config->get('application.package_name')); $this->stdErr->writeln(" curl -sS " . $this->config->get('application.installer_url') . " | php\n"); } return false; } $this->stdErr->writeln(sprintf('Checking for updates (current version: <info>%s</info>)', $currentVersion)); $updater = new Updater(null, false); $strategy = new ManifestStrategy($currentVersion, $manifestUrl, $this->allowMajor, $this->allowUnstable); $strategy->setManifestTimeout($this->timeout); $updater->setStrategyObject($strategy); if (!$updater->hasUpdate()) { $this->stdErr->writeln('No updates found'); return false; } $newVersionString = $updater->getNewVersion(); if ($notes = $strategy->getUpdateNotes($updater)) { $this->stdErr->writeln(''); $this->stdErr->writeln(sprintf('Version <info>%s</info> is available. Update notes:', $newVersionString)); $this->stdErr->writeln(preg_replace('/^/m', ' ', $notes)); $this->stdErr->writeln(''); } if (!$this->questionHelper->confirm(sprintf('Update to version %s?', $newVersionString))) { return false; } $this->stdErr->writeln(sprintf('Updating to version %s', $newVersionString)); $updater->update(); $this->stdErr->writeln("Successfully updated to version <info>{$newVersionString}</info>"); return $newVersionString; }
public function __construct($sig = false) { // We may have already been instantated, which means we already have a sig if (!$sig) { if (!self::$sig) { throw new \Exception("Need signature file the first time I'm run!"); } } else { // We've been given a sig. Check it... if (!isset($sig['config']['hash']) || $sig['config']['hash'] !== "sha256") { throw new \Exception("Invalid sig file.. Hash is not sha256 - check sigfile"); } self::$sig = $sig; } // If we're in a phar, use that. if (\Phar::running()) { $dir = dirname(\Phar::running(false)); } else { $dir = __DIR__; } $this->modroot = $dir . "/../"; }
/** * Execute 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 * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { $localPackagePath = $deployment->getWorkspacePath($application); $releasePath = $deployment->getApplicationReleasePath($application); $remotePath = Files::concatenatePaths(array($application->getDeploymentPath(), 'cache/transfer')); // make sure there is a remote .cache folder $command = 'mkdir -p ' . $remotePath; $this->shell->executeOrSimulate($command, $node, $deployment); $username = $node->hasOption('username') ? $node->getOption('username') . '@' : ''; $hostname = $node->getHostname(); $port = $node->hasOption('port') ? ' -p ' . escapeshellarg($node->getOption('port')) : ''; $key = $node->hasOption('privateKeyFile') ? ' -i ' . escapeshellarg($node->getOption('privateKeyFile')) : ''; $quietFlag = isset($options['verbose']) && $options['verbose'] ? '' : '-q'; $rshFlag = $node->isLocalhost() ? '' : '--rsh="ssh' . $port . $key . '" '; $rsyncExcludes = isset($options['rsyncExcludes']) ? $options['rsyncExcludes'] : array('.git'); $excludeFlags = $this->getExcludeFlags($rsyncExcludes); $rsyncFlags = isset($options['rsyncFlags']) ? $options['rsyncFlags'] : '--recursive --times --perms --links --delete --delete-excluded' . $excludeFlags; $destinationArgument = $node->isLocalhost() ? $remotePath : "{$username}{$hostname}:{$remotePath}"; $command = "rsync {$quietFlag} --compress {$rshFlag} {$rsyncFlags} " . escapeshellarg($localPackagePath . '/.') . ' ' . escapeshellarg($destinationArgument); if ($node->hasOption('password')) { $passwordSshLoginScriptPathAndFilename = Files::concatenatePaths(array(dirname(dirname(dirname(__DIR__))), 'Resources', 'Private/Scripts/PasswordSshLogin.expect')); if (\Phar::running() !== '') { $passwordSshLoginScriptContents = file_get_contents($passwordSshLoginScriptPathAndFilename); $passwordSshLoginScriptPathAndFilename = Files::concatenatePaths(array($deployment->getTemporaryPath(), 'PasswordSshLogin.expect')); file_put_contents($passwordSshLoginScriptPathAndFilename, $passwordSshLoginScriptContents); } $command = sprintf('expect %s %s %s', escapeshellarg($passwordSshLoginScriptPathAndFilename), escapeshellarg($node->getOption('password')), $command); } $localhost = new Node('localhost'); $localhost->setHostname('localhost'); $this->shell->executeOrSimulate($command, $localhost, $deployment); if (isset($passwordSshLoginScriptPathAndFilename) && \Phar::running() !== '') { unlink($passwordSshLoginScriptPathAndFilename); } $command = strtr("cp -RPp {$remotePath}/. {$releasePath}", "\t\n", ' '); // TODO Copy revision file (if it exists) for application to deployment path with release identifier $this->shell->executeOrSimulate($command, $node, $deployment); }