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',
87 '--admin-updates' => 'adminUpdates',
89 '--site-profile' => 'siteProfile'
91 foreach ($map as $arg => $target) {
92 if (substr($arg, 0, 2) == '--') {
93 $longoptions[] = substr($arg, 2) . '=';
95 $shortoptions .= substr($arg, 1) . ':';
99 $parser = new Console_Getopt();
100 $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
101 if (PEAR::isError($result)) {
102 $this->warning($result->getMessage());
105 list($options, $args) = $result;
108 $this->dbtype = 'mysql';
109 $this->adminUpdates = true;
110 $this->verbose = true;
111 // ssl is defaulted in lib/installer.php
113 foreach ($options as $option) {
115 if (isset($map[$arg])) {
117 $this->$var = $option[1];
118 if ($var == 'adminUpdates' || $arg == '--fancy') {
119 $this->$var = ($option[1] != 'false') && ($option[1] != 'no');
121 } else if ($arg == '--skip-config') {
122 $this->skipConfig = true;
123 } else if ($arg == 'q' || $arg == '--quiet') {
124 $this->verbose = false;
125 } else if ($arg == 'v' || $arg == '--verbose') {
126 $this->verbose = true;
127 } else if ($arg == 'h' || $arg == '--help') {
128 // will go back to show help
134 if (empty($this->server)) {
135 $this->updateStatus("You must specify a web server for the site.", true);
136 // path is optional though
140 if (!$this->validateDb()) {
144 if (!$this->validateAdmin()) {
153 return $this->doInstall();
159 install_cli.php - StatusNet command-line installer
161 -s --server=<name> Use <name> as server name (required)
162 -p --path=<path> Use <path> as path name
163 --sitename User-friendly site name (required)
164 --fancy Whether to use fancy URLs (default no)
165 --ssl Server SSL enabled (default never),
166 [never | sometimes | always]
168 --dbtype 'mysql' (default) or 'pgsql'
169 --host Database hostname (required)
170 --database Database/schema name (required)
171 --username Database username (required)
172 --password Database password (required)
174 --admin-nick Administrator nickname (required)
175 --admin-pass Initial password for admin user (required)
176 --admin-email Initial email address for admin user
177 --admin-updates 'yes' (default) or 'no', whether to subscribe
178 admin to update@status.net (default yes)
180 --site-profile site profile ['public', 'private' (default), 'community', 'singleuser']
182 --skip-config Don't write a config.php -- use with caution,
183 requires a global configuration file.
187 -q --quiet Quiet (little output)
188 -v --verbose Verbose (lots of output)
189 -h --help Show this message and quit.
194 function warning($message, $submessage='')
196 print $this->html2text($message) . "\n";
197 if ($submessage != '') {
198 print " " . $this->html2text($submessage) . "\n";
203 function updateStatus($status, $error=false)
205 if ($this->verbose || $error) {
209 print $this->html2text($status);
214 private function html2text($html)
216 // break out any links for text legibility
217 $breakout = preg_replace('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
220 return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
224 $installer = new CliInstaller();
225 $ok = $installer->main();