do-install.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/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'])) && server_is_public($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 (!checkDb()) {
  71. @unlink(join_path(DATA_PATH, 'config.php'));
  72. fail('FreshRSS database error: ' . (empty($_SESSION['bd_error']) ? 'Unknown error' : $_SESSION['bd_error']));
  73. }
  74. echo '• Remember to create the default user: ', $config['default_user'] , "\n",
  75. "\t", './cli/create-user.php --user ', $config['default_user'], " --password 'password' --more-options\n";
  76. accessRights();
  77. if (!deleteInstall()) {
  78. fail('FreshRSS access right problem while deleting install file!');
  79. }
  80. done();