summaryrefslogtreecommitdiff
path: root/pear/scripts/pearwin.php
blob: 7bbfe4c7a97a9ec82fd98df527392baa37698b24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 5                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.php.net/license/3_0.txt.                                  |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Stig Bakken <ssb@php.net>                                   |
// |          Tomas V.V.Cox <cox@idecnet.com>                             |
// +----------------------------------------------------------------------+
//
// $Id$

require_once 'PEAR.php';
require_once 'PEAR/Common.php';
require_once 'PEAR/Config.php';
require_once 'PEAR/Remote.php';
require_once 'PEAR/Registry.php';
require_once 'Console/Getopt.php';

error_reporting(E_ALL ^ E_NOTICE);

$progname = basename($argv[0]);

PEAR::setErrorHandling(PEAR_ERROR_PRINT, "$progname: %s\n");

$argv = Console_Getopt::readPHPArgv();
if (PEAR::isError($argv)) {
    die($argv->getMessage());
}
$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqu:v");
if (PEAR::isError($options)) {
    usage($options);
}


$php_sysconfdir = getenv('PHP_SYSCONFDIR');
if (!empty($php_sysconfdir)) {
    $pear_default_config = $php_sysconfdir.DIRECTORY_SEPARATOR.'pearsys.ini';
    $pear_user_config    = $php_sysconfdir.DIRECTORY_SEPARATOR.'pear.ini';
} else {
    $pear_default_config = PHP_SYSCONFDIR.DIRECTORY_SEPARATOR.'pearsys.ini';
    $pear_user_config    = PHP_SYSCONFDIR.DIRECTORY_SEPARATOR.'pear.ini';
}

$opts = $options[0];

//echo "ini_get : ".ini_get("pear_install_dir")."\n";
//echo "get_cfg_var : ".get_cfg_var("pear_install_dir")."\n";

foreach ($opts as $opt) {
    switch ($opt[0]) {
        case 'c':
            $pear_user_config = $opt[1];
            break;
        case 'C':
            $pear_default_config = $opt[1];
            break;
    }
}

$config = new PEAR_Config($pear_user_config, $pear_default_config);
$store_user_config = false;
$store_default_config = false;
$verbose = 1;

foreach ($opts as $opt) {
    $param = $opt[1];
    switch ($opt[0]) {
        case 'd':
            list($key, $value) = explode('=', $param);
            $config->set($key, $value);
            break;
        case 'D':
            list($key, $value) = explode('=', $param);
            $config->set($key, $value, true);
            break;
        case 's':
            $store_user_config = true;
            break;
        case 'S':
            $store_default_config = true;
            break;
        case 'u':
            $config->toDefault($param);
            break;
        case 'v':
            $verbose++;
            break;
        case 'q':
            $verbose--;
            break;
    }
}

if ($store_default_config) {
    if (@is_writeable($pear_default_config)) {
        $config->writeConfigFile($pear_default_config, 'default');
    } else {
        die("You don't have write access to $pear_default_config, exiting!\n");
    }
}

if ($store_user_config) {
    $config->writeConfigFile($pear_user_config, 'userdefined');
}

$fallback_config = array(
    'master_server' => 'pear.php.net',
    'php_dir'       => getenv('PEAR_INSTALL_DIR'),
    'ext_dir'       => getenv('PEAR_EXTENSION_DIR'),
    'doc_dir'       => getenv('PHP_DATADIR') . DIRECTORY_SEPARATOR . 'pear' .
                       DIRECTORY_SEPARATOR . 'doc',
    'verbose'       => true,
);
$fallback_done = array();

foreach ($fallback_config as $key => $value) {
    if (!$config->isDefined($key)) {
        $config->set($key, $value);
        $fallback_done[$key] = true;
    }
}

//$verbose    = $config->get("verbose");
$script_dir = $config->get("php_dir");
$ext_dir    = $config->get("ext_dir");
$doc_dir    = $config->get("doc_dir");

PEAR::setErrorHandling(PEAR_ERROR_PRINT);

$command = (isset($options[1][1])) ? $options[1][1] : null;
$rest = array_slice($options[1], 2);

if (isset($command_options[$command])) {
    $tmp = Console_Getopt::getopt($rest, $command_options[$command]);
    if (PEAR::isError($tmp)) {
        usage($tmp);
    }
    $cmdopts = $tmp[0];
    $cmdargs = $tmp[1];
} else {
    $cmdopts = array();
    $cmdargs = $rest;
}


/* Extracted from pearcmd-common.php */
function heading($text)
{
    $l = strlen(trim($text));
    print rtrim($text) . "\n" . str_repeat("=", $l) . "\n";
}

switch ($command) {
    case 'install':
        include 'pearcmd-install.php';
        break;
    case 'uninstall':
        include 'pearcmd-uninstall.php';
        break;
    case 'list':
        include 'pearcmd-list.php';
        break;
    case 'package':
        include 'pearcmd-package.php';
        break;
    case 'remote-list':
        include 'pearcmd-remote-list.php';
        break;
    case 'show-config':
        $keys = $config->getKeys();
        foreach ($keys as $key) {
            $value = $config->get($key);
            $xi = "";
            if ($config->isDefaulted($key)) {
                $xi .= " (default)";
            }
            if (isset($fallback_done[$key])) {
                $xi .= " (built-in)";
            }
            printf("%s = %s%s\n", $key, $value, $xi);
        }
        break;
    default: {
        if (!$store_default_config && !$store_user_config) {
            usage();
        }
        break;
    }
}

function usage($obj = null)
{
    $stderr = fopen('php://stderr', 'w');
    if ($obj !== null) {
        fputs($stderr, $obj->getMessage());
    }
    fputs($stderr,
          "Usage: pear [options] command [command-options] <parameters>\n".
          "Options:\n".
          "     -v             increase verbosity level (default 1)\n".
          "     -q             be quiet, decrease verbosity level\n".
          "     -c file        find user configuration in `file'\n".
          "     -C file        find system configuration in `file'\n".
          "     -d \"foo=bar\" set user config variable `foo' to `bar'\n".
          "     -D \"foo=bar\" set system config variable `foo' to `bar'\n".
          "     -s             store user configuration\n".
          "     -S             store system configuration\n".
          "     -u foo         unset `foo' in the user configuration\n".
          "     -h, -?         display help/usage (this message)\n".
          "Commands:\n".
          "   help [command]\n".
          "   install [-r] <package file>\n".
          "   uninstall [-r] <package name>\n".
          "   package [package info file]\n".
          "   list\n".
          "   remote-list\n".
          "   show-config\n".
          "\n");
    fclose($stderr);
    exit;
}

?>