File install-pear.php of Package php-pear
1
2
3
/* $Id: install-pear.php,v 1.5 2009/05/30 08:19:19 remi Exp $ */
4
5
error_reporting(1803);
6
7
if (ini_get('date.timezone') === '' && function_exists('date_default_timezone_set')) {
8
date_default_timezone_set('UTC');
9
}
10
11
$pear_dir = dirname(__FILE__);
12
ini_set('include_path', '');
13
if (function_exists('mb_internal_encoding')) {
14
mb_internal_encoding('ASCII');
15
}
16
set_time_limit(0);
17
include_once 'PEAR.php';
18
include_once 'PEAR/Installer.php';
19
include_once 'PEAR/Registry.php';
20
include_once 'PEAR/PackageFile.php';
21
include_once 'PEAR/Downloader/Package.php';
22
include_once 'PEAR/Frontend.php';
23
$a = true;
24
if (!PEAR::loadExtension('xml')) {
25
$a = false;
26
echo "[PEAR] xml extension is required\n";
27
}
28
if (!PEAR::loadExtension('pcre')) {
29
$a = false;
30
echo "[PEAR] pcre extension is required\n";
31
}
32
if (!$a) {
33
return -1;
34
}
35
36
$force = false;
37
$install_files = array();
38
array_shift($argv);
39
$debug = false;
40
for ($i = 0; $i < sizeof($argv); $i++) {
41
$arg = $argv[$i];
42
$bn = basename($arg);
43
if (ereg('package-(.*)\.xml$', $bn, $matches) ||
44
ereg('([A-Za-z0-9_:]+)-.*\.(tar|tgz)$', $bn, $matches)) {
45
$install_files[$matches[1]] = $arg;
46
} elseif ($arg == '-a') {
47
$cache_dir = $argv[$i+1];
48
$i++;
49
} elseif ($arg == '--force') {
50
$force = true;
51
} elseif ($arg == '-dp') {
52
$prefix = $argv[$i+1];
53
$i++;
54
} elseif ($arg == '-ds') {
55
$suffix = $argv[$i+1];
56
$i++;
57
} elseif ($arg == '-d') {
58
$with_dir = $argv[$i+1];
59
$i++;
60
} elseif ($arg == '-b') {
61
$bin_dir = $argv[$i+1];
62
$i++;
63
} elseif ($arg == '-c') {
64
$cfg_dir = $argv[$i+1];
65
$i++;
66
} elseif ($arg == '-w') {
67
$www_dir = $argv[$i+1];
68
$i++;
69
} elseif ($arg == '-p') {
70
$php_bin = $argv[$i+1];
71
$i++;
72
} elseif ($arg == '-o') {
73
$download_dir = $argv[$i+1];
74
$i++;
75
} elseif ($arg == '-t') {
76
$temp_dir = $argv[$i+1];
77
$i++;
78
} elseif ($arg == '--debug') {
79
$debug = 1;
80
} elseif ($arg == '--extremedebug') {
81
$debug = 2;
82
}
83
}
84
85
$config = PEAR_Config::singleton();
86
87
if (PEAR::isError($config)) {
88
$locs = PEAR_Config::getDefaultConfigFiles();
89
die("ERROR: One of $locs[user] or $locs[system] is corrupt, please remove them and try again");
90
}
91
92
// make sure we use only default values
93
$config_layers = $config->getLayers();
94
foreach ($config_layers as $layer) {
95
if ($layer == 'default') continue;
96
$config->removeLayer($layer);
97
}
98
$keys = $config->getKeys();
99
if ($debug) {
100
$config->set('verbose', 5, 'default');
101
} else {
102
$config->set('verbose', 0, 'default');
103
}
104
// PEAR executables
105
if (!empty($bin_dir)) {
106
$config->set('bin_dir', $bin_dir, 'default');
107
}
108
109
// Cache files
110
if (!empty($cache_dir)) {
111
$config->set('cache_dir', $cache_dir, 'default');
112
}
113
114
// Config files
115
if (!empty($cfg_dir)) {
116
$config->set('cfg_dir', $cfg_dir, 'default');
117
}
118
119
// Web files
120
if (!empty($www_dir)) {
121
$config->set('www_dir', $www_dir, 'default');
122
}
123
124
// Downloaded files
125
if (!empty($download_dir)) {
126
$config->set('download_dir', $download_dir, 'default');
127
}
128
129
// Temporary files
130
if (!empty($temp_dir)) {
131
$config->set('temp_dir', $temp_dir, 'default');
132
}
133
134
// User supplied a dir prefix
135
if (!empty($with_dir)) {
136
$ds = DIRECTORY_SEPARATOR;
137
$config->set('php_dir', $with_dir, 'default');
138
$config->set('doc_dir', $with_dir . $ds . 'doc', 'default');
139
$config->set('data_dir', $with_dir . $ds . 'data', 'default');
140
$config->set('test_dir', $with_dir . $ds . 'test', 'default');
141
if (empty($www_dir)) {
142
$config->set('www_dir', $with_dir . $ds . 'htdocs', 'default');
143
}
144
if (empty($cfg_dir)) {
145
$config->set('cfg_dir', $with_dir . $ds . 'cfg', 'default');
146
}
147
if (!is_writable($config->get('cache_dir'))) {
148
include_once 'System.php';
149
$cdir = System::mktemp(array('-d', 'pear'));
150
if (PEAR::isError($cdir)) {
151
$ui->outputData("[PEAR] cannot make new temporary directory: " . $cdir);
152
die(1);
153
}
154
$oldcachedir = $config->get('cache_dir');
155
$config->set('cache_dir', $cdir);
156
}
157
}
158
159
// PHP executable
160
if (!empty($php_bin)) {
161
$config->set('php_bin', $php_bin);
162
}
163
164
// PHP prefix
165
if (isset($prefix)) {
166
if ($prefix != 'a') {
167
if ($prefix[0] == 'a') {
168
$prefix = substr($prefix, 1);
169
}
170
$config->set('php_prefix', $prefix, 'system');
171
}
172
}
173
174
// PHP suffix
175
if (isset($suffix)) {
176
if ($suffix != 'a') {
177
if ($suffix[0] == 'a') {
178
$suffix = substr($suffix, 1);
179
}
180
$config->set('php_suffix', $suffix, 'system');
181
}
182
}
183
184
/* Print PEAR Conf (useful for debuging do NOT REMOVE) */
185
if ($debug) {
186
sort($keys);
187
foreach ($keys as $key) {
188
echo $key . ' ' .
189
$config->getPrompt($key) . ": " . $config->get($key, null, 'default') . "\n";
190
}
191
if ($debug == 2) { // extreme debugging
192
exit;
193
}
194
}
195
// end print
196
197
$php_dir = $config->get('php_dir');
198
$options = array();
199
$options['upgrade'] = true;
200
$install_root = getenv('INSTALL_ROOT');
201
if (!empty($install_root)) {
202
$options['packagingroot'] = $install_root;
203
$reg = &new PEAR_Registry($options['packagingroot']);
204
} else {
205
$reg = $config->getRegistry('default');
206
}
207
208
$ui = PEAR_Frontend::singleton('PEAR_Frontend_CLI');
209
if (PEAR::isError($ui)) {
210
die($ui->getMessage());
211
}
212
$installer = new PEAR_Installer($ui);
213
$pkg = new PEAR_PackageFile($config, $debug);
214
215
foreach ($install_files as $package => $instfile) {
216
$info = $pkg->fromAnyFile($instfile, PEAR_VALIDATE_INSTALLING);
217
if (PEAR::isError($info)) {
218
if (is_array($info->getUserInfo())) {
219
foreach ($info->getUserInfo() as $err) {
220
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err['message']));
221
}
222
}
223
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $info->getMessage()));
224
continue;
225
}
226
$new_ver = $info->getVersion();
227
$downloaderpackage = new PEAR_Downloader_Package($installer);
228
$err = $downloaderpackage->initialize($instfile);
229
if (PEAR::isError($err)) {
230
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
231
continue;
232
}
233
if ($reg->packageExists($package)) {
234
$old_ver = $reg->packageInfo($package, 'version');
235
if (version_compare($new_ver, $old_ver, 'gt')) {
236
$installer->setOptions($options);
237
$dp = array($downloaderpackage);
238
$installer->setDownloadedPackages($dp);
239
$err = $installer->install($downloaderpackage, $options);
240
if (PEAR::isError($err)) {
241
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
242
continue;
243
}
244
$ui->outputData(sprintf("[PEAR] %-15s- upgraded: %s", $package, $new_ver));
245
} else {
246
if ($force) {
247
$options['force'] = true;
248
$installer->setOptions($options);
249
$dp = array($downloaderpackage);
250
$installer->setDownloadedPackages($dp);
251
$err = $installer->install($downloaderpackage, $options);
252
if (PEAR::isError($err)) {
253
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
254
continue;
255
}
256
$ui->outputData(sprintf("[PEAR] %-15s- installed: %s", $package, $new_ver));
257
} else {
258
$ui->outputData(sprintf("[PEAR] %-15s- already installed: %s", $package, $old_ver));
259
}
260
}
261
} else {
262
$options['nodeps'] = true;
263
$installer->setOptions($options);
264
$dp = array($downloaderpackage);
265
$installer->setDownloadedPackages($dp);
266
$err = $installer->install($downloaderpackage, $options);
267
if (PEAR::isError($err)) {
268
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
269
continue;
270
}
271
$ui->outputData(sprintf("[PEAR] %-15s- installed: %s", $package, $new_ver));
272
}
273
if ($package == 'PEAR') {
274
if (is_file($ufile = $config->getConfFile('user'))) {
275
$ui->outputData('Warning! a PEAR user config file already exists from ' .
276
'a previous PEAR installation at ' .
277
"'$ufile'. You may probably want to remove it.");
278
}
279
$config->set('verbose', 1, 'default');
280
if (isset($oldcachedir)) {
281
$config->set('cache_dir', $oldcachedir);
282
}
283
$data = array();
284
foreach ($config->getKeys() as $key) {
285
$data[$key] = $config->get($key);
286
}
287
$cnf_file = $config->getConfFile('system');
288
if (!empty($install_root)) {
289
$cnf_file = $install_root . DIRECTORY_SEPARATOR . $cnf_file;
290
}
291
$config->writeConfigFile($cnf_file, 'system', $data);
292
$ui->outputData('Wrote PEAR system config file at: ' . $cnf_file);
293
$ui->outputData('You may want to add: ' . $config->get('php_dir') . ' to your php.ini include_path');
294
}
295
}
296
297