From 1b1a43ce1140a7c4c4128d76ed1243d0d20b7c70 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Wed, 22 May 2019 12:11:58 +0300 Subject: fix linux download --- bin/rr | 285 ---------------------------------------------------------- composer.json | 2 +- src/bin/rr | 285 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+), 286 deletions(-) delete mode 100644 bin/rr create mode 100644 src/bin/rr diff --git a/bin/rr b/bin/rr deleted file mode 100644 index 633b5a25..00000000 --- a/bin/rr +++ /dev/null @@ -1,285 +0,0 @@ -#!/usr/bin/env php -open($archive); - - $name = self::getSignature() . '/rr'; - if (self::getOSType() == 'windows') { - $name .= '.exe'; - } - - $stream = $zip->getStream($name); - if (!is_resource($stream)) { - return; - } - - $to = fopen($target, 'w'); - stream_copy_to_stream($stream, $to); - fclose($to); - - $zip->close(); - } - - /** - * @param string $archive - * @param string $target - * @throws Exception - */ - protected function extractTAR(string $archive, string $target) - { - $arch = new PharData($archive); - $arch->extractTo('./', self::getSignature() . '/rr'); - - copy('./' . self::getSignature() . '/rr', $target); - unlink('./' . self::getSignature() . '/rr'); - rmdir('./' . self::getSignature()); - } -} - -(new Application('RoadRunner', RRHelper::getVersion())) - ->register('get-binary') - ->setDescription("Install or update RoadRunner binaries in specified folder (current folder by default)") - ->addOption('location', 'l', InputArgument::OPTIONAL, 'destination folder', '.') - ->setCode(function (InputInterface $input, OutputInterface $output) { - $output->writeln('Updating binary file of RoadRunner'); - - $finalFile = $input->getOption('location') . DIRECTORY_SEPARATOR . 'rr'; - if (RRHelper::getOSType() == 'windows') { - $finalFile .= '.exe'; - } - - if (is_file($finalFile)) { - $output->writeln('RoadRunner binary file already exists!'); - $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion('Do you want overwrite it? [Y/n] '); - - if (!$helper->ask($input, $output, $question)) { - return; - } - } - - $output->writeln('Downloading RoadRunner archive for ' . ucfirst(RRHelper::getOSType()) . ''); - - $progressBar = new ProgressBar($output); - $progressBar->setFormat('verbose'); - - $zipFileName = tempnam('.', "rr_zip"); - if (RRHelper::getOSType() == 'linux') { - $zipFileName .= '.tar.gz'; - } - - $zipFile = fopen($zipFileName, "w+"); - $curlResource = curl_init(); - - curl_setopt($curlResource, CURLOPT_URL, RRHelper::getBinaryDownloadUrl()); - curl_setopt($curlResource, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curlResource, CURLOPT_BINARYTRANSFER, true); - curl_setopt($curlResource, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($curlResource, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curlResource, CURLOPT_FILE, $zipFile); - curl_setopt($curlResource, CURLOPT_PROGRESSFUNCTION, - function ($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($progressBar) { - if ($download_size == 0) { - return; - } - - if ($progressBar->getStartTime() === 0) { - $progressBar->start(); - } - - $progressBar->setFormat('[%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% ' . intval($download_size / 1024) . 'KB'); - $progressBar->setMaxSteps($download_size); - $progressBar->setProgress($downloaded); - }); - curl_setopt($curlResource, CURLOPT_NOPROGRESS, false); // needed to make progress function work - curl_setopt($curlResource, CURLOPT_HEADER, 0); - curl_exec($curlResource); - curl_close($curlResource); - fclose($zipFile); - - $progressBar->finish(); - $output->writeln(""); - - $output->writeln('Unpacking ' . basename(RRHelper::getBinaryDownloadUrl()) . ''); - - RRHelper::extractBinary($zipFileName, $finalFile); - unlink($zipFileName); - - if (!file_exists($finalFile) || filesize($finalFile) === 0) { - throw new Exception('Unable to extract the file.'); - } - - chmod($finalFile, 0755); - $output->writeln('Binary file updated!'); - }) - ->getApplication() - ->register("init-config") - ->setDescription("Inits default .rr.yaml config in specified folder (current folder by default)") - ->addOption('location', 'l', InputArgument::OPTIONAL, 'destination folder', '.') - ->setCode(function (InputInterface $input, OutputInterface $output) { - if (is_file($input->getOption('location') . DIRECTORY_SEPARATOR . '.rr.yaml')) { - $output->writeln('Config file already exists!'); - $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion('Do you want overwrite it? [Y/n] '); - - if (!$helper->ask($input, $output, $question)) { - return; - } - } - - copy( - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '.rr.yaml', - $input->getOption('location') . DIRECTORY_SEPARATOR . '.rr.yaml' - ); - $output->writeln('Config file created!'); - }) - ->getApplication() - ->run(); diff --git a/composer.json b/composer.json index 323d2ac3..e59f0459 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,6 @@ } }, "bin": [ - "bin/rr" + "src/bin/rr" ] } diff --git a/src/bin/rr b/src/bin/rr new file mode 100644 index 00000000..633b5a25 --- /dev/null +++ b/src/bin/rr @@ -0,0 +1,285 @@ +#!/usr/bin/env php +open($archive); + + $name = self::getSignature() . '/rr'; + if (self::getOSType() == 'windows') { + $name .= '.exe'; + } + + $stream = $zip->getStream($name); + if (!is_resource($stream)) { + return; + } + + $to = fopen($target, 'w'); + stream_copy_to_stream($stream, $to); + fclose($to); + + $zip->close(); + } + + /** + * @param string $archive + * @param string $target + * @throws Exception + */ + protected function extractTAR(string $archive, string $target) + { + $arch = new PharData($archive); + $arch->extractTo('./', self::getSignature() . '/rr'); + + copy('./' . self::getSignature() . '/rr', $target); + unlink('./' . self::getSignature() . '/rr'); + rmdir('./' . self::getSignature()); + } +} + +(new Application('RoadRunner', RRHelper::getVersion())) + ->register('get-binary') + ->setDescription("Install or update RoadRunner binaries in specified folder (current folder by default)") + ->addOption('location', 'l', InputArgument::OPTIONAL, 'destination folder', '.') + ->setCode(function (InputInterface $input, OutputInterface $output) { + $output->writeln('Updating binary file of RoadRunner'); + + $finalFile = $input->getOption('location') . DIRECTORY_SEPARATOR . 'rr'; + if (RRHelper::getOSType() == 'windows') { + $finalFile .= '.exe'; + } + + if (is_file($finalFile)) { + $output->writeln('RoadRunner binary file already exists!'); + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion('Do you want overwrite it? [Y/n] '); + + if (!$helper->ask($input, $output, $question)) { + return; + } + } + + $output->writeln('Downloading RoadRunner archive for ' . ucfirst(RRHelper::getOSType()) . ''); + + $progressBar = new ProgressBar($output); + $progressBar->setFormat('verbose'); + + $zipFileName = tempnam('.', "rr_zip"); + if (RRHelper::getOSType() == 'linux') { + $zipFileName .= '.tar.gz'; + } + + $zipFile = fopen($zipFileName, "w+"); + $curlResource = curl_init(); + + curl_setopt($curlResource, CURLOPT_URL, RRHelper::getBinaryDownloadUrl()); + curl_setopt($curlResource, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curlResource, CURLOPT_BINARYTRANSFER, true); + curl_setopt($curlResource, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curlResource, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curlResource, CURLOPT_FILE, $zipFile); + curl_setopt($curlResource, CURLOPT_PROGRESSFUNCTION, + function ($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($progressBar) { + if ($download_size == 0) { + return; + } + + if ($progressBar->getStartTime() === 0) { + $progressBar->start(); + } + + $progressBar->setFormat('[%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% ' . intval($download_size / 1024) . 'KB'); + $progressBar->setMaxSteps($download_size); + $progressBar->setProgress($downloaded); + }); + curl_setopt($curlResource, CURLOPT_NOPROGRESS, false); // needed to make progress function work + curl_setopt($curlResource, CURLOPT_HEADER, 0); + curl_exec($curlResource); + curl_close($curlResource); + fclose($zipFile); + + $progressBar->finish(); + $output->writeln(""); + + $output->writeln('Unpacking ' . basename(RRHelper::getBinaryDownloadUrl()) . ''); + + RRHelper::extractBinary($zipFileName, $finalFile); + unlink($zipFileName); + + if (!file_exists($finalFile) || filesize($finalFile) === 0) { + throw new Exception('Unable to extract the file.'); + } + + chmod($finalFile, 0755); + $output->writeln('Binary file updated!'); + }) + ->getApplication() + ->register("init-config") + ->setDescription("Inits default .rr.yaml config in specified folder (current folder by default)") + ->addOption('location', 'l', InputArgument::OPTIONAL, 'destination folder', '.') + ->setCode(function (InputInterface $input, OutputInterface $output) { + if (is_file($input->getOption('location') . DIRECTORY_SEPARATOR . '.rr.yaml')) { + $output->writeln('Config file already exists!'); + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion('Do you want overwrite it? [Y/n] '); + + if (!$helper->ask($input, $output, $question)) { + return; + } + } + + copy( + __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '.rr.yaml', + $input->getOption('location') . DIRECTORY_SEPARATOR . '.rr.yaml' + ); + $output->writeln('Config file created!'); + }) + ->getApplication() + ->run(); -- cgit v1.2.3