├── bin ├── club └── application.php ├── Resources ├── available_ingredients.yml └── templates │ └── aliases.php.twig ├── tests ├── recipes │ └── good.yml └── phpunit │ ├── ApplicationTest.php │ ├── TestBase.php │ ├── Command │ ├── Fixtures │ │ └── ExampleCommand.php │ └── CommandBaseTest.php │ └── CreateProjectCommandTest.php ├── phpunit.xml.dist ├── src ├── Command │ ├── LocalEnvironmentFacade.php │ ├── PullProjectCommand.php │ ├── ACAliasesCommand.php │ ├── CommandBase.php │ └── CreateProjectCommand.php ├── Loader │ └── JsonFileLoader.php └── Configuration │ └── ProjectConfiguration.php ├── .editorconfig ├── .acquia ├── Dockerfile.ci └── pipeline.yaml ├── box.json ├── .gitignore ├── CONTRIBUTING.md ├── RELEASE.md ├── composer.json ├── CHANGELOG.md ├── README.md └── LICENSE.txt /bin/club: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 2 | 3 | 4 | 5 | tests/phpunit 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Command/LocalEnvironmentFacade.php: -------------------------------------------------------------------------------- 1 | assertContains($expected, $output); 20 | } 21 | 22 | /** 23 | * Provides values to testApplication(). 24 | * 25 | * @return array 26 | * An array of values to test. 27 | */ 28 | public function getValueProvider() 29 | { 30 | return [ 31 | ['create-project'], 32 | ['pull-project'], 33 | ['ac-aliases'], 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/phpunit/TestBase.php: -------------------------------------------------------------------------------- 1 | application = new Application(); 31 | $this->local_environment_facade = $this->createMock(LocalEnvironmentFacade::class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Loader/JsonFileLoader.php: -------------------------------------------------------------------------------- 1 | getJSONErrorMessage($errorCode) 19 | )); 20 | } 21 | } 22 | 23 | return $config; 24 | } 25 | 26 | public function supports($resource, $type = null) 27 | { 28 | $ext = pathinfo($resource, PATHINFO_EXTENSION); 29 | return is_string($resource) && ('json' === $ext || 'conf' === $ext); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /bin/application.php: -------------------------------------------------------------------------------- 1 | new LocalEnvironmentFacade(), 20 | ]; 21 | 22 | $application->addCommands([ 23 | new CreateProjectCommand($container['localEnvironmentFacade']), 24 | new PullProjectCommand($container['localEnvironmentFacade']), 25 | new AcAliasesCommand($container['localEnvironmentFacade']), 26 | ]); 27 | $application->run(); 28 | -------------------------------------------------------------------------------- /tests/phpunit/Command/Fixtures/ExampleCommand.php: -------------------------------------------------------------------------------- 1 | output = $output; 17 | } 18 | 19 | /** 20 | * @param \Symfony\Component\Console\Input\InputInterface $input 21 | */ 22 | public function setInput(InputInterface $input) { 23 | $this->input = $input; 24 | } 25 | 26 | /** 27 | * @param \Symfony\Component\Console\Helper\QuestionHelper $question_helper 28 | */ 29 | public function setQuestionHelper(QuestionHelper $question_helper) { 30 | $this->questionHelper = $question_helper; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Releases 2 | 3 | The following are steps for releasing a new version of club. 4 | 5 | ## Git steps 6 | ``` 7 | git tag VERSION_NUMBER 8 | git push origin master 9 | ``` 10 | 11 | ## Building a phar file 12 | ``` 13 | ./vendor/bin/box build 14 | ``` 15 | 16 | ## Github steps 17 | 1. Create a new [release](https://github.com/acquia/club/releases/new]) 18 | 2. Add Release notes with [changelog generator](https://github.com/skywinder/github-changelog-generator) 19 | 3. Upload club.phar 20 | 4. Click Publish release 21 | 22 | 23 | 24 | ## Troubleshooting. 25 | ### Box phar build fails 26 | Symfony has an issue when building phars sometimes and errors with the following: 27 | ``` 28 | PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): unable to create pipe Too many open files' in phar:///usr/local/bin/box.phar/src/vendors/symfony/console/Application.php:954 29 | ``` 30 | 31 | Workaround: 32 | ``` 33 | ulimit -Sn 4096 34 | ``` 35 | ### ./vendor/bin/box not found 36 | Make sure you are on latest github master code and run 37 | `composer install` 38 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "acquia/club", 3 | "description": "Allows BLT projects to be created or cloned from Acquia Cloud.", 4 | "type": "library", 5 | "require": { 6 | "symfony/console": "^3.1", 7 | "acquia/acquia-sdk-php-cloud-api": "^0.10.7", 8 | "symfony/yaml": "^3.1", 9 | "symfony/config": "^3.1", 10 | "symfony/process": "^3.1", 11 | "tivie/php-os-detector": "1.0", 12 | "twig/twig": "~1.0", 13 | "vierbergenlars/php-semver": "^3.0", 14 | "dflydev/dot-access-data": "^1.0" 15 | }, 16 | "license": "GPL-2.0", 17 | "authors": [ 18 | { 19 | "name": "Matthew Grasmick", 20 | "email": "matthew.grasmick@acquia.com" 21 | } 22 | ], 23 | "minimum-stability": "dev", 24 | "prefer-stable": true, 25 | "autoload": { 26 | "psr-4": {"Acquia\\Club\\": "src/"} 27 | }, 28 | "autoload-dev": { 29 | "psr-4": {"Acquia\\Club\\Tests\\": "tests/phpunit/"} 30 | }, 31 | "bin": [ 32 | "bin/club" 33 | ], 34 | "require-dev": { 35 | "kherge/box": "^2.7", 36 | "phpunit/phpunit": "^5.5.4", 37 | "squizlabs/php_codesniffer": "^2.7" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Resources/templates/aliases.php.twig: -------------------------------------------------------------------------------- 1 | '{{alias["parent"]}}', 17 | 'uri' => '{{alias["uri"]}}', 18 | ); 19 | {% elseif alias["group"] %} 20 | $aliases['{{alias["env"]}}'] = array( 21 | 'site-list' => array( 22 | {% for groupalias in alias["aliases"] %} 23 | '{{groupalias}}', 24 | {% endfor %} 25 | ), 26 | ); 27 | {% else %} 28 | // Site {{alias["ac-site"]}}, environment {{alias["env-name"]}}. 29 | $aliases['{{alias["ac-env"]}}'] = array( 30 | 'root' => '{{alias["root"]}}', 31 | 'ac-site' => '{{alias["ac-site"]}}', 32 | 'ac-env' => '{{alias["env-name"]}}', 33 | 'ac-realm' => '{{alias["ac-realm"]}}', 34 | 'uri' => '{{alias["uri"]}}', 35 | 'remote-host' => '{{alias["remote-host"]}}', 36 | 'remote-user' => '{{alias["remote-user"]}}', 37 | 'path-aliases' => array( 38 | '%drush-script' => 'drush' . $drush_major_version, 39 | ), 40 | ); 41 | $aliases['{{alias["ac-env"]}}.livedev'] = array( 42 | 'parent' => '@{{alias["ac-site"]}}.{{alias["ac-env"]}}', 43 | 'root' => '/mnt/gfs/{{alias["ac-site"]}}.{{alias["ac-env"]}}/livedev/docroot', 44 | ); 45 | {% endif %} 46 | {% endfor %} 47 | -------------------------------------------------------------------------------- /src/Configuration/ProjectConfiguration.php: -------------------------------------------------------------------------------- 1 | root('project'); 14 | 15 | $rootNode 16 | ->children() 17 | ->scalarNode('human_name') 18 | ->info('The human readable name of the project.') 19 | ->cannotBeEmpty() 20 | ->isRequired() 21 | ->end() 22 | ->scalarNode('machine_name') 23 | ->info('The machine readable name of the project.') 24 | ->cannotBeEmpty() 25 | ->isRequired() 26 | ->end() 27 | ->scalarNode('prefix') 28 | ->info('The project prefix, used for commit message validation.') 29 | ->cannotBeEmpty() 30 | ->isRequired() 31 | ->end() 32 | ->booleanNode('vm') 33 | ->isRequired() 34 | ->end() 35 | ->arrayNode('ci') 36 | ->children() 37 | ->scalarNode('provider') 38 | ->isRequired() 39 | ->cannotBeEmpty() 40 | ->defaultValue('pipelines') 41 | ->validate() 42 | ->ifNotInArray(['pipelines', 'travis_ci']) 43 | ->thenInvalid('Invalid continuous integration provider %s') 44 | ->end() 45 | ->end() 46 | ->end() 47 | ->end() 48 | ->arrayNode('ac') 49 | ->children() 50 | ->scalarNode('site') 51 | ->isRequired() 52 | ->cannotBeEmpty() 53 | ->end() 54 | ->scalarNode('env') 55 | ->isRequired() 56 | ->cannotBeEmpty() 57 | ->defaultValue('dev') 58 | ->end() 59 | ->end() 60 | ->end() 61 | ->arrayNode('ingredients') 62 | ->info('A flat array of ingredients. E.g. acquia-blog.') 63 | ->prototype('scalar') 64 | ->end() 65 | ->end() 66 | ; 67 | 68 | return $treeBuilder; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/phpunit/Command/CommandBaseTest.php: -------------------------------------------------------------------------------- 1 | local_environment_facade = $this->createMock(LocalEnvironmentFacade::class); 33 | $this->input = $this->createMock(InputInterface::class); 34 | $this->output = $this->createMock(OutputInterface::class); 35 | $this->question_helper = $this->createMock(QuestionHelper::class); 36 | } 37 | 38 | /** 39 | * @param bool $xdebug_enabled 40 | * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $call_writeln 41 | * 42 | * @dataProvider providerTestCheckXdebugOutput 43 | */ 44 | public function testCheckXdebugOutput($xdebug_enabled, $call_writeln) 45 | { 46 | // Set expectations. 47 | $this->local_environment_facade 48 | ->method('isPhpExtensionLoaded') 49 | ->willReturn($xdebug_enabled); 50 | $this->output 51 | ->expects($call_writeln) 52 | ->method('writeln'); 53 | 54 | // Create command. 55 | $command = $this->createExampleCommand(); 56 | 57 | // Call method checkXdebug(). 58 | $command->checkXdebug(); 59 | 60 | // @todo Verify that askContinue() was/was not called. 61 | } 62 | 63 | /** 64 | * @return array 65 | */ 66 | public function providerTestCheckXdebugOutput() { 67 | return [ 68 | [TRUE, $this->once()], 69 | [FALSE, $this->never()] 70 | ]; 71 | } 72 | 73 | /** 74 | * @return \Acquia\Club\Tests\Command\Fixtures\ExampleCommand 75 | */ 76 | public function createExampleCommand() { 77 | $command = new ExampleCommand($this->local_environment_facade); 78 | $command->setInput($this->input); 79 | $command->setOutput($this->output); 80 | $command->setQuestionHelper($this->question_helper); 81 | 82 | return $command; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [0.4](https://github.com/acquia/club/tree/0.4) (2017-01-04) 4 | [Full Changelog](https://github.com/acquia/club/compare/0.3...0.4) 5 | 6 | **Fixed bugs:** 7 | 8 | - Twig aliases file incorrectly comments as all aliases being prod. [\#20](https://github.com/acquia/club/issues/20) 9 | - Aliases for ACSF URI's are incorrectly made for dev and stage [\#21](https://github.com/acquia/club/issues/21) 10 | 11 | ## [0.3](https://github.com/acquia/club/tree/0.3) (2017-01-04) 12 | [Full Changelog](https://github.com/acquia/club/compare/0.2...0.3) 13 | 14 | **Fixed bugs:** 15 | 16 | - Cloud API push fails with an error [\#14](https://github.com/acquia/club/issues/14) 17 | 18 | **Merged pull requests:** 19 | 20 | - Adds in dev stage and prod site group [\#19](https://github.com/acquia/club/pull/19) ([kylebrowning](https://github.com/kylebrowning)) 21 | - Fixes usage of cloudApiConfig in create project [\#16](https://github.com/acquia/club/pull/16) ([kylebrowning](https://github.com/kylebrowning)) 22 | 23 | ## [0.2](https://github.com/acquia/club/tree/0.2) (2016-12-27) 24 | [Full Changelog](https://github.com/acquia/club/compare/0.1...0.2) 25 | 26 | **Closed issues:** 27 | 28 | - Box dependency [\#9](https://github.com/acquia/club/issues/9) 29 | - Homebrew install not working [\#8](https://github.com/acquia/club/issues/8) 30 | 31 | **Merged pull requests:** 32 | 33 | - Adding misc fixes, lightning extension usage. [\#13](https://github.com/acquia/club/pull/13) ([grasmash](https://github.com/grasmash)) 34 | - Fixes space after while for passing build. [\#12](https://github.com/acquia/club/pull/12) ([kylebrowning](https://github.com/kylebrowning)) 35 | - Adding support for ingredients. [\#11](https://github.com/acquia/club/pull/11) ([grasmash](https://github.com/grasmash)) 36 | - Adds RELEASE.MD, updates some composer requires. [\#10](https://github.com/acquia/club/pull/10) ([kylebrowning](https://github.com/kylebrowning)) 37 | - Fixes a typo in File name inclusion [\#7](https://github.com/acquia/club/pull/7) ([kylebrowning](https://github.com/kylebrowning)) 38 | 39 | ## [0.1](https://github.com/acquia/club/tree/0.1) (2016-10-18) 40 | **Merged pull requests:** 41 | 42 | - PHPCBF PSR2 fixes. [\#6](https://github.com/acquia/club/pull/6) ([grasmash](https://github.com/grasmash)) 43 | - Updating lock file. [\#5](https://github.com/acquia/club/pull/5) ([grasmash](https://github.com/grasmash)) 44 | - Verifying BLT version. [\#4](https://github.com/acquia/club/pull/4) ([grasmash](https://github.com/grasmash)) 45 | - Updating readme [\#3](https://github.com/acquia/club/pull/3) ([kylebrowning](https://github.com/kylebrowning)) 46 | - Updates ACAliases to pulll down ACSF aliases [\#2](https://github.com/acquia/club/pull/2) ([kylebrowning](https://github.com/kylebrowning)) 47 | - Updates to build phar and prep for Brew formula [\#1](https://github.com/acquia/club/pull/1) ([kylebrowning](https://github.com/kylebrowning)) 48 | 49 | 50 | 51 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.com/acquia/club.svg?token=eFBAT6vQ9cqDh1Sed5Mw&branch=master)](https://travis-ci.com/acquia/club) 2 | 3 | **Club does not currently have a stable release. It should be considered experimental.** 4 | 5 | # Club: Command Line Utility for BLT 6 | 7 | `club` is a command line utility for managing BLT and accessing Acquia cloud resources. 8 | 9 | 10 | ------- 11 |

12 | Features • 13 | Installation • 14 | Usage • 15 | Contributing 16 |

17 | 18 | ------- 19 | 20 | ## Features 21 | 22 | | :metal: | club 23 | --------------------------|------------------------------------------------------------ 24 | :sparkles: | Generate aliases for ACSF and AC that are attached to your account. 25 | :rocket: | Pull existing projects from Acquia Cloud and automatically load them into a VM. 26 | :wrench: | Create new projects for BLT 27 | :cake: | build recipes to deploy consistent projects throughout your team. 28 | 29 | ## Installation 30 | Currently `club` supports 3 installation methods. Preferred installation method is homebrew as it will ensure all dependencies are install on your system. 31 | 32 | ### Homebrew 33 | ``` 34 | brew install acquia/tools/club 35 | ``` 36 | 37 | ### Manual phar install 38 | 39 | ``` 40 | curl -OL http://github.com/acquia/club/releases/download/0.4/club.phar 41 | chmod u+x club.phar 42 | mv club.phar /usr/local/bin/club 43 | ``` 44 | 45 | ### Manual git checkout 46 | 47 | ``` 48 | git clone https://github.com/acquia/club.git 49 | cd club 50 | composer install 51 | ./vendor/bin/box build 52 | chmod u+x club.phar 53 | mv club.phar /usr/local/bin/club 54 | ``` 55 | 56 | ## Usage 57 | For the following commands to work, you will need access to your Acquia Cloud API keys. 58 | 59 | - `club ac-aliases` will generate all of your Acquia Cloud site subscription aliases. If you have Acquia Cloud SIte Factory, it will also generate all of your aliases for all of your sites on your factory. 60 | - `club create-project` will ask various questions, ensure that certain settings are made, build a new BLT project, build a local VM with your new site and push to Acquia cloud if you want. 61 | - `club pull-project` will pull an existing Acquia Cloud cloud to your local, build it in a vm, and sync files and dabatases if needed. 62 | 63 | ## FAQ 64 | 65 | #### What is the difference between Club and BLT? 66 | 67 | Club is a standalone executable tool that is used to create or clone existing BLT-based projects. Exactly one version of Club is installed per machine. It is not intended to be a dependency of a Drupal application, and it should never be committed to a codebase. 68 | 69 | BLT is a project-specific tool (not standalone). It is intended to be a dependency of a Drupal application. You may have multiple projects, each using a different version of BLT, on one machine. 70 | 71 | | Characteristic | BLT | Club | 72 | |----------------------------------------|-----|------| 73 | | Standalone, installed to local machine | | x | 74 | | Works outside of project context | | x | 75 | | Multple versions per machine | x | | 76 | | Committed to project codebase | x | | 77 | | Managed via Composer | x | | 78 | | Managed via Homebrew | | x | 79 | 80 | #### Why aren't Club and BLT the same tool? 81 | 82 | It's not feasible to combine Club and BLT at this time. Club creates projects. BLT is one part of the created project. 83 | 84 | You can execute a Club command outside the context of a Drupal application directory. Conversely, BLT requires a Drupal application directory. 85 | 86 | Some tools (e.g., Drush) have worked around similar issues by allowing you to have a "global" version of Drush on your machine in addition to a project-specific version. The global version defers to the project-specific version by way of a separate "launcher" layer. 87 | 88 | This is helpful, but often leads to confusion. It's possible, but unlikely, that we'll refactor BLT to behave in this way at some point in the future. 89 | 90 | ## Contributing to Club 91 | 92 | Please see [CONTRIBUTING.md](CONTRIBUTING.md) 93 | -------------------------------------------------------------------------------- /tests/phpunit/CreateProjectCommandTest.php: -------------------------------------------------------------------------------- 1 | fs = new Filesystem(); 25 | $this->fs->remove($test_dir); 26 | } 27 | } 28 | 29 | public function testCreateProjectRecipe() { 30 | $this->application->add(new CreateProjectCommand($this->local_environment_facade)); 31 | 32 | $command = $this->application->find('create-project'); 33 | $commandTester = new CommandTester($command); 34 | $commandTester->setInputs([ 35 | // Create new project now? 36 | 'yes', 37 | // Do you want to push this to an Acquia Cloud subscription? 38 | 'no', 39 | ]); 40 | $commandTester->execute(array( 41 | 'command' => $command->getName(), 42 | '--recipe' => 'tests/recipes/good.yml' 43 | )); 44 | 45 | $status_code = $commandTester->getStatusCode(); 46 | $this->assertEquals($status_code, 0, "The command create-project exited with a non-zero code: " . $commandTester->getDisplay()); 47 | $output = $commandTester->getDisplay(); 48 | $this->assertProjectFileExists('acquia-pipelines.yml'); 49 | $this->assertProjectFileExists('composer.json'); 50 | $this->assertProjectFileExists('composer.lock'); 51 | $this->assertProjectFileExists('blt/project.yml'); 52 | $this->assertProjectFileExists('blt/.schema_version'); 53 | $this->assertProjectFileExists('docroot/modules/contrib/acquia_blog'); 54 | $this->assertProjectFileNotExists('box/config.yml'); 55 | $this->assertProjectFileNotExists('VagrantFile'); 56 | $this->assertContains('Your project was created in', $output); 57 | } 58 | 59 | /** 60 | * Tests the 'create-project' command. 61 | */ 62 | public function testCreateProject() 63 | { 64 | $this->application->add(new CreateProjectCommand($this->local_environment_facade)); 65 | 66 | $command = $this->application->find('create-project'); 67 | $commandTester = new CommandTester($command); 68 | $commandTester->setInputs([ 69 | // Project title (human readable): 70 | 'Test Project', 71 | // Project machine name: 72 | $this->machine_name, 73 | // Project prefix: 74 | 'TP', 75 | // Do you want to create a VM? 76 | 'no', 77 | // Do you want to use Continuous Integration? 78 | 'yes', 79 | // Choose a Continuous Integration provider: 80 | 'pipelines', 81 | // Do you want to add default ingredients? 82 | 'yes', 83 | // Choose an ingredient: (acquia_blog) 84 | '1', 85 | // Choose an ingredient: (done) 86 | '0', 87 | // Create new project now? 88 | 'yes', 89 | // Do you want to push this to an Acquia Cloud subscription? 90 | 'no' 91 | ]); 92 | 93 | $commandTester->execute(array( 94 | 'command' => $command->getName(), 95 | )); 96 | 97 | $status_code = $commandTester->getStatusCode(); 98 | $this->assertEquals($status_code, 0, "The command create-project exited with a non-zero code: " . $commandTester->getDisplay()); 99 | $output = $commandTester->getDisplay(); 100 | $this->assertProjectFileExists('acquia-pipelines.yml'); 101 | $this->assertProjectFileExists('composer.json'); 102 | $this->assertProjectFileExists('composer.lock'); 103 | $this->assertProjectFileExists('blt/project.yml'); 104 | $this->assertProjectFileExists('blt/.schema_version'); 105 | $this->assertProjectFileExists('docroot/modules/contrib/acquia_blog'); 106 | $this->assertProjectFileNotExists('box/config.yml'); 107 | $this->assertProjectFileNotExists('VagrantFile'); 108 | $this->assertContains('Your project was created in', $output); 109 | } 110 | 111 | /** 112 | * @param $filename 113 | * @param string $message 114 | */ 115 | public function assertProjectFileExists($filename, $message = '') { 116 | $this->assertFileExists($this->machine_name . '/' . $filename, $message); 117 | } 118 | 119 | /** 120 | * @param $filename 121 | * @param string $message 122 | */ 123 | public function assertProjectFileNotExists($filename, $message = '') { 124 | $this->assertFileNotExists($this->machine_name . '/' . $filename, $message); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/Command/PullProjectCommand.php: -------------------------------------------------------------------------------- 1 | setName('pull-project') 22 | ->setDescription('Pulls an existing project from Acquia Cloud.') 23 | ->setHelp("This command allows you to pull projects...") 24 | ; 25 | } 26 | 27 | /** 28 | * Initializes the command just after the input has been validated. 29 | * 30 | * This is mainly useful when a lot of commands extends one main command 31 | * where some things need to be initialized based on the input arguments and options. 32 | * 33 | * @param InputInterface $input An InputInterface instance 34 | * @param OutputInterface $output An OutputInterface instance 35 | */ 36 | protected function initialize(InputInterface $input, OutputInterface $output) 37 | { 38 | parent::initialize($input, $output); 39 | $this->cloudApiConfig = $this->loadCloudApiConfig(); 40 | $this->setCloudApiClient($this->cloudApiConfig['email'], $this->cloudApiConfig['key']); 41 | } 42 | 43 | protected function execute(InputInterface $input, OutputInterface $output) 44 | { 45 | 46 | $this->checkXdebug(); 47 | 48 | $cloud_api_client = $this->getCloudApiClient(); 49 | $answers['ac']['site'] = $this->askWhichCloudSite($cloud_api_client); 50 | $this->checkDestinationDir($answers['ac']['site']); 51 | $site = $this->getSiteByLabel($cloud_api_client, $answers['ac']['site']); 52 | $answers['ac']['env'] = $this->askWhichCloudEnvironment($cloud_api_client, $site); 53 | 54 | // @todo Determine which branch is on the env and pull that branch. 55 | 56 | $dir_name = $answers['ac']['site']; 57 | $this->executeCommands([ 58 | "git clone {$site->vcsUrl()} $dir_name", 59 | ]); 60 | 61 | if (file_exists($dir_name . '/composer.lock')) { 62 | $composer_lock = json_decode(file_get_contents($dir_name . '/composer.lock'), true); 63 | $this->verifyBltVersion($composer_lock); 64 | } else { 65 | $this->output->writeln("No composer.lock file was found in the repository. Is this BLT project?"); 66 | return 1; 67 | } 68 | 69 | $this->output->writeln( 70 | "Great. Now let's make some choices about how your project will be set up locally." 71 | ); 72 | $question = new ConfirmationQuestion('Do you want to create a VM? ', true); 73 | $answers['vm'] = $this->questionHelper->ask($input, $output, $question); 74 | 75 | if ($answers['vm']) { 76 | $question = new ConfirmationQuestion( 77 | 'Do you want to download a database from Acquia Cloud? ', 78 | true 79 | ); 80 | $answers['download_db'] = $this->questionHelper->ask($input, $output, $question); 81 | 82 | // @todo Change to a choice btw download and stage file proxy. 83 | $question = new ConfirmationQuestion( 84 | 'Do you want to download the public and private file directories from Acquia Cloud? ', 85 | true 86 | ); 87 | $answers['download_files'] = $this->questionHelper->ask($input, $output, $question); 88 | } 89 | 90 | $this->output->writeln( 91 | "Awesome. Let's pull down your project. This could take a while..." 92 | ); 93 | 94 | $this->executeCommands([ 95 | 'composer install', 96 | 'composer blt-alias', 97 | ], $dir_name); 98 | 99 | if ($answers['vm']) { 100 | $remote_alias = $answers['ac']['site'] . '.' . $answers['ac']['env']; 101 | $this->executeCommands([ 102 | "./vendor/bin/blt vm", 103 | ], $dir_name); 104 | 105 | if ($answers['download_db']) { 106 | $this->executeCommands([ 107 | "./vendor/bin/blt setup:build", 108 | "./vendor/bin/blt local:sync -Ddrush.aliases.remote=$remote_alias", 109 | ], $dir_name); 110 | } else { 111 | $this->executeCommands([ 112 | "./vendor/bin/blt local:setup", 113 | ], $dir_name); 114 | } 115 | 116 | if ($answers['download_files']) { 117 | $this->executeCommands([ 118 | "drush rsync @$remote_alias:%files @self:%files" 119 | ], $dir_name . '/docroot'); 120 | } 121 | 122 | // @todo Derive the local alias from project.local.yml's drush.aliases.local. 123 | $local_alias = "@{$answers['machine_name']}.local"; 124 | $this->executeCommands([ 125 | "./vendor/bin/drush $local_alias uli", 126 | ], $dir_name); 127 | } 128 | 129 | $this->output->writeln("Your project was cloned to $dir_name."); 130 | if ($answers['vm']) { 131 | $this->output->writeln("A virtual machine was created. You can login to your site by running:"); 132 | $this->output->writeln("drush @{$answers['machine_name']}.local"); 133 | } 134 | } 135 | 136 | protected function verifyBltVersion($composer_lock) 137 | { 138 | foreach ($composer_lock['packages'] as $package) { 139 | if ($package['name'] == 'acquia/blt') { 140 | if ($package['version'] == '8.x-dev') { 141 | return true; 142 | } 143 | 144 | $semver = new version($package['version']); 145 | if (!$semver->satisfies(new expression(self::BLT_VERSION_CONSTRAINT))) { 146 | $constraint = self::BLT_VERSION_CONSTRAINT; 147 | $this->output->writeln( 148 | "This project's version of BLT does not satisfy the required version constraint of $constraint." 149 | ); 150 | return 1; 151 | } 152 | 153 | return true; 154 | } 155 | } 156 | 157 | $this->output->writeln("acquia/blt was not found in this project's composer.lock file."); 158 | return 1; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/Command/ACAliasesCommand.php: -------------------------------------------------------------------------------- 1 | setName('ac-aliases') 31 | ->setDescription('Updates your local drush aliases for Acquia Cloud subscriptions.') 32 | ->setHelp("This command will download ") 33 | ; 34 | } 35 | 36 | 37 | protected function execute(InputInterface $input, OutputInterface $output) 38 | { 39 | $question = new ConfirmationQuestion( 40 | 'This will overwrite existing drush aliases. Do you want to continue? ', 41 | false 42 | ); 43 | $continue = $this->questionHelper->ask($input, $output, $question); 44 | if (!$continue) { 45 | return 1; 46 | } 47 | 48 | $this->cloudApiConfig = $this->loadCloudApiConfig(); 49 | $this->setCloudApiClient($this->cloudApiConfig['email'], $this->cloudApiConfig['key']); 50 | 51 | $this->output->writeln("Gathering sites list from Acquia Cloud."); 52 | $sites = (array) $this->cloudApiClient->sites(); 53 | $sitesCount = count($sites); 54 | 55 | $this->progressBar = new ProgressBar($output, $sitesCount); 56 | 57 | $style = new OutputFormatterStyle('white', 'blue'); 58 | $output->getFormatter()->setStyle('status', $style); 59 | $this->progressBar->setFormat(" %current%/%max% subscriptions [%bar%] %percent:3s%% \n %message%"); 60 | $this->progressBar->setMessage('Starting Aliases sync...'); 61 | $this->output->writeln( 62 | "Found " . $sitesCount . " subscription(s). Gathering information about each.\n" 63 | ); 64 | $errors = []; 65 | $this->progressBar->setRedrawFrequency(0.1); 66 | foreach ($sites as $site) { 67 | $this->progressBar->setMessage('Syncing: ' . $site); 68 | try { 69 | $this->getSiteAliases($site, $errors); 70 | } catch (\Exception $e) { 71 | $errors[] = "Could not fetch alias data for $site. Error: ". $e->getMessage(); 72 | } 73 | $this->progressBar->advance(); 74 | } 75 | $this->progressBar->setMessage("Syncing: complete. \n"); 76 | $this->progressBar->clear(); 77 | $this->progressBar->finish(); 78 | 79 | if ($errors) { 80 | $formatter = $this->getHelper('formatter'); 81 | $formattedBlock = $formatter->formatBlock($errors, 'error'); 82 | $output->writeln($formattedBlock); 83 | } 84 | 85 | $this->output->writeln("Aliases were written to, type 'drush sa' to see them."); 86 | } 87 | 88 | /** 89 | * @param $site SiteNames[] 90 | */ 91 | protected function getSiteAliases($site, &$errors) 92 | { 93 | // Skip AC trex sites because the api breaks on them. 94 | $skip_site = false; 95 | if (strpos($site, 'trex') !== false 96 | || strpos($site, ':*') !== false) { 97 | $skip_site = true; 98 | } 99 | if (!$skip_site) { 100 | // gather our environments. 101 | $environments = $this->cloudApiClient->environments($site); 102 | // Lets split the site name in the format ac-realm:ac-site 103 | $site_split = explode(':', $site); 104 | $siteRealm = $site_split[0]; 105 | $siteID = $site_split[1]; 106 | 107 | // Loop over all environments. 108 | foreach ($environments as $env) { 109 | // Build our variables in case API changes. 110 | $envName = $env->name(); 111 | $uri = $env->defaultDomain(); 112 | $remoteHost = $env->sshHost(); 113 | $remoteUser = $env['unix_username']; 114 | $docroot = '/var/www/html/' . $siteID . '.' . $envName . '/docroot'; 115 | 116 | $aliases[$envName] = array( 117 | 'env-name' => $envName, 118 | 'root' => $docroot, 119 | 'ac-site' => $siteID, 120 | 'ac-env' => $envName, 121 | 'ac-realm' => $siteRealm, 122 | 'uri' => $uri, 123 | 'remote-host' => $remoteHost, 124 | 'remote-user' => $remoteUser, 125 | ); 126 | } 127 | if ($siteRealm == 'enterprise-g1') { 128 | $acsf_site_url = 'https://www.' . $siteID . '.acsitefactory.com'; 129 | if ($this->checkForACSFCredentials($siteID)) { 130 | // @TODO: Ask the user if they want to update the credentials 131 | $sites = $this->getACSFAliases($siteID, $acsf_site_url, $errors); 132 | if (!empty($sites)) { 133 | $prod_group = array(); 134 | $stage_group = array(); 135 | $dev_group = array(); 136 | foreach ($sites as $site) { 137 | // Configure prod aliases 138 | $site_alias = $site->site . '.prod'; 139 | $this->generateACSFAliases($aliases, $siteID, $site_alias, $site->domain, '.01live'); 140 | // Configure prod group 141 | $prod_group[] = '@' . $site_alias; 142 | // Configure stage aliases 143 | $site_alias = $site->site . '.stage'; 144 | $this->generateACSFAliases($aliases, $siteID, $site_alias, $site->domain, '.01test'); 145 | // Configure stage group 146 | $stage_group[] = '@' . $site_alias; 147 | // Configure dev aliases 148 | $site_alias = $site->site . '.dev'; 149 | $this->generateACSFAliases($aliases, $siteID, $site_alias, $site->domain, '.01dev'); 150 | // Configure dev group 151 | $dev_group[] = '@' . $site_alias; 152 | } 153 | 154 | $aliases['allprod'] = array( 155 | 'site' => $site->site, 156 | 'aliases' => $prod_group, 157 | 'env' => 'prod', 158 | 'group' => true 159 | ); 160 | 161 | $aliases['allstage'] = array( 162 | 'site' => $site->site, 163 | 'aliases' => $stage_group, 164 | 'env' => 'stage', 165 | 'group' => true 166 | ); 167 | $aliases['alldev'] = array( 168 | 'site' => $site->site, 169 | 'aliases' => $dev_group, 170 | 'env' => 'dev', 171 | 'group' => true 172 | ); 173 | } 174 | } else { 175 | $this->progressBar->clear(); 176 | $question = new ConfirmationQuestion( 177 | "Found an Acquia Cloud Site Factory instance named " . $siteID . ".\nTo setup aliases for this instance you will need an instance-specific API key found at " . $acsf_site_url . ". \nDo you want to download aliases for this instance? [y/n]: ", 178 | false 179 | ); 180 | $continue = $this->questionHelper->ask($this->input, $this->output, $question); 181 | if ($continue) { 182 | $this->askForACSFCredentials($siteID); 183 | $this->getACSFAliases($siteID, $acsf_site_url); 184 | } else { 185 | $config = $this->cloudApiConfig; 186 | $acsfConfig = array( 187 | "$siteID" => array( 188 | 'username' => '', 189 | 'apikey' => '', 190 | 'enabled' => false 191 | ) 192 | ); 193 | // @todo this fails when "n" is selected 194 | $config = array_merge_recursive($config, $acsfConfig); 195 | $this->writeCloudApiConfig($config); 196 | } 197 | } 198 | } 199 | $this->writeSiteAliases($siteID, $aliases); 200 | } 201 | } 202 | 203 | protected function generateACSFAliases(&$aliases, $siteID, $site_alias, $domain, $env) 204 | { 205 | $parent = '@' . $siteID . $env; 206 | switch ($env) { 207 | case '.01dev': 208 | $domain = str_replace($siteID, 'dev-' . $siteID, $domain); 209 | break; 210 | case '.01test': 211 | $domain = str_replace($siteID, 'test-' . $siteID, $domain); 212 | break; 213 | } 214 | $aliases[$site_alias]['uri'] = $domain; 215 | $aliases[$site_alias]['parent'] = $parent; 216 | $aliases[$site_alias]['site'] = $site_alias; 217 | $aliases[$site_alias]['env'] = $env; 218 | } 219 | protected function writeSiteAliases($site_id, $aliases) 220 | { 221 | // Load twig template 222 | $loader = new Twig_Loader_Filesystem(__DIR__ . '/../../Resources/templates'); 223 | $twig = new Twig_Environment($loader); 224 | // Render our aliases. 225 | $aliasesRender = $twig->render('aliases.php.twig', array('aliases' => $aliases)); 226 | $aliasesFileName = $this->drushAliasDir . '/' . $site_id . '.aliases.drushrc.php'; 227 | $writable = ( is_writable($aliasesFileName) ) ? true : chmod($aliasesFileName, 0755); 228 | // Write to file. 229 | file_put_contents($aliasesFileName, $aliasesRender); 230 | } 231 | 232 | protected function getACSFAliases($siteID, $acsf_site_url, &$errors) 233 | { 234 | 235 | $username = $this->cloudApiConfig[$siteID]['username']; 236 | $apikey = $this->cloudApiConfig[$siteID]['apikey']; 237 | $creds = base64_encode($username . ':' . $apikey); 238 | 239 | try { 240 | $sitesList = $this->curlCallToURL($acsf_site_url, $creds); 241 | $count = $sitesList['count']; 242 | if ($count > 100) { 243 | $numberOfPages = $count / 100; 244 | for ($i=2; $i <= ceil($numberOfPages); $i++) { 245 | $sitesList = array_merge_recursive($sitesList, $this->curlCallToURL($acsf_site_url, $creds, $i)); 246 | } 247 | } 248 | return $sitesList['sites']; 249 | } catch (\Exception $e) { 250 | $errors[] = "Failed to fetch " . $siteID . " aliases: " . $e->getMessage(); 251 | return false; 252 | } 253 | } 254 | 255 | 256 | 257 | protected function checkForACSFCredentials($siteId) 258 | { 259 | if (isset($this->cloudApiConfig[$siteId])) { 260 | return true; 261 | } else { 262 | return false; 263 | } 264 | } 265 | 266 | /** 267 | * 268 | */ 269 | protected function askForACSFCredentials($siteId) 270 | { 271 | $usernameQuestion = new Question("Please enter your ACSF username for $siteId: ", ''); 272 | $privateKeyQuestion = new Question("Please enter your ACSF API key for $siteId: ", ''); 273 | $privateKeyQuestion->setHidden(true); 274 | $username = $this->questionHelper->ask($this->input, $this->output, $usernameQuestion); 275 | $apikey = $this->questionHelper->ask($this->input, $this->output, $privateKeyQuestion); 276 | 277 | $config = $this->cloudApiConfig; 278 | $acsfConfig = array( 279 | "$siteId" => array( 280 | 'username' => $username, 281 | 'apikey' => $apikey, 282 | 'enabled' => true 283 | ) 284 | ); 285 | $this->cloudApiConfig = array_merge_recursive($config, $acsfConfig); 286 | $this->writeCloudApiConfig($this->cloudApiConfig); 287 | } 288 | 289 | 290 | protected function curlCallToURL($url, $creds, $page = 1, $limit = 100) 291 | { 292 | $full_url = $url . '/api/v1/sites?limit=' . $limit . '&page=' . $page; 293 | // Get cURL resource 294 | $ch = curl_init(); 295 | // Set url 296 | curl_setopt($ch, CURLOPT_URL, $full_url); 297 | // Set method 298 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); 299 | // Set options 300 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 301 | // Set headers 302 | curl_setopt($ch, CURLOPT_HTTPHEADER, [ 303 | "Authorization: Basic " . $creds, 304 | ]); 305 | // Send the request & save response to $resp 306 | $resp = curl_exec($ch); 307 | 308 | if (!$resp) { 309 | die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); 310 | } 311 | if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 403) { 312 | throw new \Exception('API Authorization failed.'); 313 | } 314 | // Close request to clear up some resources 315 | curl_close($ch); 316 | return (array)json_decode($resp); 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /src/Command/CommandBase.php: -------------------------------------------------------------------------------- 1 | localEnvironment = $localEnvironmentFacade; 83 | } 84 | 85 | /** 86 | * Initializes the command just after the input has been validated. 87 | * 88 | * This is mainly useful when a lot of commands extends one main command 89 | * where some things need to be initialized based on the input arguments and options. 90 | * 91 | * @param InputInterface $input An InputInterface instance 92 | * @param OutputInterface $output An OutputInterface instance 93 | */ 94 | protected function initialize(InputInterface $input, OutputInterface $output) 95 | { 96 | $this->input = $input; 97 | $this->output = $output; 98 | $this->questionHelper = $this->getHelper('question'); 99 | $this->formatter = $this->getHelper('formatter'); 100 | $this->fs = new Filesystem(); 101 | $this->cloudConfDir = $_SERVER['HOME'] . '/.acquia'; 102 | $this->drushAliasDir = $_SERVER['HOME'] . '/.drush'; 103 | $this->cloudConfFileName = 'cloudapi.conf'; 104 | $this->cloudConfFilePath = $this->cloudConfDir . '/' . $this->cloudConfFileName; 105 | } 106 | 107 | /** 108 | * Checks whether xDebug is enabled. If so, prompts user to continue. 109 | * 110 | * @return bool 111 | * Returns TRUE if user chose not to continue, FALSE if xDebug is not 112 | * enabled. 113 | */ 114 | public function checkXdebug() 115 | { 116 | // if ($this->localEnvironment->isPhpExtensionLoaded('xdebug') && !defined('PHPUNIT_CLUB')) { 117 | if (!$this->localEnvironment->isPhpExtensionLoaded('xdebug')) { 118 | return false; 119 | } 120 | 121 | $this->output->writeln( 122 | "You have xDebug enabled. This will make everything very slow. You should really disable it." 123 | ); 124 | 125 | if (!($this->askContinue())) { 126 | return 1; 127 | } 128 | } 129 | 130 | /** 131 | * @return bool 132 | */ 133 | protected function askContinue() 134 | { 135 | $question = new ConfirmationQuestion( 136 | 'Do you want to continue? ', 137 | true 138 | ); 139 | $continue = $this->questionHelper->ask( 140 | $this->input, 141 | $this->output, 142 | $question 143 | ); 144 | 145 | return $continue; 146 | } 147 | 148 | /** 149 | * @return int 150 | */ 151 | protected function checkCwd() 152 | { 153 | if ($this->fs->exists('.git')) { 154 | $errorMessages = [ 155 | "It looks like you're currently inside of a git repository.", 156 | "You can't create a new project inside of a repository.", 157 | 'Please change directories and try again.', 158 | ]; 159 | $formattedBlock = $this->formatter->formatBlock($errorMessages, 'error'); 160 | $this->output->writeln($formattedBlock); 161 | 162 | return 1; 163 | } 164 | } 165 | 166 | /** 167 | * @return array 168 | */ 169 | protected function loadCloudApiConfig() 170 | { 171 | if (!$config = $this->loadCloudApiConfigFile()) { 172 | $config = $this->askForCloudApiCredentials(); 173 | } 174 | 175 | return $config; 176 | } 177 | 178 | /** 179 | * @return array 180 | */ 181 | protected function loadCloudApiConfigFile() 182 | { 183 | $config_dirs = [ 184 | $_SERVER['HOME'] . $this->cloudConfDir, 185 | ]; 186 | $locator = new FileLocator($config_dirs); 187 | 188 | try { 189 | $file = $locator->locate($this->cloudConfFileName, null, true); 190 | $loaderResolver = new LoaderResolver(array(new JsonFileLoader($locator))); 191 | $delegatingLoader = new DelegatingLoader($loaderResolver); 192 | $config = $delegatingLoader->load($file); 193 | return $config; 194 | } catch (\Exception $e) { 195 | return []; 196 | } 197 | } 198 | 199 | /** 200 | * 201 | */ 202 | protected function askForCloudApiCredentials() 203 | { 204 | $usernameQuestion = new Question('Please enter your Acquia cloud email address: ', ''); 205 | $privateKeyQuestion = new Question('Please enter your Acquia cloud private key: ', ''); 206 | $privateKeyQuestion->setHidden(true); 207 | 208 | do { 209 | $email = $this->questionHelper->ask($this->input, $this->output, $usernameQuestion); 210 | $key = $this->questionHelper->ask($this->input, $this->output, $privateKeyQuestion); 211 | $this->setCloudApiClient($email, $key); 212 | $cloud_api_client = $this->getCloudApiClient(); 213 | } while (!$cloud_api_client); 214 | 215 | $config = array( 216 | 'email' => $email, 217 | 'key' => $key, 218 | ); 219 | 220 | $this->writeCloudApiConfig($config); 221 | } 222 | 223 | /** 224 | * @param $cloud_api_client 225 | * 226 | * @return string 227 | */ 228 | protected function askWhichCloudSite($cloud_api_client) 229 | { 230 | $question = new ChoiceQuestion( 231 | 'Which site?', 232 | $this->getSitesList($cloud_api_client) 233 | ); 234 | $site_name = $this->questionHelper->ask($this->input, $this->output, $question); 235 | 236 | return $site_name; 237 | } 238 | 239 | /** 240 | * @param CloudApiClient $cloud_api_client 241 | * @param Site $site 242 | */ 243 | protected function askWhichCloudEnvironment($cloud_api_client, $site) 244 | { 245 | $environments = $this->getEnvironmentsList($cloud_api_client, $site); 246 | $question = new ChoiceQuestion( 247 | 'Which environment?', 248 | (array) $environments 249 | ); 250 | $env = $this->questionHelper->ask($this->input, $this->output, $question); 251 | 252 | return $env; 253 | } 254 | 255 | /** 256 | * @param $config 257 | */ 258 | protected function writeCloudApiConfig($config) 259 | { 260 | file_put_contents($this->cloudConfFilePath, json_encode($config)); 261 | $this->output->writeln("Credentials were written to {$this->cloudConfFilePath}."); 262 | } 263 | 264 | /** 265 | * @return mixed 266 | */ 267 | protected function getCloudApiConfig() 268 | { 269 | return $this->cloudApiConfig; 270 | } 271 | 272 | protected function setCloudApiClient($username, $password) 273 | { 274 | try { 275 | $cloudapi = CloudApiClient::factory(array( 276 | 'username' => $username, 277 | 'password' => $password, 278 | )); 279 | 280 | // We must call some method on the client to test authentication. 281 | $cloudapi->sites(); 282 | 283 | $this->cloudApiClient = $cloudapi; 284 | 285 | return $cloudapi; 286 | } catch (\Exception $e) { 287 | // @todo this is being thrown after first auth. still works? check out. 288 | $this->output->writeln("Failed to authenticate with Acquia Cloud API."); 289 | if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { 290 | $this->output->writeln('Exception was thrown: ' . $e->getMessage()); 291 | } 292 | return null; 293 | } 294 | } 295 | 296 | /** 297 | * @param $username 298 | * @param $password 299 | * 300 | * @return \Acquia\Cloud\Api\CloudApiClient|null 301 | */ 302 | protected function getCloudApiClient() 303 | { 304 | return $this->cloudApiClient; 305 | } 306 | 307 | protected function checkDestinationDir($dir_name) 308 | { 309 | $destination_dir = getcwd() . '/' . $dir_name; 310 | if ($this->fs->exists($destination_dir)) { 311 | $this->output->writeln("Uh oh. The destination directory already exists."); 312 | $question = new ConfirmationQuestion("Delete $destination_dir? ", false); 313 | $delete_dir = $this->questionHelper->ask($this->input, $this->output, $question); 314 | if ($delete_dir) { 315 | if ($this->fs->exists($destination_dir . '/.vagrant')) { 316 | $this->output->writeln(''); 317 | $this->output->writeln("One more thing, it looks like there's a vagrant machine in the destination directory."); 318 | $question = new ConfirmationQuestion("Destroy the vagrant machine in $destination_dir? ", false); 319 | $vagrant_destroy = $this->questionHelper->ask($this->input, $this->output, $question); 320 | 321 | if ($vagrant_destroy) { 322 | $this->executeCommand('vagrant destroy --force', $destination_dir); 323 | } 324 | } 325 | 326 | // @todo recursively chmod all files in docroot/sites/default. 327 | $this->fs->chmod($destination_dir . '/docroot/sites/default/default.settings.php', 777); 328 | $this->fs->remove($destination_dir); 329 | } else { 330 | $this->output->writeln( 331 | "Please choose a different machine name for your project, or change directories." 332 | ); 333 | return 1; 334 | } 335 | } 336 | } 337 | 338 | /** 339 | * @param \Acquia\Cloud\Api\CloudApiClient $cloud_api_client 340 | * @param $site_id 341 | * 342 | * @return \Acquia\Cloud\Api\Response\Site 343 | */ 344 | protected function getSite(CloudApiClient $cloud_api_client, $site_id) 345 | { 346 | return $cloud_api_client->site($site_id); 347 | } 348 | 349 | /** 350 | * @param \Acquia\Cloud\Api\CloudApiClient $cloud_api_client 351 | * 352 | * @return array 353 | */ 354 | protected function getSites(CloudApiClient $cloud_api_client) 355 | { 356 | $sites = $cloud_api_client->sites(); 357 | $sites_filtered = []; 358 | 359 | foreach ($sites as $key => $site) { 360 | $label = $this->getSiteLabel($site); 361 | if ($label !== '*') { 362 | $sites_filtered[(string) $site] = $site; 363 | } 364 | } 365 | 366 | return $sites_filtered; 367 | } 368 | 369 | /** 370 | * @param $site 371 | * 372 | * @return mixed 373 | */ 374 | protected function getSiteLabel($site) 375 | { 376 | $site_slug = (string) $site; 377 | $site_split = explode(':', $site_slug); 378 | 379 | return $site_split[1]; 380 | } 381 | 382 | /** 383 | * @param \Acquia\Cloud\Api\CloudApiClient $cloud_api_client 384 | * 385 | * @return array 386 | */ 387 | protected function getSitesList(CloudApiClient $cloud_api_client) 388 | { 389 | $site_list = []; 390 | $sites = $this->getSites($cloud_api_client); 391 | foreach ($sites as $site) { 392 | $site_list[] = $this->getSiteLabel($site); 393 | } 394 | sort($site_list, SORT_NATURAL | SORT_FLAG_CASE); 395 | 396 | return $site_list; 397 | } 398 | 399 | /** 400 | * @param \Acquia\Cloud\Api\CloudApiClient $cloud_api_client 401 | * @param $label 402 | * 403 | * @return \Acquia\Cloud\Api\Response\Site|null 404 | */ 405 | protected function getSiteByLabel(CloudApiClient $cloud_api_client, $label) 406 | { 407 | $sites = $this->getSites($cloud_api_client); 408 | foreach ($sites as $site_id) { 409 | if ($this->getSiteLabel($site_id) == $label) { 410 | $site = $this->getSite($cloud_api_client, $site_id); 411 | return $site; 412 | } 413 | } 414 | 415 | return null; 416 | } 417 | 418 | /** 419 | * @param \Acquia\Cloud\Api\CloudApiClient $cloud_api_client 420 | * @param $site 421 | * 422 | * @return array 423 | */ 424 | protected function getEnvironmentsList(CloudApiClient $cloud_api_client, $site) 425 | { 426 | $environments = $cloud_api_client->environments($site); 427 | $environments_list = []; 428 | foreach ($environments as $environment) { 429 | $environments_list[] = $environment->name(); 430 | } 431 | 432 | return $environments_list; 433 | } 434 | 435 | /** 436 | * @param string $command 437 | * 438 | * @return bool 439 | */ 440 | protected function executeCommand($command, $cwd = null, $display_output = true, $mustRun = true) 441 | { 442 | $timeout = 10800; 443 | $env = [ 444 | 'COMPOSER_PROCESS_TIMEOUT' => $timeout 445 | ] + $_ENV; 446 | $process = new Process($command, $cwd, $env, null, $timeout); 447 | $process->setTty(true); 448 | $method = $mustRun ? 'mustRun' : 'run'; 449 | 450 | if ($display_output) { 451 | $process->$method(function ($type, $buffer) { 452 | print $buffer; 453 | }); 454 | return $process->isSuccessful(); 455 | } else { 456 | $process->$method(); 457 | return $process->getOutput(); 458 | } 459 | } 460 | /** 461 | * @param $command 462 | * 463 | * @return bool 464 | */ 465 | protected function executeCommands($commands = [], $cwd = null) 466 | { 467 | foreach ($commands as $command) { 468 | $this->executeCommand($command, $cwd); 469 | } 470 | } 471 | } 472 | -------------------------------------------------------------------------------- /src/Command/CreateProjectCommand.php: -------------------------------------------------------------------------------- 1 | setName('create-project') 37 | ->setDescription('Creates a new project.') 38 | ->setHelp("This command allows you to create projects...") 39 | ->addOption('recipe', 'r', InputOption::VALUE_OPTIONAL) 40 | ; 41 | } 42 | 43 | /** 44 | * @param \Symfony\Component\Console\Input\InputInterface $input 45 | * @param \Symfony\Component\Console\Output\OutputInterface $output 46 | * 47 | * @return bool 48 | */ 49 | protected function execute(InputInterface $input, OutputInterface $output) 50 | { 51 | $this->checkXdebug(); 52 | $this->checkCwd(); 53 | 54 | $recipe_filename = $input->getOption('recipe'); 55 | if ($recipe_filename) { 56 | $answers = $this->loadConfigFile($recipe_filename); 57 | $this->checkDestinationDir($answers['machine_name']); 58 | } else { 59 | $answers = $this->askForAnswers(); 60 | } 61 | 62 | $this->output->writeln("You have entered the following values:"); 63 | $this->printArrayAsTable($answers); 64 | $question = new ConfirmationQuestion('Create new project now? ', true); 65 | $create = $this->questionHelper->ask($input, $output, $question); 66 | 67 | if ($create) { 68 | $this->createProject($answers); 69 | } 70 | 71 | $cwd = getcwd() . '/' . $answers['machine_name']; 72 | if ($answers['vm']) { 73 | try { 74 | $this->createVm($answers); 75 | } catch (\Exception $e) { 76 | $this->output->writeln("Something went wrong with your VM initialization. Continuing setup..."); 77 | // @todo run "vagrant destroy." and remove local.project.yml. 78 | } 79 | } 80 | 81 | if (!empty($answers['ci']['provider'])) { 82 | $this->executeCommands([ 83 | "./vendor/bin/blt ci:{$answers['ci']['provider']}:init", 84 | ], $cwd); 85 | } 86 | 87 | $question = new ConfirmationQuestion('Do you want to push this to an Acquia Cloud subscription? [yes] ', true); 88 | $ac = $this->questionHelper->ask($this->input, $this->output, $question); 89 | if ($ac) { 90 | $this->cloudApiConfig = $this->loadCloudApiConfig(); 91 | $this->setCloudApiClient($this->cloudApiConfig['email'], $this->cloudApiConfig['key']); 92 | $cloud_api_client = $this->getCloudApiClient(); 93 | $answers['ac']['site'] = $this->askWhichCloudSite($cloud_api_client); 94 | $site = $this->getSiteByLabel($cloud_api_client, $answers['ac']['site']); 95 | $answers['ac']['env'] = $this->askWhichCloudEnvironment($cloud_api_client, $site); 96 | 97 | $this->executeCommands([ 98 | "git push {$site->vcsUrl()}", 99 | ], $cwd); 100 | 101 | if ($answers['ci']['provider'] == 'pipelines') { 102 | $question = new ConfirmationQuestion('Start a pipelines build now? [yes] ', true); 103 | $this->output->writeln("You must have pipelines already enabled."); 104 | $pipelines_start = $this->questionHelper->ask($this->input, $this->output, $question); 105 | if ($pipelines_start) { 106 | $this->executeCommands([ 107 | "pipelines start", 108 | ], $cwd); 109 | $this->output->writeln("Starting a pipelines build to generate a deployment artifact on cloud."); 110 | } 111 | } 112 | 113 | // @todo Deploy branch and install. 114 | // @todo drush uli remote. 115 | // $question = new ConfirmationQuestion("Do you want to install Drupal on Acquia Cloud's {$answers['env']}? [yes] ", true); 116 | // $answers['ac']['install'] = $this->questionHelper->ask($this->input, $this->output, $question); 117 | } 118 | 119 | $this->output->writeln("Your project was created in $cwd."); 120 | if ($answers['vm']) { 121 | $this->output->writeln("A virtual machine was created. You can login to your site by running:"); 122 | $this->output->writeln("drush @{$answers['machine_name']}.local"); 123 | } 124 | } 125 | 126 | /** 127 | * @param string $filename 128 | * 129 | * @return array 130 | */ 131 | protected function loadConfigFile($filename) 132 | { 133 | if (!file_exists($filename)) { 134 | throw new FileNotFoundException($filename); 135 | } 136 | 137 | $recipe = Yaml::parse( 138 | file_get_contents($filename) 139 | ); 140 | $configs = [ $recipe ]; 141 | $processor = new Processor(); 142 | $configuration_tree = new ProjectConfiguration(); 143 | $processed_configuration = $processor->processConfiguration( 144 | $configuration_tree, 145 | $configs 146 | ); 147 | 148 | return $processed_configuration; 149 | } 150 | 151 | /** 152 | * @return array 153 | */ 154 | protected function askForAnswers() 155 | { 156 | $this->output->writeln("Let's start by entering some information about your project."); 157 | 158 | $question = new Question('Project title (human readable): '); 159 | $this->requireQuestion($question); 160 | $answers['human_name'] = $this->questionHelper->ask($this->input, $this->output, $question); 161 | 162 | $default_machine_name = self::convertStringToMachineSafe($answers['human_name']); 163 | $question = new Question("Project machine name: [$default_machine_name] ", $default_machine_name); 164 | $answers['machine_name'] = $this->questionHelper->ask($this->input, $this->output, $question); 165 | 166 | $this->checkDestinationDir($answers['machine_name']); 167 | 168 | $default_prefix = self::convertStringToPrefix($answers['human_name']); 169 | $question = new Question("Project prefix: [$default_prefix]", $default_prefix); 170 | $answers['prefix'] = $this->questionHelper->ask($this->input, $this->output, $question); 171 | 172 | $this->output->writeln("Great. Now let's make some choices about how your project will be set up."); 173 | $question = new ConfirmationQuestion('Do you want to create a VM? [yes] ', true); 174 | $answers['vm'] = $this->questionHelper->ask($this->input, $this->output, $question); 175 | 176 | $question = new ConfirmationQuestion('Do you want to use Continuous Integration? [yes] ', true); 177 | $ci = $this->questionHelper->ask($this->input, $this->output, $question); 178 | if ($ci) { 179 | $provider_options = [ 180 | 'pipelines' => 'Acquia Pipelines', 181 | 'travis' => 'Travis CI', 182 | ]; 183 | $question = new ChoiceQuestion('Choose a Continuous Integration provider: [pipelines]', $provider_options, [1]); 184 | $answers['ci']['provider'] = $this->questionHelper->ask($this->input, $this->output, $question); 185 | } 186 | 187 | // $question = new ConfirmationQuestion('Do you want to create an Acquia Cloud free tier site for this project? ', false); 188 | // $create_acf_site = $helper->ask($input, $output, $question); 189 | 190 | $question = new ConfirmationQuestion('Do you want to add default ingredients? [yes] ', true); 191 | $ingredients = $this->questionHelper->ask($this->input, $this->output, $question); 192 | if ($ingredients || !empty($answers['ingredients'])) { 193 | $done_value = 'done'; 194 | $available_ingredients_config = Yaml::parse(file_get_contents(__DIR__ . '/../../Resources/available_ingredients.yml')); 195 | $available_ingredients = $available_ingredients_config['available_ingredients']; 196 | array_unshift($available_ingredients, $done_value); 197 | $i = 0; 198 | $answers['ingredients'] = []; 199 | do { 200 | $i++; 201 | $available_ingredients = array_diff($available_ingredients, $answers['ingredients']); 202 | $question = new ChoiceQuestion("Choose an ingredient: Choose [0] $done_value to finish.", $available_ingredients); 203 | $answers['ingredients'][$i] = $this->questionHelper->ask($this->input, $this->output, $question); 204 | $this->output->writeln("" . $answers['ingredients'][$i] . " added"); 205 | } while ($answers['ingredients'][$i] != $done_value); 206 | if (($key = array_search($done_value, $answers['ingredients'])) !== false) { 207 | unset($answers['ingredients'][$key]); 208 | } 209 | } 210 | 211 | return $answers; 212 | } 213 | 214 | /** 215 | * @param array $answers 216 | */ 217 | protected function createProject($answers) 218 | { 219 | $this->output->writeln("Awesome. Let's create your project. This could take a while..."); 220 | 221 | $this->executeCommands([ 222 | "composer create-project acquia/blt-project:~8 {$answers['machine_name']} --no-interaction", 223 | ]); 224 | 225 | $project_dir = getcwd() . '/' . $answers['machine_name']; 226 | 227 | $this->updateProjectYml($answers); 228 | 229 | if (!empty($answers['ingredients'])) { 230 | foreach ($answers['ingredients'] as $ingredient) { 231 | $this->executeCommand("composer require acquia-pso/$ingredient --no-update", $project_dir); 232 | } 233 | $this->executeCommand("composer update", $project_dir); 234 | } 235 | 236 | $lightning_extend_filename = $project_dir . '/docroot/sites/default/lightning.extend.yml'; 237 | $this->fs->copy($project_dir . '/docroot/profiles/contrib/lightning/lightning.extend.yml', $lightning_extend_filename); 238 | $lightning_extend = Yaml::parse(file_get_contents($lightning_extend_filename)); 239 | if (!empty($answers['ingredients'])) { 240 | $lightning_extend['modules'] = $answers['ingredients']; 241 | } 242 | 243 | file_put_contents($lightning_extend_filename, Yaml::dump($lightning_extend)); 244 | 245 | $this->output->writeln("Your project has been created locally."); 246 | } 247 | 248 | protected function updateProjectYml($answers) 249 | { 250 | $cwd = getcwd() . '/' . $answers['machine_name']; 251 | $config_file = $cwd . '/blt/project.yml'; 252 | $config = Yaml::parse(file_get_contents($config_file)); 253 | $config['project']['prefix'] = $answers['prefix']; 254 | $config['project']['machine_name'] = $answers['machine_name']; 255 | $config['project']['human_name'] = $answers['human_name']; 256 | // Hostname cannot contain underscores. 257 | $machine_name_safe = str_replace('_', '-', $answers['machine_name']); 258 | $config['project']['local']['hostname'] = str_replace('${project.machine_name}', $machine_name_safe, $config['project']['local']['hostname']); 259 | $this->fs->dumpFile($config_file, Yaml::dump($config)); 260 | } 261 | 262 | protected function createVm($answers) 263 | { 264 | $cwd = getcwd() . '/' . $answers['machine_name']; 265 | $this->executeCommands([ 266 | "./vendor/bin/blt vm", 267 | "./vendor/bin/blt local:setup", 268 | "./vendor/bin/drush @{$answers['machine_name']}.local uli", 269 | ], $cwd); 270 | } 271 | 272 | /** 273 | * @param $string 274 | * 275 | * @return mixed 276 | */ 277 | public static function convertStringToPrefix($string) 278 | { 279 | $words = explode(' ', $string); 280 | $prefix = ''; 281 | foreach ($words as $word) { 282 | $prefix .= substr($word, 0, 1); 283 | } 284 | 285 | return strtoupper($prefix); 286 | } 287 | 288 | /** 289 | * @param $identifier 290 | * @param array $filter 291 | * 292 | * @return mixed 293 | */ 294 | public static function convertStringToMachineSafe($identifier, array $filter = array( 295 | ' ' => '_', 296 | '-' => '_', 297 | '/' => '_', 298 | '[' => '_', 299 | ']' => '', 300 | )) 301 | { 302 | $identifier = str_replace(array_keys($filter), array_values($filter), $identifier); 303 | 304 | // Valid characters are: 305 | // - a-z (U+0030 - U+0039) 306 | // - A-Z (U+0041 - U+005A) 307 | // - the underscore (U+005F) 308 | // - 0-9 (U+0061 - U+007A) 309 | // - ISO 10646 characters U+00A1 and higher 310 | // We strip out any character not in the above list. 311 | $identifier = preg_replace('/[^\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier); 312 | // Identifiers cannot start with a digit, two hyphens, or a hyphen followed by a digit. 313 | $identifier = preg_replace(array( 314 | '/^[0-9]/', 315 | '/^(-[0-9])|^(--)/' 316 | ), array('_', '__'), $identifier); 317 | 318 | return strtolower($identifier); 319 | } 320 | 321 | /** 322 | * @param \Symfony\Component\Console\Question\Question $question 323 | */ 324 | protected function requireQuestion(Question $question) 325 | { 326 | $question->setValidator(function ($value) { 327 | if (trim($value) == '') { 328 | throw new \Exception('You must enter a value.'); 329 | } 330 | return $value; 331 | }); 332 | } 333 | 334 | /** 335 | * @param $array 336 | */ 337 | protected function printArrayAsTable($array) 338 | { 339 | $flattened_array = $this->flattenArray($array); 340 | $rowGenerator = function () use ($flattened_array) { 341 | $rows = []; 342 | foreach ($flattened_array as $key => $value) { 343 | if ($value == '1') { 344 | $value = 'yes'; 345 | } elseif ($value == '0') { 346 | $value = 'no'; 347 | } 348 | $rows[] = [$key, $value]; 349 | } 350 | return $rows; 351 | }; 352 | 353 | $table = new Table($this->output); 354 | $table->setHeaders(array('Property', 'Value')) 355 | ->setRows($rowGenerator()) 356 | ->render(); 357 | } 358 | 359 | /** 360 | * Flattens multi-dimensional array into two-dimensional array with dot-notated keys. 361 | * @param $array 362 | * 363 | * @return array 364 | */ 365 | protected function flattenArray($array) 366 | { 367 | $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array)); 368 | $result = []; 369 | foreach ($iterator as $leaf_value) { 370 | $keys = array(); 371 | foreach (range(0, $iterator->getDepth()) as $depth) { 372 | $keys[] = $iterator->getSubIterator($depth)->key(); 373 | } 374 | $result[ join('.', $keys) ] = $leaf_value; 375 | } 376 | 377 | return $result; 378 | } 379 | } 380 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------