From 03748ddd6464bdc636ee8ff404d4f6f5380f5df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Mon, 16 Apr 2018 10:57:27 +0200 Subject: [PATCH 1/9] [FEATURE] Install Script: Add first version --- auto_install.php | 164 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 auto_install.php diff --git a/auto_install.php b/auto_install.php new file mode 100644 index 0000000000..ef30d1912a --- /dev/null +++ b/auto_install.php @@ -0,0 +1,164 @@ +config['php_path'])) { + check_php($app->config['php_path'], $checks); + } else { + die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); + } + + echo " NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"; + + return $checks; +} + +function run_database_check() +{ + global $db_host; + global $db_user; + global $db_pass; + global $db_data; + + $result = array( + 'title' => 'MySQL Connection', + 'required' => true, + 'status' => true, + 'help' => '', + ); + + if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) { + $result['status'] = false; + $result['help'] = 'Failed, please check your MySQL settings and credentials.'; + } + + return $result; +} From 791071a1c640d04d79c2770d3f7f730a3048df96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Mon, 16 Apr 2018 14:56:02 +0200 Subject: [PATCH 2/9] [CLEANUP] Code: Remove function --- auto_install.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/auto_install.php b/auto_install.php index ef30d1912a..bc418d6889 100644 --- a/auto_install.php +++ b/auto_install.php @@ -13,7 +13,9 @@ if (file_exists('.htconfig.php') && filesize('.htconfig.php')) { } // Remove die from config file -copy_config_file(); +$fileContent = file_get_contents('./htconfig.php'); +$fileContent = str_replace('die', '//die', $fileContent); +file_put_contents('.htautoinstall.php', $fileContent); require_once 'boot.php'; require_once 'mod/install.php'; @@ -109,13 +111,6 @@ echo " Complete!\n\n"; echo "\nInstallation is finished\n"; -function copy_config_file() -{ - $fileContent = file_get_contents('./htconfig.php'); - $fileContent = str_replace('die', '//die', $fileContent); - file_put_contents('.htautoinstall.php', $fileContent); -} - /** * @param App $app * @return array From 96d8591b95e10fda6dee639d222c3368ec9a0e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 11:40:16 +0200 Subject: [PATCH 3/9] [TASK] Remove auto_install.php --- auto_install.php | 159 ----------------------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 auto_install.php diff --git a/auto_install.php b/auto_install.php deleted file mode 100644 index bc418d6889..0000000000 --- a/auto_install.php +++ /dev/null @@ -1,159 +0,0 @@ -config['php_path'])) { - check_php($app->config['php_path'], $checks); - } else { - die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); - } - - echo " NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"; - - return $checks; -} - -function run_database_check() -{ - global $db_host; - global $db_user; - global $db_pass; - global $db_data; - - $result = array( - 'title' => 'MySQL Connection', - 'required' => true, - 'status' => true, - 'help' => '', - ); - - if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) { - $result['status'] = false; - $result['help'] = 'Failed, please check your MySQL settings and credentials.'; - } - - return $result; -} From 1d552b5e66b3ece7e539432d0d2c462708b86c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 11:43:23 +0200 Subject: [PATCH 4/9] [TASK] Install script: Add installation class --- src/Core/Console/AutomaticInstallation.php | 181 +++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/Core/Console/AutomaticInstallation.php diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php new file mode 100644 index 0000000000..a847b4a1bc --- /dev/null +++ b/src/Core/Console/AutomaticInstallation.php @@ -0,0 +1,181 @@ +output("Initializing setup...\n"); + + $a = get_app(); + $db_host = ''; + $db_user = ''; + $db_pass = ''; + $db_data = ''; + require_once '.htautoinstall.php'; + + $this->output(" Complete!\n\n"); + + // Check basic setup + $this->output("Checking basic setup...\n"); + + $checkResults = []; + $checkResults['basic'] = $this->runBasicChecks($a); + $errorMessage = $this->extractErrors($checkResults['basic']); + + if ($errorMessage !== '') { + die($errorMessage); + } + + $this->output(" Complete!\n\n"); + + // Check database connection + $this->output("Checking database...\n"); + + $checkResults['db'] = array(); + $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data); + $errorMessage = $this->extractErrors($checkResults['db']); + + if ($errorMessage !== '') { + die($errorMessage); + } + + $this->output(" Complete!\n\n"); + + // Install database + $this->output("Inserting data into database...\n"); + + $checkResults['data'] = load_database(); + + if ($checkResults['data'] !== '') { + die("ERROR: DB Database creation error. Is the DB empty?\n"); + } + + $this->output(" Complete!\n\n"); + + // Copy config file + $this->output("Saving config file...\n"); + if (!copy('.htautoinstall.php', '.htconfig.php')) { + die("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n"); + } + $this->output(" Complete!\n\n"); + $this->output("\nInstallation is finished\n"); + + return 0; + } + + /** + * @param App $app + * @return array + */ + public function runBasicChecks($app) + { + $checks = []; + + check_funcs($checks); + check_imagik($checks); + check_htconfig($checks); + check_smarty3($checks); + check_keys($checks); + + if (!empty($app->config['php_path'])) { + check_php($app->config['php_path'], $checks); + } else { + die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); + } + + $this->output(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); + + return $checks; + } + + /** + * @param $db_host + * @param $db_user + * @param $db_pass + * @param $db_data + * @return array + */ + public function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data) + { + $result = array( + 'title' => 'MySQL Connection', + 'required' => true, + 'status' => true, + 'help' => '', + ); + + + if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) { + $result['status'] = false; + $result['help'] = 'Failed, please check your MySQL settings and credentials.'; + } + + return $result; + } + + /** + * @param array $results + * @return string + */ + public function extractErrors($results) + { + $errorMessage = ''; + $allChecksRequired = $this->getOption('a') !== null; + + foreach ($results as $result) { + if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) { + $errorMessage .= "--------\n"; + $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n"; + } + } + + return $errorMessage; + } + + /** + * @param string $text + */ + public function output($text) + { + $debugInfo = $this->getOption('v') !== null; + if ($debugInfo) { + echo $text; + } + } +} From d53e64a583d3cc3ed81ff43095b631a132ea52f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 11:46:27 +0200 Subject: [PATCH 5/9] [TASK] Install Script: Register installation class --- src/Core/Console.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Core/Console.php b/src/Core/Console.php index a1143ae1d9..fa69ad968e 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -21,6 +21,7 @@ class Console extends \Asika\SimpleConsole\Console 'extract' => __NAMESPACE__ . '\Console\Extract', 'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock', 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence', + 'install' => __NAMESPACE__ . '\Console\AutomaticInstallation', 'maintenance' => __NAMESPACE__ . '\Console\Maintenance', 'newpassword' => __NAMESPACE__ . '\Console\NewPassword', 'php2po' => __NAMESPACE__ . '\Console\PhpToPo', @@ -42,6 +43,7 @@ Commands: globalcommunityblock Block remote profile from interacting with this node globalcommunitysilence Silence remote profile from global community page help Show help about a command, e.g (bin/console help config) + install Starts automatic installation of friendica based on values from htconfig.php maintenance Set maintenance mode for this node newpassword Set a new password for a given user php2po Generate a messages.po file from a strings.php file From 7b7ca71bf6b96ea45a201b4562d35a51f6ed5cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 14:20:21 +0200 Subject: [PATCH 6/9] [TASK] Auto install: Rename script command --- src/Core/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Console.php b/src/Core/Console.php index fa69ad968e..36614ad55b 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -21,7 +21,7 @@ class Console extends \Asika\SimpleConsole\Console 'extract' => __NAMESPACE__ . '\Console\Extract', 'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock', 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence', - 'install' => __NAMESPACE__ . '\Console\AutomaticInstallation', + 'autoinstall' => __NAMESPACE__ . '\Console\AutomaticInstallation', 'maintenance' => __NAMESPACE__ . '\Console\Maintenance', 'newpassword' => __NAMESPACE__ . '\Console\NewPassword', 'php2po' => __NAMESPACE__ . '\Console\PhpToPo', From 24626f5fd20d076025e1c49d1dc59580ffca9834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 14:21:40 +0200 Subject: [PATCH 7/9] [TASK] Auto install: Rename script command --- src/Core/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Console.php b/src/Core/Console.php index 36614ad55b..82c485179e 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -43,7 +43,7 @@ Commands: globalcommunityblock Block remote profile from interacting with this node globalcommunitysilence Silence remote profile from global community page help Show help about a command, e.g (bin/console help config) - install Starts automatic installation of friendica based on values from htconfig.php + autoinstall Starts automatic installation of friendica based on values from htconfig.php maintenance Set maintenance mode for this node newpassword Set a new password for a given user php2po Generate a messages.po file from a strings.php file From 457b86711d47236dcabafdbdf83a9d44ccecf4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Wed, 18 Apr 2018 14:30:42 +0200 Subject: [PATCH 8/9] [TASK] Auto install: Rework class --- src/Core/Console/AutomaticInstallation.php | 66 ++++++++-------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index a847b4a1bc..5df99c1e94 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -16,11 +16,7 @@ class AutomaticInstallation extends Console return <<output("Initializing setup...\n"); + $this->out("Initializing setup...\n"); $a = get_app(); $db_host = ''; $db_user = ''; $db_pass = ''; $db_data = ''; - require_once '.htautoinstall.php'; + require_once 'htconfig.php'; - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Check basic setup - $this->output("Checking basic setup...\n"); + $this->out("Checking basic setup...\n"); $checkResults = []; $checkResults['basic'] = $this->runBasicChecks($a); $errorMessage = $this->extractErrors($checkResults['basic']); if ($errorMessage !== '') { - die($errorMessage); + throw new \RuntimeException($errorMessage); } - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Check database connection - $this->output("Checking database...\n"); + $this->out("Checking database...\n"); $checkResults['db'] = array(); $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data); $errorMessage = $this->extractErrors($checkResults['db']); if ($errorMessage !== '') { - die($errorMessage); + throw new \RuntimeException($errorMessage); } - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Install database - $this->output("Inserting data into database...\n"); + $this->out("Inserting data into database...\n"); $checkResults['data'] = load_database(); if ($checkResults['data'] !== '') { - die("ERROR: DB Database creation error. Is the DB empty?\n"); + throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n"); } - $this->output(" Complete!\n\n"); + $this->out(" Complete!\n\n"); // Copy config file - $this->output("Saving config file...\n"); - if (!copy('.htautoinstall.php', '.htconfig.php')) { - die("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n"); + $this->out("Saving config file...\n"); + if (!copy('htconfig.php', '.htconfig.php')) { + throw new \RuntimeException("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n"); } - $this->output(" Complete!\n\n"); - $this->output("\nInstallation is finished\n"); + $this->out(" Complete!\n\n"); + $this->out("\nInstallation is finished\n"); return 0; } @@ -103,7 +94,7 @@ HELP; * @param App $app * @return array */ - public function runBasicChecks($app) + private function runBasicChecks($app) { $checks = []; @@ -116,10 +107,10 @@ HELP; if (!empty($app->config['php_path'])) { check_php($app->config['php_path'], $checks); } else { - die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); + throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); } - $this->output(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); + $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); return $checks; } @@ -131,7 +122,7 @@ HELP; * @param $db_data * @return array */ - public function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data) + private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data) { $result = array( 'title' => 'MySQL Connection', @@ -153,7 +144,7 @@ HELP; * @param array $results * @return string */ - public function extractErrors($results) + private function extractErrors($results) { $errorMessage = ''; $allChecksRequired = $this->getOption('a') !== null; @@ -167,15 +158,4 @@ HELP; return $errorMessage; } - - /** - * @param string $text - */ - public function output($text) - { - $debugInfo = $this->getOption('v') !== null; - if ($debugInfo) { - echo $text; - } - } } From e2a58a791c3b3da4c307ffcb18ad936b8b8e6728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Thu, 19 Apr 2018 10:21:41 +0200 Subject: [PATCH 9/9] [DOCS] Auto Install: Add description --- src/Core/Console/AutomaticInstallation.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 5df99c1e94..6318b19a88 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -17,6 +17,9 @@ class AutomaticInstallation extends Console Installation - Install Friendica automatically Synopsis bin/console autoinstall [-h|--help|-?] [-v] [-a] + +Description + Installs Friendica with data based on the htconfig.php file Notes: Not checking .htaccess/URL-Rewrite during CLI installation.