From dca0cbc93ab3e430a495000e8e32c62ed3da4995 Mon Sep 17 00:00:00 2001 From: digitalkaoz Date: Mon, 23 Jan 2012 12:10:49 +0100 Subject: [PATCH] added installer script --- README.md | 7 ++- bin/installer | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 2 deletions(-) create mode 100755 bin/installer diff --git a/README.md b/README.md index e3b20a3af..79cfb19c9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ See the [about page](http://packagist.org/about) on [packagist.org](http://packa Installation / Usage -------------------- -1. Download the [`composer.phar`](http://getcomposer.org/composer.phar) executable +1. Download the [`composer.phar`](http://getcomposer.org/composer.phar) executable or use the installer. + + $ curl http://getcomposer.org/installer | php + 2. Create a composer.json defining your dependencies. Note that this example is a short version for applications that are not meant to be published as packages themselves. To create libraries/packages please read the [guidelines](http://packagist.org/about). @@ -43,7 +46,7 @@ Since composer works with the current working directory it is possible to instal in a system wide way. 1. Change into a directory in your path like `cd /usr/local/bin` -2. Get composer `wget http://getcomposer.org/composer.phar` +2. Get composer `curl http://getcomposer.org/installer | php` 3. Make the phar executeable `chmod a+x composer.phar` 3. Change into a project directory `cd /path/to/my/project` 4. Use composer as you normally would `composer.phar install` diff --git a/bin/installer b/bin/installer new file mode 100755 index 000000000..798757f64 --- /dev/null +++ b/bin/installer @@ -0,0 +1,151 @@ +#!/usr/bin/env php + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + +process($argv); + +/** + * processes the installer + */ +function process($argv) +{ + $check = in_array('--check', $argv); + $help = in_array('--help', $argv); + $force = in_array('--force', $argv); + + if ($help) { + displayHelp(); + exit(0); + } + + $ok = checkPlatform(); + + if ($check && !$ok) { + exit(1); + } + + if ($ok || $force) { + installComposer(); + } + + exit(0); +} + +/** + * displays the help + */ +function displayHelp() +{ + echo << $actual) { + switch ($error) { + case 'unicode': + $text = " detect_unicode = Off (actual: {$actual})".PHP_EOL; + break; + + case 'readonly': + $text = " phar.readonly = Off (actual: {$actual})".PHP_EOL; + break; + + case 'require_hash': + $text = " phar.require_hash = Off (actual: {$actual})".PHP_EOL; + break; + + case 'suhosin': + $text = " suhosin.executor.include.whitelist = phar (actual: {$actual})".PHP_EOL; + break; + case 'php': + $text = " PHP_VERSION (actual: {$actual})".PHP_EOL; + break; + } + out($text, 'info'); + } + echo PHP_EOL; + return false; + } + + out("All settings correct for using Composer".PHP_EOL,'success'); + return true; +} + +/** + * installs composer to the current working directory + */ +function installComposer() +{ + $installDir = getcwd(); + $file = $installDir . DIRECTORY_SEPARATOR . 'composer.phar'; + + if (is_readable($file)) { + @unlink($file); + } + + $download = copy('http://getcomposer.org/composer.phar', $installDir.DIRECTORY_SEPARATOR.'composer.phar'); + + out(PHP_EOL."Composer successfully installed to: " . $file, 'success'); + out(PHP_EOL."Use it: php composer.phar".PHP_EOL, 'info'); +} + +/** + * colorize output + */ +function out($text, $color = null) +{ + $styles = array( + 'success' => "\033[0;32m%s\033[0m", + 'error' => "\033[31;31m%s\033[0m", + 'info' => "\033[33;33m%s\033[0m" + ); + + echo sprintf(isset($styles[$color]) ? $styles[$color] : "%s", $text); +} \ No newline at end of file