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 * @author Mikael Nordfeldth <mmn@hethane.se>
25 * @license GNU Affero General Public License http://www.gnu.org/licenses/
27 * @link http://status.net
30 if (php_sapi_name() !== 'cli') {
34 define('INSTALLDIR', dirname(dirname(__FILE__)));
35 set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib');
37 require_once INSTALLDIR . '/lib/installer.php';
38 require_once 'Console/Getopt.php';
40 class CliInstaller extends Installer
42 public $verbose = true;
46 * @return boolean success
50 if (!$this->checkPrereqs()) {
53 if ($this->prepare()) {
54 return $this->handle();
62 * Get our input parameters...
63 * @return boolean success
67 $shortoptions = 'qvh';
68 $longoptions = array('quiet', 'verbose', 'help', 'skip-config');
71 '--server' => 'server',
74 '--sitename' => 'sitename',
78 '--dbtype' => 'dbtype',
80 '--database' => 'database',
81 '--username' => 'username',
82 '--password' => 'password',
84 '--admin-nick' => 'adminNick',
85 '--admin-pass' => 'adminPass',
86 '--admin-email' => 'adminEmail',
88 '--site-profile' => 'siteProfile'
90 foreach ($map as $arg => $target) {
91 if (substr($arg, 0, 2) == '--') {
92 $longoptions[] = substr($arg, 2) . '=';
94 $shortoptions .= substr($arg, 1) . ':';
98 $parser = new Console_Getopt();
99 $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
100 if (PEAR::isError($result)) {
101 $this->warning($result->getMessage());
104 list($options, $args) = $result;
107 $this->dbtype = 'mysql';
108 $this->verbose = true;
109 // ssl is defaulted in lib/installer.php
111 foreach ($options as $option) {
113 if (isset($map[$arg])) {
115 $this->$var = $option[1];
116 if ($arg == '--fancy') {
117 $this->$var = ($option[1] != 'false') && ($option[1] != 'no');
119 } else if ($arg == '--skip-config') {
120 $this->skipConfig = true;
121 } else if ($arg == 'q' || $arg == '--quiet') {
122 $this->verbose = false;
123 } else if ($arg == 'v' || $arg == '--verbose') {
124 $this->verbose = true;
125 } else if ($arg == 'h' || $arg == '--help') {
126 // will go back to show help
132 if (empty($this->server)) {
133 $this->updateStatus("You must specify a web server for the site.", true);
134 // path is optional though
138 if (!$this->validateDb()) {
142 if (!$this->validateAdmin()) {
151 return $this->doInstall();
157 install_cli.php - StatusNet command-line installer
159 -s --server=<name> Use <name> as server name (required)
160 -p --path=<path> Use <path> as path name
161 --sitename User-friendly site name (required)
162 --fancy Whether to use fancy URLs (default no)
163 --ssl Server SSL enabled (default never),
164 [never | sometimes | always]
166 --dbtype 'mysql' (default) or 'pgsql'
167 --host Database hostname (required)
168 --database Database/schema name (required)
169 --username Database username (required)
170 --password Database password (required)
172 --admin-nick Administrator nickname (required)
173 --admin-pass Initial password for admin user (required)
174 --admin-email Initial email address for admin user
175 --admin-updates 'yes' (default) or 'no', whether to subscribe
176 admin to update@status.net (default yes)
178 --site-profile site profile ['public', 'private' (default), 'community', 'singleuser']
180 --skip-config Don't write a config.php -- use with caution,
181 requires a global configuration file.
185 -q --quiet Quiet (little output)
186 -v --verbose Verbose (lots of output)
187 -h --help Show this message and quit.
192 function warning($message, $submessage='')
194 print $this->html2text($message) . "\n";
195 if ($submessage != '') {
196 print " " . $this->html2text($submessage) . "\n";
201 function updateStatus($status, $error=false)
203 if ($this->verbose || $error) {
207 print $this->html2text($status);
212 private function html2text($html)
214 // break out any links for text legibility
215 $breakout = preg_replace('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
218 return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
222 $installer = new CliInstaller();
223 $ok = $installer->main();