2010-04-08 01:47:08 +01:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
2019-07-15 01:40:31 +01:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2010-04-08 01:47:08 +01:00
|
|
|
/**
|
2019-07-15 01:40:31 +01:00
|
|
|
* CLI Installer
|
2010-04-08 01:47:08 +01:00
|
|
|
*
|
2019-07-15 01:40:31 +01:00
|
|
|
* @package Installation
|
|
|
|
* @author Brion Vibber <brion@pobox.com>
|
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2010-04-08 01:47:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (php_sapi_name() !== 'cli') {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
define('INSTALLDIR', dirname(__DIR__));
|
2010-04-08 01:47:08 +01:00
|
|
|
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib');
|
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/installer.php';
|
|
|
|
require_once 'Console/Getopt.php';
|
|
|
|
|
|
|
|
class CliInstaller extends Installer
|
|
|
|
{
|
|
|
|
public $verbose = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go for it!
|
2019-07-15 01:40:31 +01:00
|
|
|
* @return bool success
|
2010-04-08 01:47:08 +01:00
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function main(): bool
|
2010-04-08 01:47:08 +01:00
|
|
|
{
|
2017-11-26 21:14:30 +00:00
|
|
|
if ($this->prepare()) {
|
2019-07-15 01:40:31 +01:00
|
|
|
if (!$this->checkPrereqs()) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-08 01:47:08 +01:00
|
|
|
return $this->handle();
|
2019-07-15 01:40:31 +01:00
|
|
|
} else {
|
2010-04-08 01:47:08 +01:00
|
|
|
$this->showHelp();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get our input parameters...
|
2019-07-15 01:40:31 +01:00
|
|
|
* @return bool success
|
2010-04-08 01:47:08 +01:00
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function prepare(): bool
|
2010-04-08 01:47:08 +01:00
|
|
|
{
|
|
|
|
$shortoptions = 'qvh';
|
2019-07-15 01:40:31 +01:00
|
|
|
$longoptions = ['quiet', 'verbose', 'help', 'skip-config'];
|
|
|
|
$map = [
|
|
|
|
'-s' => 'server',
|
|
|
|
'--server' => 'server',
|
|
|
|
'-p' => 'path',
|
|
|
|
'--path' => 'path',
|
2010-04-08 01:47:08 +01:00
|
|
|
'--sitename' => 'sitename',
|
2019-07-15 01:40:31 +01:00
|
|
|
'--fancy' => 'fancy',
|
|
|
|
'--ssl' => 'ssl',
|
2010-04-08 01:47:08 +01:00
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
'--dbtype' => 'dbtype',
|
|
|
|
'--host' => 'host',
|
2010-04-08 01:47:08 +01:00
|
|
|
'--database' => 'database',
|
|
|
|
'--username' => 'username',
|
|
|
|
'--password' => 'password',
|
|
|
|
|
|
|
|
'--admin-nick' => 'adminNick',
|
|
|
|
'--admin-pass' => 'adminPass',
|
|
|
|
'--admin-email' => 'adminEmail',
|
2013-06-18 04:16:31 +01:00
|
|
|
|
|
|
|
'--site-profile' => 'siteProfile'
|
2019-07-15 01:40:31 +01:00
|
|
|
];
|
2010-04-08 01:47:08 +01:00
|
|
|
foreach ($map as $arg => $target) {
|
|
|
|
if (substr($arg, 0, 2) == '--') {
|
|
|
|
$longoptions[] = substr($arg, 2) . '=';
|
|
|
|
} else {
|
|
|
|
$shortoptions .= substr($arg, 1) . ':';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$parser = new Console_Getopt();
|
|
|
|
$result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
|
|
|
|
if (PEAR::isError($result)) {
|
|
|
|
$this->warning($result->getMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
list($options, $args) = $result;
|
|
|
|
|
|
|
|
// defaults
|
|
|
|
$this->dbtype = 'mysql';
|
|
|
|
$this->verbose = true;
|
2013-08-12 12:08:14 +01:00
|
|
|
// ssl is defaulted in lib/installer.php
|
2010-04-08 01:47:08 +01:00
|
|
|
|
|
|
|
foreach ($options as $option) {
|
|
|
|
$arg = $option[0];
|
|
|
|
if (isset($map[$arg])) {
|
|
|
|
$var = $map[$arg];
|
|
|
|
$this->$var = $option[1];
|
2014-05-19 13:53:11 +01:00
|
|
|
if ($arg == '--fancy') {
|
2010-04-08 01:47:08 +01:00
|
|
|
$this->$var = ($option[1] != 'false') && ($option[1] != 'no');
|
|
|
|
}
|
2019-07-15 01:40:31 +01:00
|
|
|
} elseif ($arg == '--skip-config') {
|
2010-04-08 01:47:08 +01:00
|
|
|
$this->skipConfig = true;
|
2019-07-15 01:40:31 +01:00
|
|
|
} elseif ($arg == 'q' || $arg == '--quiet') {
|
2010-04-08 01:47:08 +01:00
|
|
|
$this->verbose = false;
|
2019-07-15 01:40:31 +01:00
|
|
|
} elseif ($arg == 'v' || $arg == '--verbose') {
|
2010-04-08 01:47:08 +01:00
|
|
|
$this->verbose = true;
|
2019-07-15 01:40:31 +01:00
|
|
|
} elseif ($arg == 'h' || $arg == '--help') {
|
2010-04-08 01:47:08 +01:00
|
|
|
// will go back to show help
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$fail = false;
|
|
|
|
if (empty($this->server)) {
|
|
|
|
$this->updateStatus("You must specify a web server for the site.", true);
|
|
|
|
// path is optional though
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->validateDb()) {
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->validateAdmin()) {
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !$fail;
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
public function handle()
|
2010-04-08 01:47:08 +01:00
|
|
|
{
|
|
|
|
return $this->doInstall();
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
public function showHelp()
|
2010-04-08 01:47:08 +01:00
|
|
|
{
|
|
|
|
echo <<<END_HELP
|
2019-07-15 01:40:31 +01:00
|
|
|
install_cli.php - GNU social command-line installer
|
2010-04-08 01:47:08 +01:00
|
|
|
|
|
|
|
-s --server=<name> Use <name> as server name (required)
|
|
|
|
-p --path=<path> Use <path> as path name
|
|
|
|
--sitename User-friendly site name (required)
|
|
|
|
--fancy Whether to use fancy URLs (default no)
|
2013-08-12 12:08:14 +01:00
|
|
|
--ssl Server SSL enabled (default never),
|
2016-02-09 23:57:39 +00:00
|
|
|
[never | always]
|
2010-04-08 01:47:08 +01:00
|
|
|
|
|
|
|
--dbtype 'mysql' (default) or 'pgsql'
|
|
|
|
--host Database hostname (required)
|
|
|
|
--database Database/schema name (required)
|
|
|
|
--username Database username (required)
|
|
|
|
--password Database password (required)
|
|
|
|
|
|
|
|
--admin-nick Administrator nickname (required)
|
|
|
|
--admin-pass Initial password for admin user (required)
|
|
|
|
--admin-email Initial email address for admin user
|
|
|
|
--admin-updates 'yes' (default) or 'no', whether to subscribe
|
|
|
|
admin to update@status.net (default yes)
|
|
|
|
|
2013-06-18 04:16:31 +01:00
|
|
|
--site-profile site profile ['public', 'private' (default), 'community', 'singleuser']
|
|
|
|
|
2010-04-08 01:47:08 +01:00
|
|
|
--skip-config Don't write a config.php -- use with caution,
|
|
|
|
requires a global configuration file.
|
|
|
|
|
|
|
|
General options:
|
|
|
|
|
|
|
|
-q --quiet Quiet (little output)
|
|
|
|
-v --verbose Verbose (lots of output)
|
|
|
|
-h --help Show this message and quit.
|
|
|
|
|
|
|
|
END_HELP;
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
/**
|
|
|
|
* @param string $message
|
|
|
|
* @param string $submessage
|
|
|
|
*/
|
|
|
|
public function warning(string $message, string $submessage = '')
|
2010-04-08 01:47:08 +01:00
|
|
|
{
|
|
|
|
print $this->html2text($message) . "\n";
|
|
|
|
if ($submessage != '') {
|
|
|
|
print " " . $this->html2text($submessage) . "\n";
|
|
|
|
}
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
/**
|
|
|
|
* @param string $status
|
|
|
|
* @param bool $error
|
|
|
|
*/
|
|
|
|
public function updateStatus(string $status, bool $error = false)
|
2010-04-08 01:47:08 +01:00
|
|
|
{
|
|
|
|
if ($this->verbose || $error) {
|
|
|
|
if ($error) {
|
|
|
|
print "ERROR: ";
|
|
|
|
}
|
|
|
|
print $this->html2text($status);
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
/**
|
|
|
|
* @param string $html
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function html2text(string $html): string
|
2010-04-08 01:47:08 +01:00
|
|
|
{
|
|
|
|
// break out any links for text legibility
|
2019-07-15 01:40:31 +01:00
|
|
|
$breakout = preg_replace(
|
|
|
|
'/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
|
|
|
|
'\2 <\1>',
|
|
|
|
$html
|
|
|
|
);
|
2010-09-30 19:29:31 +01:00
|
|
|
return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
|
2010-04-08 01:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$installer = new CliInstaller();
|
|
|
|
$ok = $installer->main();
|
|
|
|
exit($ok ? 0 : 1);
|