Update install.php

This commit is contained in:
Roman Kelesidis 2024-08-10 19:22:37 +07:00
commit 893e065822

View file

@ -7,7 +7,7 @@
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/ */
define('ROOT', __DIR__ . '/'); define('BB_ROOT', __DIR__ . '/');
// Check CLI mode // Check CLI mode
if (php_sapi_name() !== 'cli') { if (php_sapi_name() !== 'cli') {
@ -15,7 +15,7 @@ if (php_sapi_name() !== 'cli') {
} }
// Check if already installed // Check if already installed
if (is_file(ROOT . '.env')) { if (is_file(BB_ROOT . '.env')) {
out('- TorrentPier already installed!', 'error'); out('- TorrentPier already installed!', 'error');
exit; exit;
} }
@ -129,27 +129,27 @@ out("--- TorrentPier Installer ---\n", 'info');
// Setting permissions // Setting permissions
out('- Setting permissions for folders...', 'info'); out('- Setting permissions for folders...', 'info');
chmod_r(ROOT . 'data', 0755, 0644); chmod_r(BB_ROOT . 'data', 0755, 0644);
chmod_r(ROOT . 'internal_data', 0755, 0644); chmod_r(BB_ROOT . 'internal_data', 0755, 0644);
chmod_r(ROOT . 'sitemap', 0755, 0644); chmod_r(BB_ROOT . 'sitemap', 0755, 0644);
out("- Permissions successfully applied!\n", 'success'); out("- Permissions successfully applied!\n", 'success');
// Check composer installation // Check composer installation
if (!is_file(ROOT . 'vendor/autoload.php')) { if (!is_file(BB_ROOT . 'vendor/autoload.php')) {
out('- Hmm, it seems there are no Composer dependencies', 'info'); out('- Hmm, it seems there are no Composer dependencies', 'info');
// Downloading composer // Downloading composer
if (!is_file(ROOT . 'composer.phar')) { if (!is_file(BB_ROOT . 'composer.phar')) {
out('- Downloading Composer...', 'info'); out('- Downloading Composer...', 'info');
if (copy('https://getcomposer.org/installer', ROOT . 'composer-setup.php')) { if (copy('https://getcomposer.org/installer', BB_ROOT . 'composer-setup.php')) {
out("- Composer successfully downloaded!\n", 'success'); out("- Composer successfully downloaded!\n", 'success');
runProcess('php ' . ROOT . 'composer-setup.php'); runProcess('php ' . BB_ROOT . 'composer-setup.php');
} else { } else {
out('- Cannot download Composer', 'error'); out('- Cannot download Composer', 'error');
exit; exit;
} }
if (is_file(ROOT . 'composer-setup.php')) { if (is_file(BB_ROOT . 'composer-setup.php')) {
if (unlink(ROOT . 'composer-setup.php')) { if (unlink(BB_ROOT . 'composer-setup.php')) {
out("- Composer installation file successfully removed!\n", 'success'); out("- Composer installation file successfully removed!\n", 'success');
} else { } else {
out('- Cannot remove Composer installation file. Delete it manually', 'warning'); out('- Cannot remove Composer installation file. Delete it manually', 'warning');
@ -158,9 +158,9 @@ if (!is_file(ROOT . 'vendor/autoload.php')) {
} }
// Installing dependencies // Installing dependencies
if (is_file(ROOT . 'composer.phar')) { if (is_file(BB_ROOT . 'composer.phar')) {
out('- Installing dependencies...', 'info'); out('- Installing dependencies...', 'info');
runProcess('php ' . ROOT . 'composer.phar install --no-interaction --no-ansi'); runProcess('php ' . BB_ROOT . 'composer.phar install --no-interaction --no-ansi');
out("- Completed!\n", 'success'); out("- Completed!\n", 'success');
} else { } else {
out('- composer.phar not found', 'error'); out('- composer.phar not found', 'error');
@ -169,8 +169,8 @@ if (!is_file(ROOT . 'vendor/autoload.php')) {
} }
// Preparing ENV // Preparing ENV
if (is_file(ROOT . '.env.example') && !is_file(ROOT . '.env')) { if (is_file(BB_ROOT . '.env.example') && !is_file(BB_ROOT . '.env')) {
if (copy(ROOT . '.env.example', ROOT . '.env')) { if (copy(BB_ROOT . '.env.example', BB_ROOT . '.env')) {
out("- Environment file created!\n", 'success'); out("- Environment file created!\n", 'success');
} else { } else {
out('- Cannot create environment file', 'error'); out('- Cannot create environment file', 'error');
@ -185,10 +185,10 @@ $DB_DATABASE = '';
$DB_USERNAME = ''; $DB_USERNAME = '';
$DB_PASSWORD = ''; $DB_PASSWORD = '';
if (is_file(ROOT . '.env')) { if (is_file(BB_ROOT . '.env')) {
out("--- Configuring TorrentPier ---", 'info'); out("--- Configuring TorrentPier ---", 'info');
$envContent = file_get_contents(ROOT . '.env'); $envContent = file_get_contents(BB_ROOT . '.env');
if ($envContent === false) { if ($envContent === false) {
out('- Cannot open environment file', 'error'); out('- Cannot open environment file', 'error');
exit; exit;
@ -224,7 +224,7 @@ if (is_file(ROOT . '.env')) {
} }
$newEnvContent = implode("\n", $editedLines); $newEnvContent = implode("\n", $editedLines);
if (file_put_contents(ROOT . '.env', $newEnvContent)) { if (file_put_contents(BB_ROOT . '.env', $newEnvContent)) {
out("- TorrentPier successfully configured!\n", 'success'); out("- TorrentPier successfully configured!\n", 'success');
} else { } else {
out('- Cannot save environment file', 'error'); out('- Cannot save environment file', 'error');
@ -267,7 +267,7 @@ if (!empty($DB_HOST) && !empty($DB_DATABASE) && !empty($DB_USERNAME)) {
$conn->select_db($DB_DATABASE); $conn->select_db($DB_DATABASE);
// Checking SQL dump // Checking SQL dump
$dumpPath = ROOT . 'install/sql/mysql.sql'; $dumpPath = BB_ROOT . 'install/sql/mysql.sql';
if (is_file($dumpPath) && is_readable($dumpPath)) { if (is_file($dumpPath) && is_readable($dumpPath)) {
out('- SQL dump file found and readable!', 'success'); out('- SQL dump file found and readable!', 'success');
} else { } else {