fix auto install

This commit is contained in:
Philipp Holzer 2019-04-13 21:46:06 +02:00
parent 90a38a00d8
commit 677cb205f5
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
5 changed files with 78 additions and 23 deletions

View file

@ -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
*

View file

@ -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 <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
-U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
-P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
-U|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH)
-U|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL)
-B|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
-b|--basepath <base_path> The basepath of Friendica(env FRIENDICA_BASE_PATH)
-S|--sslpolicy <ssl_policy> The SSL policy of Friendica (env FRIENDICA_SSL_POLICY)
-n|--hostname <hostname> The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME)
-t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
-L|--lang <language> 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");

View file

@ -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);

View file

@ -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 {

42
test.config.php Normal file
View file

@ -0,0 +1,42 @@
<?php
// Local configuration
// If you're unsure about what any of the config keys below do, please check the config/defaults.config.php for detailed
// documentation of their data type and behavior.
return [
'database' => [
'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',
],
];