Update install scripts

This commit is contained in:
DariusIII
2017-04-26 00:20:58 +02:00
parent 27a9ea9fb6
commit 9894cc700b
3 changed files with 82 additions and 22 deletions
+1
View File
@@ -1,6 +1,7 @@
.DS_Store
config.php
.env
install.lock
error_log
failed-login.log
php_errors.log
+73 -12
View File
@@ -1,17 +1,32 @@
<?php
require_once dirname(__DIR__) . DS . 'bootstrap.php';
if (!defined('NN_INSTALLER')) {
define('NN_INSTALLER', true);
}
require_once dirname(__DIR__) . '/bootstrap.php';
include_once dirname(__DIR__) . '/nntmux/constants.php';
use app\extensions\util\Versions;
use nntmux\config\Configure;
use nntmux\db\DB;
use nntmux\db\DbUpdate;
use nntmux\ColorCLI;
use nntmux\Users;
$config = new Configure('install');
$pdo = new DB();
$users = new Users();
$error = false;
if (file_exists(NN_ROOT . '_install/install.lock')) {
ColorCLI::doEcho(ColorCLI::notice('Installation is locked. If you want to reinstall the database, please remove install.lock file from _install folder'));
exit();
}
// Check if user selected right DB type.
if (getenv('DB_SYSTEM') === 'mysql') {
if (getenv('DB_SYSTEM') !== 'mysql') {
ColorCLI::doEcho(ColorCLI::error('Invalid database system. Must be: mysql ; Not: ' . getenv('DB_SYSTEM')));
$error = true;
} else {
@@ -23,7 +38,7 @@ if (getenv('DB_SYSTEM') === 'mysql') {
'checkVersion' => true,
'createDb' => true,
'dbhost' => getenv('DB_HOST'),
'dbname' => getenv('DB_Name'),
'dbname' => getenv('DB_NAME'),
'dbpass' => getenv('DB_PASSWORD'),
'dbport' => getenv('PORT'),
'dbsock' => getenv('DB_SOCKET'),
@@ -41,8 +56,8 @@ if (getenv('DB_SYSTEM') === 'mysql') {
case 1:
case 2:
case 3:
$error = true;
ColorCLI::doEcho(ColorCLI::alternate($e->getMessage()));
$error = true;
ColorCLI::doEcho(ColorCLI::alternate($e->getMessage()));
break;
default:
var_dump($e);
@@ -56,8 +71,8 @@ if (getenv('DB_SYSTEM') === 'mysql') {
try {
$goodVersion = $pdo->isDbVersionAtLeast(NN_MINIMUM_MYSQL_VERSION);
} catch (\PDOException $e) {
$goodVersion = false;
$error = true;
$goodVersion = false;
$error = true;
ColorCLI::doEcho(ColorCLI::error('Could not get version from MySQL server.'));
}
@@ -67,7 +82,9 @@ if (getenv('DB_SYSTEM') === 'mysql') {
'You are using an unsupported version of ' .
getenv('DB_SYSTEM') .
' the minimum allowed version is ' .
NN_MINIMUM_MYSQL_VERSION));
NN_MINIMUM_MYSQL_VERSION
)
);
}
}
}
@@ -128,12 +145,12 @@ if (!$error) {
if ($updateSettings) {
ColorCLI::doEcho(ColorCLI::info('Database updated successfully'));
} else {
$error = true;
$error = true;
ColorCLI::doEcho(ColorCLI::error('Could not update sqlpatch to ' . $patch . ' for your database.'));
}
} else {
$dbCreateCheck = false;
$error = true;
$error = true;
ColorCLI::doEcho(ColorCLI::warning('Could not select data from your database.'));
}
}
@@ -192,8 +209,52 @@ if (getenv('ADMIN_USER') === '' || getenv('ADMIN_PASS') === '' || getenv('ADMIN_
$adminCheck = $user->add(getenv('ADMIN_USER'), getenv('ADMIN_PASS'), getenv('ADMIN_EMAIL'), 2, '', '');
if (!is_numeric($adminCheck)) {
$error = true;
} else {
$user->login($adminCheck, '', 1);
}
}
}
$doCheck = true;
$covers_path = NN_RES . 'covers' . DS;
$nzb_path = NN_RES . 'nzb' . DS;
$tmp_path = NN_RES . 'tmp' . DS;
$unrar_path = $tmp_path . 'unrar' . DS;
$nzbPathCheck = is_writable($nzb_path);
if ($nzbPathCheck === false) {
$error = true;
}
$lastchar = substr($nzb_path, strlen($nzb_path) - 1);
if ($lastchar !== '/') {
$nzb_path .= '/';
}
$unrarPathCheck = is_writable($nzb_path);
if ($unrarPathCheck === false) {
$error = true;
}
$lastchar = substr($unrar_path, strlen($unrar_path) - 1);
if ($lastchar !== '/') {
$unrar_path .= '/';
}
if (!$error) {
if (!file_exists($unrar_path)) {
mkdir($unrar_path);
}
$sql1 = sprintf("UPDATE settings SET value = %s WHERE setting = 'nzbpath'", $pdo->escapeString($nzb_path));
$sql2 = sprintf("UPDATE settings SET value = %s WHERE setting = 'tmpunrarpath'", $pdo->escapeString($unrar_path));
$sql3 = sprintf("UPDATE settings SET value = %s WHERE setting = 'coverspath'", $pdo->escapeString($covers_path));
if ($pdo->queryExec($sql1) === false || $pdo->queryExec($sql2) === false || $pdo->queryExec($sql3) === false) {
$error = true;
} else {
ColorCLI::doEcho(ColorCLI::info('Settings table updated successfully'));
}
}
if (!$error) {
@file_put_contents(NN_ROOT . '_install/install.lock', '');
ColorCLI::doEcho(ColorCLI::alternate('NNTmux installation completed successfully'));
}
+8 -10
View File
@@ -28,7 +28,7 @@ class Configure
'settings' => false
],
'install' => [
'.env' => false,
'.env' => true,
'settings' => false
],
'smarty' => [
@@ -49,21 +49,19 @@ class Configure
$this->loadSettings($config, $throwException);
}
} else {
throw new \RuntimeException("Unknown environment passed to Configure class!");
throw new \RuntimeException('Unknown environment passed to Configure class!');
}
}
public function loadSettings($filename, $throwException = true)
{
$file = NN_ROOT . '.env';
if (!file_exists($file)) {
if ($throwException) {
$errorCode = (int)($filename === '.env');
throw new \RuntimeException(
"Unable to load configuration file '$file'. Make sure it has been created and contains correct settings.",
$errorCode
);
}
if (!file_exists($file) && $throwException) {
$errorCode = (int)($filename === '.env');
throw new \RuntimeException(
"Unable to load configuration file '$file'. Make sure it has been created and contains correct settings.",
$errorCode
);
}
switch ($filename) {