+ $a = BaseObject::getApp();
+
+ // if a config file is set,
+ $config_file = $this->getOption(['f', 'file']);
+
+ if (!empty($config_file)) {
+ if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') {
+ // Copy config file
+ $this->out("Copying config file...\n");
+ if (!copy($a->basepath . DIRECTORY_SEPARATOR . $config_file, $a->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
+ throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '$a->basepath" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.ini.php' manually.\n");
+ }
+ }
+
+ $db_host = $a->getConfigValue('database', 'hostname');
+ $db_user = $a->getConfigValue('database', 'username');
+ $db_pass = $a->getConfigValue('database', 'password');
+ $db_data = $a->getConfigValue('database', 'database');
+ } else {
+ // Creating config file
+ $this->out("Creating config file...\n");
+
+ $save_db = $this->getOption(['s', 'savedb'], false);
+
+ $db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? getenv('MYSQL_HOST') : '');
+ $db_port = $this->getOption(['p', 'dbport'], ($save_db) ? getenv('MYSQL_PORT') : null);
+ $db_data = $this->getOption(['d', 'dbdata'], ($save_db) ? getenv('MYSQL_DATABASE') : '');
+ $db_user = $this->getOption(['U', 'dbuser'], ($save_db) ? getenv('MYSQL_USER') . getenv('MYSQL_USERNAME') : '');
+ $db_pass = $this->getOption(['P', 'dbpass'], ($save_db) ? getenv('MYSQL_PASSWORD') : '');
+ $php_path = $this->getOption(['b', 'phppath'], (!empty('FRIENDICA_PHP_PATH')) ? getenv('FRIENDICA_PHP_PATH') : '');
+ $admin_mail = $this->getOption(['A', 'admin'], (!empty('FRIENDICA_ADMIN_MAIL')) ? getenv('FRIENDICA_ADMIN_MAIL') : '');
+ $tz = $this->getOption(['T', 'tz'], (!empty('FRIENDICA_TZ')) ? getenv('FRIENDICA_TZ') : '');
+ $lang = $this->getOption(['L', 'lang'], (!empty('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : '');
+
+ Install::createConfig(
+ $php_path,
+ ((!empty($db_port)) ? $db_host . ':' . $db_port : $db_host),
+ $db_user,
+ $db_pass,
+ $db_data,
+ $php_path,
+ $tz,
+ $lang,
+ $admin_mail
+ );
+ }