[INSTALL] Minor reformatting and modernization. Shouldn't change functionality significatively.

This commit is contained in:
Diogo Cordeiro
2019-07-15 01:40:31 +01:00
parent 7d262ad50b
commit 893bafa14b
3 changed files with 380 additions and 365 deletions

View File

@@ -1,37 +1,36 @@
#!/usr/bin/env php
<?php
// 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/>.
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
* CLI Installer
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Installation
* @package Installation
*
* @author Brion Vibber <brion@status.net>
* @author Mikael Nordfeldth <mmn@hethane.se>
* @license GNU Affero General Public License http://www.gnu.org/licenses/
* @version 1.1.x
* @link http://status.net
* @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
*/
if (php_sapi_name() !== 'cli') {
exit(1);
}
define('INSTALLDIR', dirname(dirname(__FILE__)));
define('INSTALLDIR', dirname(__DIR__));
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib');
require_once INSTALLDIR . '/lib/installer.php';
@@ -43,16 +42,16 @@ class CliInstaller extends Installer
/**
* Go for it!
* @return boolean success
* @return bool success
*/
function main()
public function main(): bool
{
if ($this->prepare()) {
if (!$this->checkPrereqs()) {
return false;
}
if (!$this->checkPrereqs()) {
return false;
}
return $this->handle();
} else {
} else {
$this->showHelp();
return false;
}
@@ -60,23 +59,23 @@ class CliInstaller extends Installer
/**
* Get our input parameters...
* @return boolean success
* @return bool success
*/
function prepare()
public function prepare(): bool
{
$shortoptions = 'qvh';
$longoptions = array('quiet', 'verbose', 'help', 'skip-config');
$map = array(
'-s' => 'server',
'--server' => 'server',
'-p' => 'path',
'--path' => 'path',
$longoptions = ['quiet', 'verbose', 'help', 'skip-config'];
$map = [
'-s' => 'server',
'--server' => 'server',
'-p' => 'path',
'--path' => 'path',
'--sitename' => 'sitename',
'--fancy' => 'fancy',
'--ssl' => 'ssl',
'--fancy' => 'fancy',
'--ssl' => 'ssl',
'--dbtype' => 'dbtype',
'--host' => 'host',
'--dbtype' => 'dbtype',
'--host' => 'host',
'--database' => 'database',
'--username' => 'username',
'--password' => 'password',
@@ -86,7 +85,7 @@ class CliInstaller extends Installer
'--admin-email' => 'adminEmail',
'--site-profile' => 'siteProfile'
);
];
foreach ($map as $arg => $target) {
if (substr($arg, 0, 2) == '--') {
$longoptions[] = substr($arg, 2) . '=';
@@ -116,13 +115,13 @@ class CliInstaller extends Installer
if ($arg == '--fancy') {
$this->$var = ($option[1] != 'false') && ($option[1] != 'no');
}
} else if ($arg == '--skip-config') {
} elseif ($arg == '--skip-config') {
$this->skipConfig = true;
} else if ($arg == 'q' || $arg == '--quiet') {
} elseif ($arg == 'q' || $arg == '--quiet') {
$this->verbose = false;
} else if ($arg == 'v' || $arg == '--verbose') {
} elseif ($arg == 'v' || $arg == '--verbose') {
$this->verbose = true;
} else if ($arg == 'h' || $arg == '--help') {
} elseif ($arg == 'h' || $arg == '--help') {
// will go back to show help
return false;
}
@@ -146,15 +145,15 @@ class CliInstaller extends Installer
return !$fail;
}
function handle()
public function handle()
{
return $this->doInstall();
}
function showHelp()
public function showHelp()
{
echo <<<END_HELP
install_cli.php - StatusNet command-line installer
install_cli.php - GNU social command-line installer
-s --server=<name> Use <name> as server name (required)
-p --path=<path> Use <path> as path name
@@ -189,7 +188,11 @@ install_cli.php - StatusNet command-line installer
END_HELP;
}
function warning($message, $submessage='')
/**
* @param string $message
* @param string $submessage
*/
public function warning(string $message, string $submessage = '')
{
print $this->html2text($message) . "\n";
if ($submessage != '') {
@@ -198,7 +201,11 @@ END_HELP;
print "\n";
}
function updateStatus($status, $error=false)
/**
* @param string $status
* @param bool $error
*/
public function updateStatus(string $status, bool $error = false)
{
if ($this->verbose || $error) {
if ($error) {
@@ -209,12 +216,18 @@ END_HELP;
}
}
private function html2text($html)
/**
* @param string $html
* @return string
*/
private function html2text(string $html): string
{
// break out any links for text legibility
$breakout = preg_replace('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
'\2 &lt;\1&gt;',
$html);
$breakout = preg_replace(
'/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
'\2 &lt;\1&gt;',
$html
);
return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
}
}