#!/usr/bin/env php exec('CREATE ROLE ' . ($config['DB_USER']) . ' WITH LOGIN PASSWORD ' . $pdo->quote($config['DB_PASS'])); $pdo->exec('CREATE DATABASE ' . ($config['DB_NAME']) . ' WITH OWNER ' . ($config['DB_USER'])); unset($pdo); if (dbcheck($config)) { echo 'Database login created and confirmed' . PHP_EOL; } else { error('Database login failed, trying to create login failed as well'); } } $pdo = dbconnect($config); try { $pdo->query('SELECT 1 FROM ttrss_feeds'); echo 'Connection to database successful' . PHP_EOL; // Reached this point => table found, assume db is complete if (env('TTRSS_THEME_RESET', '1')) { // Make sure to set the default theme provided by TT-RSS. // Other themes might break everything after an update, so play safe here. echo 'Resetting theme to default ...' . PHP_EOL; $pdo->query("UPDATE ttrss_user_prefs SET value = '' WHERE pref_name = 'USER_CSS_THEME'"); } } catch (PDOException $e) { echo 'Database table not found, applying schema... ' . PHP_EOL; $schema = file_get_contents($confpath . '/schema/ttrss_schema_' . $config['DB_TYPE'] . '.sql'); $schema = preg_replace('/--(.*?);/', '', $schema); $schema = preg_replace('/[\r\n]/', ' ', $schema); $schema = trim($schema, ' ;'); foreach (explode(';', $schema) as $stm) { $pdo->exec($stm); } unset($pdo); } $contents = file_get_contents($conffile); foreach ($config as $name => $value) { $contents .= "putenv('TTRSS_" . $name . "=" . $value . "');\n"; } file_put_contents($conffile, $contents);