Logoj0ke.net Open Build Service > Projects > home:jg:php5-extensions > php-pear > install-pear.php
Sign Up | Log In

File install-pear.php of Package php-pear

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