3 * StatusNet - a distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Abort if called from a web server
24 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
25 print "This script must be run from the command line\n";
29 define('STATUSNET', true);
30 define('LACONICA', true); // compatibility
32 // Set various flags so we don't time out on long-running processes
34 ini_set("max_execution_time", "0");
35 ini_set("max_input_time", "0");
37 mb_internal_encoding('UTF-8');
39 // Add extlib to our path so we can get Console_Getopt
41 $_extra_path = array(INSTALLDIR.'/extlib/');
43 set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path());
45 require_once 'Console/Getopt.php';
47 // Note: $shortoptions and $longoptions should be pre-defined!
49 $_default_shortoptions = 'qvhc:s:p:';
51 $_default_longoptions = array('quiet', 'verbose', 'help', 'conf=', 'server=', 'path=');
53 if (isset($shortoptions)) {
54 $shortoptions .= $_default_shortoptions;
56 $shortoptions = $_default_shortoptions;
59 if (isset($longoptions)) {
60 $longoptions = array_merge($longoptions, $_default_longoptions);
62 $longoptions = $_default_longoptions;
65 $parser = new Console_Getopt();
67 $result = $parser->getopt($argv, $shortoptions, $longoptions);
69 if (PEAR::isError($result)) {
70 print $result->getMessage()."\n";
73 list($options, $args) = $result;
80 $_default_help_text = <<<END_OF_DEFAULT
83 -q --quiet Quiet (little output)
84 -v --verbose Verbose (lots of output)
85 -c --conf=<filename> Use <filename> as config file
86 -s --server=<name> Use <name> as server name
87 -p --path=<path> Use <path> as path name
88 -h --help Show this message and quit.
91 if (isset($helptext)) {
94 print $_default_help_text;
98 foreach ($options as $option) {
100 switch ($option[0]) {
103 $server = $option[1];
113 $conffile = $option[1];
122 require_once INSTALLDIR . '/lib/common.php';
124 set_error_handler('common_error_handler');
126 function _make_matches($opt, $alt)
130 if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
131 $matches[] = '--'.$opt;
137 if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
138 $matches[] = '--'.$alt;
147 function have_option($opt, $alt=null)
151 $matches = _make_matches($opt, $alt);
153 foreach ($options as $option) {
154 if (in_array($option[0], $matches)) {
162 function get_option_value($opt, $alt=null)
166 $matches = _make_matches($opt, $alt);
168 foreach ($options as $option) {
169 if (in_array($option[0], $matches)) {