4 * StatusNet - the distributed open-source microblogging tool
5 * Copyright (C) 2010, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @category Installation
21 * @package Installation
23 * @author Brion Vibber <brion@status.net>
24 * @license GNU Affero General Public License http://www.gnu.org/licenses/
26 * @link http://status.net
29 if (php_sapi_name() !== 'cli') {
33 define('INSTALLDIR', dirname(dirname(__FILE__)));
34 set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib');
36 require_once INSTALLDIR . '/lib/installer.php';
37 require_once 'Console/Getopt.php';
39 class CliInstaller extends Installer
41 public $verbose = true;
45 * @return boolean success
49 if (!$this->checkPrereqs()) {
52 if ($this->prepare()) {
53 return $this->handle();
61 * Get our input parameters...
62 * @return boolean success
66 $shortoptions = 'qvh';
67 $longoptions = array('quiet', 'verbose', 'help', 'skip-config');
70 '--server' => 'server',
73 '--sitename' => 'sitename',
76 '--dbtype' => 'dbtype',
78 '--database' => 'database',
79 '--username' => 'username',
80 '--password' => 'password',
82 '--admin-nick' => 'adminNick',
83 '--admin-pass' => 'adminPass',
84 '--admin-email' => 'adminEmail',
85 '--admin-updates' => 'adminUpdates'
87 foreach ($map as $arg => $target) {
88 if (substr($arg, 0, 2) == '--') {
89 $longoptions[] = substr($arg, 2) . '=';
91 $shortoptions .= substr($arg, 1) . ':';
95 $parser = new Console_Getopt();
96 $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
97 if (PEAR::isError($result)) {
98 $this->warning($result->getMessage());
101 list($options, $args) = $result;
104 $this->dbtype = 'mysql';
105 $this->adminUpdates = true;
106 $this->verbose = true;
108 foreach ($options as $option) {
110 if (isset($map[$arg])) {
112 $this->$var = $option[1];
113 if ($var == 'adminUpdates' || $arg == '--fancy') {
114 $this->$var = ($option[1] != 'false') && ($option[1] != 'no');
116 } else if ($arg == '--skip-config') {
117 $this->skipConfig = true;
118 } else if ($arg == 'q' || $arg == '--quiet') {
119 $this->verbose = false;
120 } else if ($arg == 'v' || $arg == '--verbose') {
121 $this->verbose = true;
122 } else if ($arg == 'h' || $arg == '--help') {
123 // will go back to show help
129 if (empty($this->server)) {
130 $this->updateStatus("You must specify a web server for the site.", true);
131 // path is optional though
135 if (!$this->validateDb()) {
139 if (!$this->validateAdmin()) {
148 return $this->doInstall();
154 install_cli.php - StatusNet command-line installer
156 -s --server=<name> Use <name> as server name (required)
157 -p --path=<path> Use <path> as path name
158 --sitename User-friendly site name (required)
159 --fancy Whether to use fancy URLs (default no)
161 --dbtype 'mysql' (default) or 'pgsql'
162 --host Database hostname (required)
163 --database Database/schema name (required)
164 --username Database username (required)
165 --password Database password (required)
167 --admin-nick Administrator nickname (required)
168 --admin-pass Initial password for admin user (required)
169 --admin-email Initial email address for admin user
170 --admin-updates 'yes' (default) or 'no', whether to subscribe
171 admin to update@status.net (default yes)
173 --skip-config Don't write a config.php -- use with caution,
174 requires a global configuration file.
178 -q --quiet Quiet (little output)
179 -v --verbose Verbose (lots of output)
180 -h --help Show this message and quit.
185 function warning($message, $submessage='')
187 print $this->html2text($message) . "\n";
188 if ($submessage != '') {
189 print " " . $this->html2text($submessage) . "\n";
194 function updateStatus($status, $error=false)
196 if ($this->verbose || $error) {
200 print $this->html2text($status);
205 private function html2text($html)
207 // break out any links for text legibility
208 $breakout = preg_replace('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
211 return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
215 $installer = new CliInstaller();
216 $ok = $installer->main();