]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/install_cli.php
Make attachment fit better in notice: drop text and link
[quix0rs-gnu-social.git] / scripts / install_cli.php
index 3e18f28f3ea1ef3cbaad1b910f1360b7d9747c74..e4f8f600b1681a6136c469d55e4ae376c8103440 100755 (executable)
@@ -1,36 +1,37 @@
 #!/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.
- *
- * 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
+ * CLI Installer
  *
- * @author   Brion Vibber <brion@status.net>
- * @license  GNU Affero General Public License http://www.gnu.org/licenses/
- * @version  0.9.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__));
+define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
 set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib');
 
 require_once INSTALLDIR . '/lib/installer.php';
@@ -42,16 +43,16 @@ class CliInstaller extends Installer
 
     /**
      * Go for it!
-     * @return boolean success
+     * @return bool success
      */
-    function main()
+    public function main(): bool
     {
-        if (!$this->checkPrereqs()) {
-            return false;
-        }
         if ($this->prepare()) {
+            if (!$this->checkPrereqs()) {
+                return false;
+            }
             return $this->handle();
-       } else {
+        } else {
             $this->showHelp();
             return false;
         }
@@ -59,22 +60,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',
+            '--fancy' => 'fancy',
+            '--ssl' => 'ssl',
 
-            '--dbtype'   => 'dbtype',
-            '--host'     => 'host',
+            '--dbtype' => 'dbtype',
+            '--host' => 'host',
             '--database' => 'database',
             '--username' => 'username',
             '--password' => 'password',
@@ -82,10 +84,9 @@ class CliInstaller extends Installer
             '--admin-nick' => 'adminNick',
             '--admin-pass' => 'adminPass',
             '--admin-email' => 'adminEmail',
-            '--admin-updates' => 'adminUpdates',
 
             '--site-profile' => 'siteProfile'
-        );
+        ];
         foreach ($map as $arg => $target) {
             if (substr($arg, 0, 2) == '--') {
                 $longoptions[] = substr($arg, 2) . '=';
@@ -104,24 +105,24 @@ class CliInstaller extends Installer
 
         // defaults
         $this->dbtype = 'mysql';
-        $this->adminUpdates = true;
         $this->verbose = true;
+        // ssl is defaulted in lib/installer.php
 
         foreach ($options as $option) {
             $arg = $option[0];
             if (isset($map[$arg])) {
                 $var = $map[$arg];
                 $this->$var = $option[1];
-                if ($var == 'adminUpdates' || $arg == '--fancy') {
+                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;
             }
@@ -145,20 +146,22 @@ 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
        --sitename        User-friendly site name (required)
        --fancy           Whether to use fancy URLs (default no)
+       --ssl             Server SSL enabled (default never), 
+                         [never | always]
 
        --dbtype          'mysql' (default) or 'pgsql'
        --host            Database hostname (required)
@@ -186,7 +189,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 != '') {
@@ -195,7 +202,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) {
@@ -206,12 +217,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');
     }
 }