summaryrefslogtreecommitdiff
path: root/pear/scripts/pear.in
blob: 2cf5746969b8d98423217d449c8e4f6382332c95 (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
#!@prefix@/bin/php -Cq
<?php // -*- C++ -*-

require_once "PEAR.php";
require_once "PEAR/Installer.php";
require_once "PEAR/Packager.php";
require_once "Console/Getopt.php";

error_reporting(7);

$stderr = fopen("php://stderr", "w");

PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "usage");

$options = Console_Getopt::getopt($argv, "hv:?");
if (PEAR::isError($options)) {
    usage($options);
}

PEAR::setErrorHandling(PEAR_ERROR_PRINT);

$command = $options[1][1];
switch ($command) {
    case "install":
        $package = $options[1][2];
        $installer =& new PEAR_Installer();
        if (PEAR::isError($installer->Install($package))) {
            print "\ninstall failed\n";
        } else {
            print "install ok\n";
        }
        break;
    case "package":
        $pkginfofile = $options[1][2];
        $packager =& new PEAR_Packager();
        if (PEAR::isError($packager->Package($pkginfofile))) {
            print "\npackage failed\n";
        } else {
            print "package ok\n";
        }
        break;
    default:
        usage();
        break;
}

function usage($obj = null)
{
    global $stderr;
    if ($obj !== null) {
        fputs($stderr, $obj->getMessage());
    }
    fputs($stderr,
          "Usage: pear [-v n] [-h] command <parameters>\n".
          "Options:\n".
          "     -v   set verbosity level to <n> (0-2, default 1)\n".
          "     -h   display help/usage (this message)\n".
          "Commands:\n".
          "   install <package file>\n".
          "   package [package info file]\n".
          "\n");
    exit;
}

?>