From 677cb205f50bf27757a6d7c5a810835b5690b63d Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 21:46:06 +0200 Subject: [PATCH] fix auto install --- src/App.php | 10 ++++++ src/Core/Console/AutomaticInstallation.php | 30 +++++++--------- src/Core/Installer.php | 8 +++-- src/Core/Renderer.php | 11 +++--- test.config.php | 42 ++++++++++++++++++++++ 5 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 test.config.php diff --git a/src/App.php b/src/App.php index 1123f67b06..c0cc1617d0 100644 --- a/src/App.php +++ b/src/App.php @@ -138,6 +138,16 @@ class App return $this->config->getCache(); } + /** + * Returns the current config of this nodde + * + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + /** * The basepath of this app * diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 34a933e12e..50da333625 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -7,6 +7,8 @@ use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Installer; use Friendica\Core\Theme; +use Friendica\Util\BasePath; +use Friendica\Util\BaseURL; use Friendica\Util\Config\ConfigFileLoader; use RuntimeException; @@ -36,11 +38,9 @@ Options -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) - -U|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) + -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) - -S|--sslpolicy The SSL policy of Friendica (env FRIENDICA_SSL_POLICY) - -n|--hostname The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME) -t|--tz The timezone of Friendica (env FRIENDICA_TZ) -L|--lang The language of Friendica (env FRIENDICA_LANG) @@ -50,12 +50,10 @@ Environment variables MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb) MYSQL_PASSWORD The password of the mysql/mariadb database login MYSQL_DATABASE The name of the mysql/mariadb database - FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection + FRIENDICA_URL The full base URL of Friendica - f.e. 'https://friendica.local/sub' FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection FRIENDICA_BASE_PATH The basepath of Friendica - leave empty for auto detection FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access) - FRIENDICA_SSL_POLICY The SSL policy of Friendica (default is NO SSL) - FRIENDICA_HOSTNAME The hostname of Friendica - leave empty for auto detection FRIENDICA_TZ The timezone of Friendica FRIENDICA_LANG The langauge of Friendica @@ -81,7 +79,7 @@ HELP; $installer = new Installer(); $configCache = $a->getConfigCache(); - $installer->setUpCache($configCache, dirname(__DIR__, 3), $_SERVER); + $installer->setUpCache($configCache, BasePath::create($a->getBasePath(), $_SERVER)); $this->out(" Complete!\n\n"); @@ -119,7 +117,6 @@ HELP; $save_db = $this->getOption(['s', 'savedb'], false); - //$db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? (getenv('MYSQL_HOST') ? getenv('MYSQL_HOST') : Installer::DEFAULT_HOST) : ''); $db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? (getenv('MYSQL_HOST')) : Installer::DEFAULT_HOST); $db_port = $this->getOption(['p', 'dbport'], ($save_db) ? getenv('MYSQL_PORT') : null); $configCache->set('database', 'hostname', $db_host . (!empty($db_port) ? ':' . $db_port : '')); @@ -149,7 +146,6 @@ HELP; $this->getOption(['L', 'lang'], !empty(getenv('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : Installer::DEFAULT_LANG)); - $configCache->set('system', 'urlpath', $this->getOption(['u', 'urlpath'], !empty(getenv('FRIENDICA_URL_PATH')) ? getenv('FRIENDICA_URL_PATH') : '')); $basepath = $this->getOption(['b', 'basepath'], !empty(getenv('FRIENDICA_BASE_PATH')) ? getenv('FRIENDICA_BASE_PATH') : null); if (!empty($basepath)) { $configCache->set('system', 'basepath', $basepath); @@ -158,20 +154,20 @@ HELP; if (!empty($php_path)) { $configCache->set('config', 'php_path', $php_path); } - $ssl_policy = $this->getOption(['S', 'sslpolicy'], !empty(getenv('FRIENDICA_SSL_POLICY')) ? getenv('FRIENDICA_SSL_POLICY') : null); - if (!empty($ssl_policy)) { - $configCache->set('system', 'ssl_policy', $ssl_policy); - } - $configCache->set('config', 'hostname', $this->getOption(['n', 'hostname'], !empty(getenv('FRIENDICA_HOSTNAME')) ? getenv('FRIENDICA_HOSTNAME') : '')); - $configCache->set('system', 'url', $installer->determineBaseUrl($configCache)); + $url = $this->getOption(['U', 'url'], !empty(getenv('FRIENDICA_URL')) ? getenv('FRIENDICA_URL') : null); - if (empty($configCache->get('config', 'hostname'))) { - $this->out('The Friendica hostname has to be set during CLI installation.'); + if (empty($url)) { + $this->out('The Friendica URL has to be set during CLI installation.'); return 1; + } else { + $baseUrl = new BaseURL($a->getConfig(), []); + $baseUrl->saveByURL($url); } $installer->createConfig($configCache); + + return 1; } $this->out(" Complete!\n\n"); diff --git a/src/Core/Installer.php b/src/Core/Installer.php index 52a51498e8..be725056d1 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -140,6 +140,10 @@ class Installer { $basepath = $configCache->get('system', 'basepath'); + $url = $configCache->get('system', 'url'); + + print_r("URL - " . $url . PHP_EOL); + $tpl = Renderer::getMarkupTemplate('local.config.tpl'); $txt = Renderer::replaceMacros($tpl, [ '$dbhost' => $configCache->get('database', 'hostname'), @@ -152,12 +156,12 @@ class Installer '$hostname' => $configCache->get('config', 'hostname'), '$urlpath' => $configCache->get('system', 'urlpath'), - '$baseurl' => $configCache->get('system', 'url'), + '$baseurl' => $url, '$sslpolicy' => $configCache->get('system', 'ssl_policy'), '$basepath' => $basepath, '$timezone' => $configCache->get('system', 'default_timezone'), '$language' => $configCache->get('system', 'language'), - ]); + ], false); $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt); diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index 8844f26881..ef3665d748 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -52,19 +52,22 @@ class Renderer extends BaseObject /** * @brief This is our template processor * - * @param string|FriendicaSmarty $s The string requiring macro substitution or an instance of FriendicaSmarty - * @param array $vars key value pairs (search => replace) + * @param string|FriendicaSmarty $s The string requiring macro substitution or an instance of FriendicaSmarty + * @param array $vars key value pairs (search => replace) + * @param bool $overwriteURL Overwrite the base url with the system wide set base url * * @return string substituted string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function replaceMacros($s, $vars) + public static function replaceMacros($s, $vars, $overwriteURL = true) { $stamp1 = microtime(true); $a = self::getApp(); // pass $baseurl to all templates - $vars['$baseurl'] = System::baseUrl(); + if ($overwriteURL) { + $vars['$baseurl'] = System::baseUrl(); + } $t = self::getTemplateEngine(); try { diff --git a/test.config.php b/test.config.php new file mode 100644 index 0000000000..df2073ae77 --- /dev/null +++ b/test.config.php @@ -0,0 +1,42 @@ + [ + 'hostname' => 'localhost', + 'username' => 'friendica', + 'password' => 'friendica', + 'database' => 'friendica', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'php_path' => '/usr/bin/php', + 'admin_email' => '', + 'sitename' => 'Friendica Social Network', + 'hostname' => 'friendica.local', + 'register_policy' => \Friendica\Module\Register::OPEN, + 'max_import_size' => 200000, + ], + 'system' => [ + 'urlpath' => 'test', + 'url' => 'https://friendica.local/test', + 'ssl_policy' => 1, + 'basepath' => '/vagrant', + 'default_timezone' => 'America/Los_Angeles', + 'language' => 'en', + 'debugging' => true, + 'logfile' => 'friendica.log', + 'loglevel' => 'info', + ], +]; -- 2.39.5