mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Update install scripts
This commit is contained in:
+73
-12
@@ -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'));
|
||||
}
|
||||
Reference in New Issue
Block a user