123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- function _print_drush_download_lib($library, $url) {
- $path = drush_get_option('path');
- if (empty($path)) {
- $path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries';
- }
-
- if (!is_dir($path)) {
- drush_op('mkdir', $path);
- drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
- }
-
- $olddir = getcwd();
- drush_op('chdir', $path);
-
- if (is_dir($library)) {
-
- drush_log(dt('An existing @library was overwritten at @path', array('@library' => $library, '@path' => $path . '/' . $library)), 'notice');
- }
-
- $filename = _print_drush_download_file($url);
- if ($filename) {
- $extract_ret = _print_drush_download_extract($filename);
- if ($extract_ret) {
-
- drush_op('unlink', $filename);
- drush_log(dt('@file has been downloaded and extracted in @path', array('@file' => $filename, '@path' => $path)), 'success');
- }
- else {
- drush_log(dt('@file has been downloaded to @path, but extract failed. Check that you have the necessary program installed, and if necessary extract it manually.',
- array('@file' => $filename, '@path' => $path)), 'warning');
- }
- }
- else {
- drush_log(dt('Drush was unable to download @library to @path', array('@library' => $library, '@path' => $path)), 'error');
- }
-
- drush_op('chdir', $olddir);
- }
- function _print_drush_download_file($download_url) {
- $wget_ret = drush_shell_exec("wget -nv --trust-server-names %s", $download_url);
- if (!drush_get_context('DRUSH_SIMULATE')) {
- if ($wget_ret) {
-
- $wget_out = explode('"', array_shift(drush_shell_exec_output()));
- $filename = $wget_out[1];
- }
- else {
- $tempnam = uniqid('print_drush_');
- $curl_ret = drush_shell_exec("curl -s -L -o %s %s -w '%%{url_effective}'", $tempnam, $download_url);
- if ($curl_ret) {
-
-
- $filename = explode('/', array_shift(drush_shell_exec_output()));
- $filename = array_pop($filename);
-
- if (!drush_op('rename', $tempnam, './' . $filename)) {
- $filename = $tempnam;
- }
- }
- else {
- $filename = FALSE;
- }
- }
- }
- else {
- $filename = basename($download_url);
- }
- return $filename;
- }
- function _print_drush_download_extract($filename) {
- $arch_ret = FALSE;
- if (drush_op('is_file', $filename)) {
- switch (drush_op('mime_content_type', $filename)) {
- case 1:
- $arch_ret = TRUE;
- break;
- case 'application/zip':
-
- $arch_ret = drush_shell_exec('unzip -qq -o %s', $filename);
-
- drush_log(dt('@filename is a Zip file. Check the access permissions of the extracted files.', array('@filename' => $filename)), 'warning');
- break;
- case 'application/x-gzip':
-
- $arch_ret = drush_shell_exec('tar xzf %s', $filename);
- break;
- case 'application/x-bzip2':
-
- $arch_ret = drush_shell_exec('tar xjf %s', $filename);
- break;
- case 'application/x-xz':
-
- $arch_ret = drush_shell_exec('tar xJf %s', $filename);
- break;
- }
- }
- else {
- drush_log(dt('@filename not found.', array('@filename' => $filename)), 'error');
- }
- return $arch_ret;
- }
|