From 5751592463eb244af24522751dc5c1a008634efb Mon Sep 17 00:00:00 2001 From: Steve Robbins Date: Tue, 12 Feb 2019 09:58:37 -0800 Subject: [PATCH] Resolves #153: Remove self update command --- README.md | 6 - build/make-phar.sh | 25 --- src/MageScan/Command/SelfUpdateCommand.php | 182 --------------------- src/bootstrap.php | 4 +- 4 files changed, 1 insertion(+), 216 deletions(-) delete mode 100755 build/make-phar.sh delete mode 100644 src/MageScan/Command/SelfUpdateCommand.php diff --git a/README.md b/README.md index 830dd6a..abe9eb0 100644 --- a/README.md +++ b/README.md @@ -138,12 +138,6 @@ Get the version of a Magento installation Show all modules that we tried to detect, not just those that were found -### `self-update` - - $ magescan.phar self-update - -Updates the phar file to the latest version. - # Disclaimer Since we can't see the code base, this tool makes assumptions and takes guesses. Information reported isn't guaranteed to be correct. diff --git a/build/make-phar.sh b/build/make-phar.sh deleted file mode 100755 index 1fbe085..0000000 --- a/build/make-phar.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -ROOT=/var/www/magescan.steverobbins.com -REQUEST=$ROOT/build/request -BIN_BOX=$ROOT/build/box.phar -BIN_COMPOSER=/usr/local/bin/composer -REPO_URL=https://github.com/steverobbins/magescan.git -REPO_FOLDER=$ROOT/build/magescan -PHAR_DEST=$ROOT/public/download/magescan.phar -VERSION=$ROOT/public/download/version - -if [ ! -f $REQUEST ]; then - exit 0 -fi - -rm -rf $REPO_FOLDER $REQUEST -git clone $REPO_URL $REPO_FOLDER -cd $REPO_FOLDER -$BIN_COMPOSER --no-dev install -ulimit -Sn 4096 -$BIN_BOX build -c box.json -rm -f $PHAR_DEST -mv $REPO_FOLDER/magescan.phar $PHAR_DEST -php $PHAR_DEST --version | sed -r 's/Mage Scan version //g' > $VERSION -echo Done diff --git a/src/MageScan/Command/SelfUpdateCommand.php b/src/MageScan/Command/SelfUpdateCommand.php deleted file mode 100644 index 48d8b13..0000000 --- a/src/MageScan/Command/SelfUpdateCommand.php +++ /dev/null @@ -1,182 +0,0 @@ - - * @copyright 2015 Steve Robbins - * @license http://creativecommons.org/licenses/by/4.0/ CC BY 4.0 - * @link https://github.com/steverobbins/magescan - */ - -namespace MageScan\Command; - -use MageScan\Request; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; - -/** - * Update magescan to latest version - * - * @category MageScan - * @package MageScan - * @author Steve Robbins - * @copyright 2015 Steve Robbins - * @license http://creativecommons.org/licenses/by/4.0/ CC BY 4.0 - * @link https://github.com/steverobbins/magescan - */ -class SelfUpdateCommand extends Command -{ - const URL_VERSION = 'http://magescan.steverobbins.com/download/version'; - const URL_DOWNLOAD = 'http://magescan.steverobbins.com/download/magescan.phar'; - - /** - * Configure selfupdate command - * - * @return void - */ - protected function configure() - { - $this - ->setName('self-update') - ->setDescription('Updates magescan.phar to the latest version') - ->setHelp(<<selfupdate command checks the homepage for newer -versions of magescan and if found, installs the latest. - -php magescan.phar selfupdate -EOT - ); - } - - /** - * Run selfupdate command - * - * @param InputInterface $input - * @param OutputInterface $output - * - * @return void - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $localFilename = $this->getCurrentFile(); - $tempFilename = $this->getTempFile($localFilename); - $version = $this->getApplication()->getVersion(); - $latest = $this->checkLatestVersion(); - if (version_compare($version, $latest) >= 0) { - return $output->writeln(sprintf( - 'You are using the latest version %s', - $version - )); - } - $output->writeln(sprintf( - 'Updating from %s to %s', - $version, - $latest - )); - if (!$this->downloadLatestVersion($tempFilename)) { - return $output->writeln( - 'The download failed unexpectedly' - ); - } - $test = $this->testPharValidity($tempFilename); - if ($test !== true) { - unlink($tempFilename); - return $output->writeln('Update failed ' . $test); - } - chmod($tempFilename, 0777 & ~umask()); - rename($tempFilename, $localFilename); - $output->writeln('Mage Scan successfully updated'); - } - - /** - * Gets the path/name of the local executable file - * - * @return string - * - * @throws Exception - */ - protected function getCurrentFile() - { - $file = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; - if (!is_writable($file)) { - throw new Exception( - 'Update failed: "' . $file . '" is not writable' - ); - } - return $file; - } - - /** - * Gets the path/name of the temporary download file - * - * @param string $currentFile - * - * @return string - * - * @throws Exception - */ - protected function getTempFile($currentFile) - { - $file = dirname($currentFile) . DIRECTORY_SEPARATOR - . basename($currentFile, '.phar') . '-temp.phar'; - if (!is_writable($dir = dirname($file))) { - throw new Exception( - 'Update failed: "' . $dir . '" is not writable' - ); - } - return $file; - } - - /** - * Test that the downloaded phar is valid - * - * @param string $file - * - * @return boolean|string - */ - protected function testPharValidity($file) - { - try { - new \Phar($file); - } catch (\Exception $e) { - return $e->getMessage(); - } - return true; - } - - /** - * Fetch version number of latest release - * - * @return string - * - * @throws Exception - */ - protected function checkLatestVersion() - { - $request = new Request(self::URL_VERSION); - $response = $request->get(); - if ($response->getStatusCode() !== 200) { - throw new \Exception('Error fetching latest version'); - } - return trim($response->getBody()->getContents()); - } - - /** - * Download the latest version of magescan - * - * @param string $filename - * - * @return void - */ - protected function downloadLatestVersion($filename) - { - $request = new Request(self::URL_DOWNLOAD); - $response = $request->get(); - return file_put_contents($filename, $response->getBody()->getContents()) !== false; - } -} diff --git a/src/bootstrap.php b/src/bootstrap.php index a27f2be..3ca210f 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -22,10 +22,9 @@ use MageScan\Command\Scan\SitemapCommand; use MageScan\Command\Scan\VersionCommand; use MageScan\Command\Scan\UnreachableCommand; -use MageScan\Command\SelfUpdateCommand; use Symfony\Component\Console\Application; -$app = new Application('Mage Scan', '1.12.8'); +$app = new Application('Mage Scan', '1.12.9'); $app->add(new AllCommand); $app->add(new VersionCommand); @@ -35,6 +34,5 @@ $app->add(new SitemapCommand); $app->add(new ServerCommand); $app->add(new UnreachableCommand); -$app->add(new SelfUpdateCommand); $app->run();