| 1 |
<?php
|
| 2 |
// $Id: pear.install,v 1.7 2008/05/05 20:56:38 mepcotterell Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* The Pear module installer.
|
| 7 |
*
|
| 8 |
* By default, the installer creates a PEAR environment in the
|
| 9 |
* "files/pear/" directory. This could be overridden if the
|
| 10 |
* installer was interactive. However, the Pear module will
|
| 11 |
* provide a wizard for migrating the environment to a different
|
| 12 |
* directory.
|
| 13 |
*
|
| 14 |
* @author Michael Cotterell <mepcotterell@gmail.com>
|
| 15 |
*
|
| 16 |
* @todo Look into the possibility of an interactive installer
|
| 17 |
* @todo add logging to the installer
|
| 18 |
* @todo add more error checking
|
| 19 |
*/
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Define the installer revision
|
| 23 |
*/
|
| 24 |
define('PEAR_INSTALLER_REVISION', '$Revision: 1.7 $');
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Install the Pear module
|
| 28 |
*/
|
| 29 |
function pear_install() {
|
| 30 |
|
| 31 |
pear_install_log(t('Beginning installation.'));
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Try to disable PHP's time limit
|
| 35 |
*
|
| 36 |
* If PHP is not in safe mode then disable its time limit.
|
| 37 |
*/
|
| 38 |
if (!((bool)ini_get('safe_mode'))) {
|
| 39 |
pear_install_log(t('Disabling the PHP time limit.'));
|
| 40 |
set_time_limit(0);
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* The type of interface between the web server and PHP
|
| 45 |
*
|
| 46 |
* @todo may not be needed. check to see if any of the downloading function behave differently under different interfaces.
|
| 47 |
*/
|
| 48 |
$sapi_name = php_sapi_name();
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Enable appropriate error reporting
|
| 52 |
*
|
| 53 |
* @todo make sure this doesn't conflict with drupal core
|
| 54 |
*/
|
| 55 |
error_reporting( E_ALL & ~E_NOTICE);
|
| 56 |
|
| 57 |
/**
|
| 58 |
* The path of the Pear module directory
|
| 59 |
*/
|
| 60 |
$pear_module_path = drupal_get_path('module', 'pear');
|
| 61 |
|
| 62 |
/**
|
| 63 |
* The path where the installer will store temporary files
|
| 64 |
*/
|
| 65 |
$installer_temp_path = file_directory_temp();
|
| 66 |
|
| 67 |
/**
|
| 68 |
* The path where the PEAR environment will be installed
|
| 69 |
*/
|
| 70 |
$installer_target_path = file_directory_path() . DIRECTORY_SEPARATOR . 'pear';
|
| 71 |
|
| 72 |
/**
|
| 73 |
* The path where the PEAR packages bundled with the installer will be placed
|
| 74 |
*/
|
| 75 |
$installer_bundle_path = $installer_target_path . DIRECTORY_SEPARATOR . 'installer-bundle';
|
| 76 |
|
| 77 |
/**
|
| 78 |
* The PEAR packages bundled with the installer
|
| 79 |
*
|
| 80 |
* We can't actually include them with the module because they're not licesnsed
|
| 81 |
* under the GPL, and that means they can be hosted on cvs.drupal.org. To get
|
| 82 |
* around this, the files are downloaded durring module installation.
|
| 83 |
*
|
| 84 |
* These files will not be part of the target PEAR installation. Instead, they
|
| 85 |
* are included so that the installer can extract the PEAR package tarball.
|
| 86 |
*
|
| 87 |
* @todo should we remove these files durring installation cleanup?
|
| 88 |
*/
|
| 89 |
$installer_bundle = array(
|
| 90 |
'PEAR.php' => 'http://cvs.php.net/viewcvs.cgi/pear-core/PEAR.php?view=co',
|
| 91 |
'Archive/Tar.php' => 'http://cvs.php.net/viewcvs.cgi/pear/Archive_Tar/Archive/Tar.php?view=co',
|
| 92 |
'Console/Getopt.php' => 'http://cvs.php.net/viewcvs.cgi/pear-core/Console/Getopt.php?view=co',
|
| 93 |
);
|
| 94 |
|
| 95 |
/**
|
| 96 |
* The PEAR packages to install into the target PEAR installation.
|
| 97 |
*
|
| 98 |
* There should only be one package, "PEAR", here. This is because all additional
|
| 99 |
* packages should be added using the Pear module.
|
| 100 |
*/
|
| 101 |
$installer_packages = array(
|
| 102 |
'PEAR' => 'stable', // release states: alpha, beta, stable
|
| 103 |
);
|
| 104 |
|
| 105 |
pear_install_log(t('Preparing to fetch the installer-bundle.'));
|
| 106 |
|
| 107 |
/**
|
| 108 |
* Download the installer bundle
|
| 109 |
*/
|
| 110 |
foreach ($installer_bundle as $package => $source) {
|
| 111 |
|
| 112 |
pear_install_log(t('Fetching @package...', array('@package'=>$package)));
|
| 113 |
|
| 114 |
$destination = $installer_bundle_path . DIRECTORY_SEPARATOR . $package;
|
| 115 |
|
| 116 |
pear_install_download($source, $destination);
|
| 117 |
|
| 118 |
if (!file_exists($destination)) {
|
| 119 |
die("Installation failed: $target not found");
|
| 120 |
}
|
| 121 |
|
| 122 |
}
|
| 123 |
|
| 124 |
pear_install_log(t('Successfuly fetched the installer-bundle.'));
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Let PHP know that it can include files from the bundle directory
|
| 128 |
*/
|
| 129 |
$include_path = array(
|
| 130 |
$installer_bundle_path,
|
| 131 |
get_include_path(),
|
| 132 |
);
|
| 133 |
|
| 134 |
set_include_path(implode(PATH_SEPARATOR, $include_path));
|
| 135 |
|
| 136 |
/**
|
| 137 |
* Include the PEAR tarball class
|
| 138 |
*/
|
| 139 |
include_once 'Archive/Tar.php';
|
| 140 |
|
| 141 |
pear_install_log(t('Preparing to fetch the installer packages.'));
|
| 142 |
|
| 143 |
/**
|
| 144 |
* Download and extract the installer packages
|
| 145 |
*/
|
| 146 |
foreach ($installer_packages as $package => $release) {
|
| 147 |
|
| 148 |
pear_install_log(t('Fetching @package...', array('@package'=>$package)));
|
| 149 |
|
| 150 |
$package_name = str_replace('/', '_', $package);
|
| 151 |
|
| 152 |
/**
|
| 153 |
* Fetch version information
|
| 154 |
*/
|
| 155 |
|
| 156 |
$source = 'http://pear.php.net/rest/r/' . strtolower($package_name) . '/' . $release . '.txt';
|
| 157 |
$destination = $installer_temp_path . DIRECTORY_SEPARATOR . $package_name . '.txt';
|
| 158 |
|
| 159 |
pear_install_download($source, $destination);
|
| 160 |
|
| 161 |
$version = trim(file_get_contents($destination));
|
| 162 |
|
| 163 |
pear_install_log(t('Deleting @file...', array('@file'=>$destintion)));
|
| 164 |
|
| 165 |
unlink($destination);
|
| 166 |
|
| 167 |
$tar_remove_path = $package_name . '-' . $version;
|
| 168 |
|
| 169 |
/**
|
| 170 |
* Fetch the tarball
|
| 171 |
*/
|
| 172 |
|
| 173 |
$source = 'http://pear.php.net/get/' . $package_name . '/' . $release;
|
| 174 |
|
| 175 |
$destination = $installer_temp_path . DIRECTORY_SEPARATOR . $package_name . '.tgz';
|
| 176 |
|
| 177 |
pear_install_download($source, $destination);
|
| 178 |
|
| 179 |
$tar = new Archive_Tar($destination);
|
| 180 |
|
| 181 |
pear_install_log(t('Extracting @tar...', array('@tar'=>$destination)));
|
| 182 |
|
| 183 |
$tar->extractModify($installer_target_path, $tar_remove_path);
|
| 184 |
|
| 185 |
pear_install_log(t('Deleting @file...', array('@file'=>$destintion)));
|
| 186 |
|
| 187 |
unlink($destination);
|
| 188 |
|
| 189 |
}
|
| 190 |
|
| 191 |
variable_set('pear_pear_path', $installer_target_path);
|
| 192 |
|
| 193 |
pear_install_log(t('Successfuly fetched the installer packages.'));
|
| 194 |
|
| 195 |
pear_install_log(t('Installation complete!'));
|
| 196 |
|
| 197 |
}
|
| 198 |
|
| 199 |
function pear_uninstall() {
|
| 200 |
|
| 201 |
}
|
| 202 |
|
| 203 |
/**
|
| 204 |
* Download a file
|
| 205 |
*
|
| 206 |
* @param string $url
|
| 207 |
* @param string $destination
|
| 208 |
*/
|
| 209 |
function pear_install_download($url, $destination) {
|
| 210 |
|
| 211 |
$log_vars = array(
|
| 212 |
'@url' => $url,
|
| 213 |
'@dest' => $destination,
|
| 214 |
'@dir' => dirname($destination),
|
| 215 |
);
|
| 216 |
|
| 217 |
pear_install_log(t('Preparing to download @url', $log_vars));
|
| 218 |
|
| 219 |
/**
|
| 220 |
* Make sure the destination directory exits
|
| 221 |
*/
|
| 222 |
pear_install_log(t('Preparing directory: @dir', $log_vars));
|
| 223 |
$directory = dirname($destination);
|
| 224 |
@mkdir($directory, 0777, TRUE);
|
| 225 |
|
| 226 |
/**
|
| 227 |
* Download the file using copy()
|
| 228 |
*/
|
| 229 |
pear_install_log(t('Downloading @url to @dest', $log_vars));
|
| 230 |
copy($url, $destination);
|
| 231 |
|
| 232 |
pear_install_log(t('Download of @url completed!', $log_vars));
|
| 233 |
|
| 234 |
}
|
| 235 |
|
| 236 |
/**
|
| 237 |
* Log a message to watchdog
|
| 238 |
*
|
| 239 |
* @param string $message
|
| 240 |
* @param watchdog_mask $error_mask
|
| 241 |
*/
|
| 242 |
function pear_install_log($message, $error_mask = FALSE) {
|
| 243 |
|
| 244 |
$messages = array(
|
| 245 |
$message,
|
| 246 |
t('(pear.install @revision)', array('@revision' => PEAR_INSTALLER_REVISION)),
|
| 247 |
);
|
| 248 |
|
| 249 |
$output = implode(' ', $messages);
|
| 250 |
|
| 251 |
watchdog('pear.install', $output, NULL, ($error_mask) ? WATCHDOG_DEBUG : $error_mask);
|
| 252 |
|
| 253 |
}
|