Permalink
Browse files

SelfUpdate Command

  • Loading branch information...
1 parent 6859d0e commit f86576419df4347c33015139c1c5cc7b56c65b3e Carlos Buenosvinos committed Feb 3, 2013
View
48 README.md
@@ -15,22 +15,56 @@ In most of the cases, you will be deploying to production and storing different
of your application, installing dependencies directly from your servers or rsyncing
from a deployer machine. So, using compify you can save bandwith or time when deploying.
-## Installation
+Installation
+------------
-Installing Compify is as easy as it can get. Download the [`compify.phar`][1]
-file and you're done! (or download it from the command line)
+### Locally
+
+Download the
+[`compify.phar`](https://raw.github.com/carlosbuenosvinos/compify/master/compify.phar) file and
+store it somewhere on your computer.
+
+### Globally
+
+You can run these commands to easily acces `compify` from anywhere on your system:
+
+ $ sudo wget https://raw.github.com/carlosbuenosvinos/compify/master/compify.phar -O /usr/local/bin/compify
+
+or with curl:
+
+ $ sudo curl https://raw.github.com/carlosbuenosvinos/compify/master/compify.phar -o /usr/local/bin/compify
+
+then:
+
+ $ sudo chmod a+x /usr/local/bin/compify
+
+Then, just run `compify` in order to run compify
+
+Update
+------
+
+### Locally
+
+The `self-update` command tries to update compify itself:
+
+ $ php compify.phar self-update
+
+### Globally
+
+You can update compify through this command:
+
+ $ sudo compify self-update
- curl -O https://raw.github.com/carlosbuenosvinos/compify/master/compify.phar
## Usage
php compify.phar crush --help
Usage:
crush [vendor-path]
-
+
Arguments:
vendor-path Composer vendor path (default: "./vendor")
-
+
Help:
The crush command removes all the
unnecessary files for each composer
@@ -102,5 +136,3 @@ For any issue use PR github system, for other info, send me an email to hi@carlo
## License
Compify is licensed under the MIT license.
-
-[1]: https://raw.github.com/carlosbuenosvinos/compify/master/compify.phar
View
BIN compify.phar
Binary file not shown.
View
71 src/CarlosIO/Compify/Command/SelfUpdateCommand.php
@@ -0,0 +1,71 @@
+<?php
+
+/*
+ * This file is part of Compify.
+ *
+ * (c) Carlos Buenosvinos <hi@carlos.io>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace CarlosIO\Compify\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * @author Carlos Buenosvinos <hi@carlos.io>
+ */
+class SelfUpdateCommand extends Command
+{
+ /**
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('self-update')
+ ->setDescription('Update compify.phar to the latest version.')
+ ->setHelp(<<<EOT
+The <info>self-update</info> command replace your compify.phar
+by the latest version from github.com.
+
+<info>php compify.phar self-update</info>
+
+EOT
+ )
+ ;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $remoteFilename = "https://raw.github.com/carlosbuenosvinos/compify/master/compify.phar";
+ $localFilename = $_SERVER['argv'][0];
+ $tempFilename = basename($localFilename, '.phar').'-temp.phar';
+
+ try {
+ copy($remoteFilename, $tempFilename);
+ chmod($tempFilename, 0777 & ~umask());
+
+ // test the phar validity
+ $phar = new \Phar($tempFilename);
+ // free the variable to unlock the file
+ unset($phar);
+ rename($tempFilename, $localFilename);
+ } catch (\Exception $e) {
+ if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
+ throw $e;
+ }
+ unlink($tempFilename);
+ $output->writeln('<error>The download is corrupt ('.$e->getMessage().').</error>');
+ $output->writeln('<error>Please re-run the self-update command to try again.</error>');
+ }
+
+ $output->writeln("<info>compify updated.</info>");
+ }
+}
View
1 src/CarlosIO/Compify/Console/Application.php
@@ -70,5 +70,6 @@ public function getComposer($required = true, $config = null)
protected function registerCommands()
{
$this->add(new Command\CrushCommand());
+ $this->add(new Command\SelfUpdateCommand());
}
}

0 comments on commit f865764

Please sign in to comment.