gpm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env php
  2. <?php
  3. use Grav\Common\Composer;
  4. use Symfony\Component\Console\Application;
  5. use Grav\Common\Grav;
  6. \define('GRAV_CLI', true);
  7. \define('GRAV_REQUEST_TIME', microtime(true));
  8. if (!file_exists(__DIR__ . '/../vendor/autoload.php')){
  9. // Before we can even start, we need to run composer first
  10. require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
  11. $composer = Composer::getComposerExecutor();
  12. echo "Preparing to install vendor dependencies...\n\n";
  13. echo system($composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install');
  14. echo "\n\n";
  15. }
  16. $autoload = require __DIR__ . '/../vendor/autoload.php';
  17. if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
  18. exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
  19. }
  20. if (!ini_get('date.timezone')) {
  21. date_default_timezone_set('UTC');
  22. }
  23. // Set internal encoding.
  24. if (!\extension_loaded('mbstring')) {
  25. die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
  26. }
  27. @ini_set('default_charset', 'UTF-8');
  28. mb_internal_encoding('UTF-8');
  29. if (!file_exists(GRAV_ROOT . '/index.php')) {
  30. exit('FATAL: Must be run from ROOT directory of Grav!');
  31. }
  32. if (!function_exists('curl_version')) {
  33. exit('FATAL: GPM requires PHP Curl module to be installed');
  34. }
  35. $climate = new League\CLImate\CLImate;
  36. $climate->arguments->add([
  37. 'environment' => [
  38. 'prefix' => 'e',
  39. 'longPrefix' => 'env',
  40. 'description' => 'Configuration Environment',
  41. 'defaultValue' => 'localhost'
  42. ]
  43. ]);
  44. $climate->arguments->parse();
  45. // Set up environment based on params.
  46. $environment = $climate->arguments->get('environment');
  47. $grav = Grav::instance(array('loader' => $autoload));
  48. $grav->setup($environment);
  49. $grav['config']->init();
  50. $grav['uri']->init();
  51. $grav['accounts'];
  52. $app = new Application('Grav Package Manager', GRAV_VERSION);
  53. $app->addCommands(array(
  54. new \Grav\Console\Gpm\IndexCommand(),
  55. new \Grav\Console\Gpm\VersionCommand(),
  56. new \Grav\Console\Gpm\InfoCommand(),
  57. new \Grav\Console\Gpm\InstallCommand(),
  58. new \Grav\Console\Gpm\UninstallCommand(),
  59. new \Grav\Console\Gpm\UpdateCommand(),
  60. new \Grav\Console\Gpm\SelfupgradeCommand(),
  61. new \Grav\Console\Gpm\DirectInstallCommand(),
  62. ));
  63. $app->run();