/**
  * {@inheritdoc}
  */
 protected function fire()
 {
     $repo = $this->argument('repo');
     if (!preg_match('#^([\\d\\w_-]+)/([\\d\\w\\._-]+)$#', $repo)) {
         throw new Exception('Repository must be formatted: username/repo.');
     }
     $branch = $this->argument('branch') ?: 'master';
     $url = sprintf('https://github.com/%s/archive/%s.tar.gz', $repo, $branch);
     $this->comment('Downloading...');
     $downloader = new TempDownloader($url, '.tar.gz');
     $downloader->setOutput($this->output);
     try {
         $filePath = $downloader->download();
     } catch (Exception $e) {
         $this->error($e->getMessage());
         return;
     }
     $this->comment('Extracting...');
     $extractionPath = rtrim(sys_get_temp_dir(), '/') . '/craft_plugin_' . uniqid();
     if (!@mkdir($extractionPath)) {
         $this->error('Could not create directory in system temp directory.');
         return;
     }
     $tarExtractor = new TarExtractor($filePath, $extractionPath);
     $tarExtractor->extract();
     // determine the folder structure of the download in the temp path
     $pluginReader = new PluginReader($extractionPath);
     try {
         $pluginFile = $pluginReader->read();
     } catch (Exception $e) {
         $this->error($e->getMessage());
         return;
     }
     $folderName = strtolower($pluginFile->getBasename('Plugin.php'));
     // check if craft is already installed, and overwrite option
     if (file_exists($this->pluginsPath . $folderName) && !$this->option('overwrite')) {
         $this->error(sprintf('%s is already installed!', $folderName));
         if (!$this->confirm('Do you want to overwrite?')) {
             $this->info('Exited without installing.');
             return;
         }
     }
     // move the plugin from the temp folder to the craft installation
     CFileHelper::copyDirectory($pluginFile->getPath(), $this->pluginsPath . $folderName);
     // delete the temp files
     CFileHelper::removeDirectory($extractionPath);
     $this->info('Installation complete!');
 }
 /**
  * {@inheritdoc}
  */
 protected function fire()
 {
     $path = rtrim($this->argument('path'), DIRECTORY_SEPARATOR) ?: getcwd();
     if (!is_dir($path) && !@mkdir($path, 0777, true)) {
         $this->error(sprintf('Could not create directory %s.', $path));
         return;
     }
     // check terms and conditions
     if (!$this->option('terms') && !$this->confirm('I agree to the terms and conditions (https://buildwithcraft.com/license)')) {
         $this->error('You did not agree to the terms and conditions (https://buildwithcraft.com/license)');
         return;
     }
     // check if craft is already installed, and overwrite option
     if (file_exists($path . '/craft') && !$this->option('overwrite')) {
         $this->error('Craft is already installed here!');
         if (!$this->confirm('Do you want to overwrite?')) {
             $this->info('Exited without installing.');
             return;
         }
     }
     $url = 'https://buildwithcraft.com/latest.tar.gz?accept_license=yes';
     $this->comment('Downloading...');
     $downloader = new TempDownloader($url, '.tar.gz');
     $downloader->setOutput($this->output);
     try {
         $filePath = $downloader->download();
     } catch (Exception $e) {
         $this->error($e->getMessage());
         return;
     }
     $this->comment('Extracting...');
     $tarExtractor = new TarExtractor($filePath, $path);
     $tarExtractor->extract();
     // change the name of the public folder
     if ($public = $this->option('public')) {
         rename($path . '/public', $path . '/' . $public);
     }
     $this->info('Installation complete!');
 }