gpm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if (!file_exists(GRAV_ROOT . '/index.php')) {
  24. exit('FATAL: Must be run from ROOT directory of Grav!');
  25. }
  26. if (!function_exists('curl_version')) {
  27. exit('FATAL: GPM requires PHP Curl module to be installed');
  28. }
  29. $climate = new League\CLImate\CLImate;
  30. $climate->arguments->add([
  31. 'environment' => [
  32. 'prefix' => 'e',
  33. 'longPrefix' => 'env',
  34. 'description' => 'Configuration Environment',
  35. 'defaultValue' => 'localhost'
  36. ]
  37. ]);
  38. $climate->arguments->parse();
  39. // Set up environment based on params.
  40. $environment = $climate->arguments->get('environment');
  41. $grav = Grav::instance(array('loader' => $autoload));
  42. $grav->setup($environment);
  43. $grav['config']->init();
  44. $grav['uri']->init();
  45. $grav['users'];
  46. $app = new Application('Grav Package Manager', GRAV_VERSION);
  47. $app->addCommands(array(
  48. new \Grav\Console\Gpm\IndexCommand(),
  49. new \Grav\Console\Gpm\VersionCommand(),
  50. new \Grav\Console\Gpm\InfoCommand(),
  51. new \Grav\Console\Gpm\InstallCommand(),
  52. new \Grav\Console\Gpm\UninstallCommand(),
  53. new \Grav\Console\Gpm\UpdateCommand(),
  54. new \Grav\Console\Gpm\SelfupgradeCommand(),
  55. new \Grav\Console\Gpm\DirectInstallCommand(),
  56. ));
  57. $app->run();