Files
FreshRSS/cli/_cli.php
Alexandre Alapetite 8dfe209799 Possiblity to autoinstall in Docker Compose (#3353)
* Possiblity to autoinstall in Docker Compose

#fix https://github.com/FreshRSS/FreshRSS/issues/3349

It is simply calling our existing CLI: do-install.php and
create-user.php
https://github.com/FreshRSS/FreshRSS/tree/master/cli

FreshRSS will typically be ready a few seconds before the database, so
introduce a tolerance when the database is not available / up (yet) by
trying a few times to connect. Also useful to avoid service interruption
when DB service is restarted.

Example:

```yml
freshrss-app:
    image: freshrss/freshrss
    container_name:
freshrss-app
    hostname: freshrss-app
    restart: unless-stopped

ports:
      - "8080:80"
    depends_on:
      - freshrss-db

volumes:
      - data:/var/www/FreshRSS/data
      -
extensions:/var/www/FreshRSS/extensions
    environment:
      CRON_MIN:
'*/20'
      FRESHRSS_ENV: development
      FRESHRSS_INSTALL: |-

--api_enabled
        --base_url https://rss.example.net

--db-base freshrss
        --db-host freshrss-db
        --db-password
freshrss
        --db-type pgsql
        --db-user freshrss

--default_user admin
        --language en
      FRESHRSS_USER: |-

--api_password freshrss
        --email user@example.net

--language en
        --password freshrss
        --user admin
      TZ:
Europe/Paris
```

* Minor type f in find

* shellcheck
2021-01-11 22:36:50 +01:00

91 lines
2.6 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
if (php_sapi_name() !== 'cli') {
die('FreshRSS error: This PHP script may only be invoked from command line!');
}
const EXIT_CODE_ALREADY_EXISTS = 3;
const REGEX_INPUT_OPTIONS = '/^--/';
const REGEX_PARAM_OPTIONS = '/:*$/';
require(__DIR__ . '/../constants.php');
require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader
require(LIB_PATH . '/lib_install.php');
Minz_Session::init('FreshRSS', true);
FreshRSS_Context::initSystem();
Minz_Translate::init('en');
FreshRSS_Context::$isCli = true;
function fail($message, $exitCode=1) {
fwrite(STDERR, $message . "\n");
die($exitCode);
}
function cliInitUser($username) {
if (!FreshRSS_user_Controller::checkUsername($username)) {
fail('FreshRSS error: invalid username: ' . $username . "\n");
}
$usernames = listUsers();
if (!in_array($username, $usernames)) {
fail('FreshRSS error: user not found: ' . $username . "\n");
}
if (!FreshRSS_Context::initUser($username)) {
fail('FreshRSS error: invalid configuration for user: ' . $username . "\n");
}
return $username;
}
function accessRights() {
echo ' Remember to re-apply the appropriate access rights, such as:',
"\t", 'sudo chown -R :www-data . && sudo chmod -R g+r . && sudo chmod -R g+w ./data/', "\n";
}
function done($ok = true) {
if (!$ok) {
fwrite(STDERR, (empty($_SERVER['argv'][0]) ? 'Process' : basename($_SERVER['argv'][0])) . ' failed!' . "\n");
}
exit($ok ? 0 : 1);
}
function performRequirementCheck($databaseType) {
$requirements = checkRequirements($databaseType);
if ($requirements['all'] !== 'ok') {
$message = 'FreshRSS install failed requirements:' . "\n";
foreach ($requirements as $requirement => $check) {
if ($check !== 'ok' && !in_array($requirement, array('all', 'pdo', 'message'))) {
$message .= '• ' . $requirement . "\n";
}
}
if (!empty($requirements['message'])) {
$message .= '• ' . $requirements['message'] . "\n";
}
fail($message);
}
}
function getLongOptions($options, $regex) {
$longOptions = array_filter($options, function($a) use ($regex) {
return preg_match($regex, $a);
});
return array_map(function($a) use ($regex) {
return preg_replace($regex, '', $a);
}, $longOptions);
}
function validateOptions($input, $params) {
$sanitizeInput = getLongOptions($input, REGEX_INPUT_OPTIONS);
$sanitizeParams = getLongOptions($params, REGEX_PARAM_OPTIONS);
$unknownOptions = array_diff($sanitizeInput, $sanitizeParams);
if (0 === count($unknownOptions)) {
return true;
}
fwrite(STDERR, sprintf("FreshRSS error: unknown options: %s\n", implode (', ', $unknownOptions)));
return false;
}