wget.inc

  1. 8.0.x commands/pm/package_handler/wget.inc
  2. 6.x commands/pm/package_handler/wget.inc
  3. 7.x commands/pm/package_handler/wget.inc
  4. 3.x commands/pm/package_handler/wget.inc
  5. 4.x commands/pm/package_handler/wget.inc
  6. 5.x commands/pm/package_handler/wget.inc
  7. master commands/pm/package_handler/wget.inc

Drush PM Wget extension

Functions

Namesort descending Description
package_handler_install_project Install a project.
package_handler_update_project This is an alias of the install function, since they are identical

File

commands/pm/package_handler/wget.inc
View source
  1. <?php
  2. /**
  3. * @file Drush PM Wget extension
  4. */
  5. /**
  6. * Install a project.
  7. *
  8. * @param $project The project array with name, base and full (final) paths.
  9. * @param $release The release details array from drupal.org
  10. */
  11. function package_handler_install_project(&$project, $release) {
  12. drush_log('Downloading project ' . $project['name'] . ' ...');
  13. // Get the filename...
  14. $filename = explode('/', $release['download_link']);
  15. $filename = array_pop($filename);
  16. // Set our directory to the download location.
  17. $olddir = getcwd();
  18. chdir($project['base_project_path']);
  19. // Download it.
  20. if (!drush_shell_exec("wget -P . " . $release['download_link'])) {
  21. drush_shell_exec("curl -O " . $release['download_link']);
  22. }
  23. if (file_exists($filename) || drush_get_context('DRUSH_SIMULATE')) {
  24. drush_log("Downloading " . $filename . " was successful.");
  25. }
  26. else {
  27. chdir($olddir);
  28. return drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', 'Unable to download ' . $filename . ' to ' . $project['base_project_path'] . ' from '. $release['download_link']);
  29. }
  30. // Check Md5 hash
  31. if (md5_file($filename) != $release['mdhash'] && !drush_get_context('DRUSH_SIMULATE')) {
  32. drush_op('unlink', $filename);
  33. chdir($olddir);
  34. return drush_set_error('DRUSH_PM_FILE_CORRUPT', "File $filename is corrupt (wrong md5 checksum).");
  35. }
  36. else {
  37. drush_log("Md5 checksum of $filename verified.");
  38. }
  39. // Decompress
  40. drush_shell_exec("gzip -d " . $filename);
  41. $tarpath = basename($filename, '.tar.gz');
  42. $tarpath = basename($tarpath, '.tgz');
  43. $tarpath .= '.tar';
  44. // Untar
  45. drush_shell_exec("tar -xf $tarpath");
  46. // We're not using tar -xzf because that's not working on windows...
  47. // Handle the dodgy directory used by the drupal project' packaging script.
  48. if ($project['name'] == 'drupal') {
  49. // The dodgy directory name is always the first line of output.
  50. drush_shell_exec("tar -tf $tarpath");
  51. $output = drush_shell_exec_output();
  52. $project_destination_name = $output[0];
  53. if ($rename = drush_get_option($project['name'] . '-project-rename')) {
  54. // If someone specifies --drupal-project-rename, but does not
  55. // provide a name, then default to 'drupal'.
  56. if ($rename === TRUE) {
  57. $rename = $project['name'];
  58. }
  59. $rename = trim($rename, '/');
  60. $renamed_destination = $project['base_project_path'] . (substr($project['base_project_path'], -1) != '/' ? '/' : '') . $rename;
  61. $rename_result = drush_op('rename', $project['base_project_path'] . $project_destination_name, $renamed_destination);
  62. if ($rename_result) {
  63. $project_destination_name = $rename;
  64. }
  65. }
  66. $project['full_project_path'] = $project['base_project_path'] . (substr($project['base_project_path'], -1) != '/' ? '/' : '') . $project_destination_name;
  67. }
  68. // Remove the tarball
  69. drush_op('unlink', $tarpath);
  70. // Set working directory back to the previous working directory.
  71. chdir($olddir);
  72. // 'drupal' project and profiles get untarred as drupal-6-10/foo instead of drupal/foo so must be excluded from test below.
  73. // Translations get untarred into the Drupal root, so there is no easy way to check.
  74. if (!is_dir($project['full_project_path']) && !drush_get_context('DRUSH_SIMULATE') && $project['name'] != 'drupal' && !in_array($release['type'], array('translation', 'profile'))) {
  75. return drush_set_error('DRUSH_PM_FILE_UNTAR_ERROR', 'Downloaded file ' . $filename . ' couldn\'t be untarred to ' . $project['full_project_path'] . ' correctly');
  76. }
  77. else {
  78. return TRUE;
  79. }
  80. }
  81. /**
  82. * This is an alias of the install function, since they are identical
  83. */
  84. function package_handler_update_project(&$project, $release) {
  85. return package_handler_install_project($project, $release);
  86. }