do-install.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env php
  2. <?php
  3. require(__DIR__ . '/_cli.php');
  4. if (!file_exists(DATA_PATH . '/do-install.txt')) {
  5. fail('FreshRSS seems to be already installed! Please use `./cli/reconfigure.php` instead.');
  6. }
  7. $params = array(
  8. 'environment:',
  9. 'base_url:',
  10. 'language:',
  11. 'title:',
  12. 'default_user:',
  13. 'allow_anonymous',
  14. 'allow_anonymous_refresh',
  15. 'auth_type:',
  16. 'api_enabled',
  17. 'allow_robots',
  18. 'disable_update',
  19. );
  20. $dBparams = array(
  21. 'db-type:',
  22. 'db-host:',
  23. 'db-user:',
  24. 'db-password:',
  25. 'db-base:',
  26. 'db-prefix:',
  27. );
  28. $options = getopt('', array_merge($params, $dBparams));
  29. if (!validateOptions($argv, array_merge($params, $dBparams)) || empty($options['default_user'])) {
  30. fail('Usage: ' . basename(__FILE__) . " --default_user admin ( --auth_type form" .
  31. " --environment production --base_url https://rss.example.net --allow_robots" .
  32. " --language en --title FreshRSS --allow_anonymous --allow_anonymous_refresh --api_enabled" .
  33. " --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123" .
  34. " --db-base freshrss --db-prefix freshrss_ --disable_update )");
  35. }
  36. fwrite(STDERR, 'FreshRSS install…' . "\n");
  37. $config = array(
  38. 'salt' => generateSalt(),
  39. 'db' => FreshRSS_Context::$system_conf->db,
  40. );
  41. foreach ($params as $param) {
  42. $param = rtrim($param, ':');
  43. if (isset($options[$param])) {
  44. $config[$param] = $options[$param] === false ? true : $options[$param];
  45. }
  46. }
  47. if ((!empty($config['base_url'])) && Minz_Request::serverIsPublic($config['base_url'])) {
  48. $config['pubsubhubbub_enabled'] = true;
  49. }
  50. foreach ($dBparams as $dBparam) {
  51. $dBparam = rtrim($dBparam, ':');
  52. if (isset($options[$dBparam])) {
  53. $param = substr($dBparam, strlen('db-'));
  54. $config['db'][$param] = $options[$dBparam];
  55. }
  56. }
  57. performRequirementCheck($config['db']['type']);
  58. if (!FreshRSS_user_Controller::checkUsername($options['default_user'])) {
  59. fail('FreshRSS error: invalid default username “' . $options['default_user']
  60. . '”! Must be matching ' . FreshRSS_user_Controller::USERNAME_PATTERN);
  61. }
  62. if (isset($options['auth_type']) && !in_array($options['auth_type'], array('form', 'http_auth', 'none'))) {
  63. fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }): '
  64. . $options['auth_type']);
  65. }
  66. if (file_put_contents(join_path(DATA_PATH, 'config.php'),
  67. "<?php\n return " . var_export($config, true) . ";\n") === false) {
  68. fail('FreshRSS could not write configuration file!: ' . join_path(DATA_PATH, 'config.php'));
  69. }
  70. if (function_exists('opcache_reset')) {
  71. opcache_reset();
  72. }
  73. Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php');
  74. FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
  75. Minz_Session::_param('currentUser', '_'); //Default user
  76. $ok = false;
  77. try {
  78. $error = initDb();
  79. if ($error != '') {
  80. $_SESSION['bd_error'] = $error;
  81. } else {
  82. $ok = true;
  83. }
  84. } catch (Exception $ex) {
  85. $_SESSION['bd_error'] = $ex->getMessage();
  86. }
  87. if (!$ok) {
  88. @unlink(join_path(DATA_PATH, 'config.php'));
  89. fail('FreshRSS database error: ' . (empty($_SESSION['bd_error']) ? 'Unknown error' : $_SESSION['bd_error']));
  90. }
  91. echo '• Remember to create the default user: ', $config['default_user'] , "\n",
  92. "\t", './cli/create-user.php --user ', $config['default_user'], " --password 'password' --more-options\n";
  93. accessRights();
  94. if (!setupMigrations()) {
  95. fail('FreshRSS access right problem while creating migrations version file!');
  96. }
  97. if (!deleteInstall()) {
  98. fail('FreshRSS access right problem while deleting install file!');
  99. }
  100. done();