diff --git a/_cleanup.php b/_cleanup.php index 3c223d399..3b292c216 100644 --- a/_cleanup.php +++ b/_cleanup.php @@ -7,12 +7,15 @@ * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License */ +if (!defined('BB_ROOT')) { + define('BB_ROOT', __DIR__ . DIRECTORY_SEPARATOR); +} + +// Check CLI mode if (php_sapi_name() !== 'cli') { exit; } -define('BB_ROOT', __DIR__ . DIRECTORY_SEPARATOR); - $items = [ '.github', '.editorconfig', @@ -47,9 +50,9 @@ foreach ($items as $item) { function removeFile(string $file): void { if (unlink($file)) { - echo "[INFO] File removed: $file" . PHP_EOL; + echo "- File removed: $file" . PHP_EOL; } else { - echo "[ERROR] File cannot be removed: $file" . PHP_EOL; + echo "- File cannot be removed: $file" . PHP_EOL; exit; } } @@ -73,9 +76,9 @@ function removeDir(string $dir): void } if (rmdir($dir)) { - echo "[INFO] Folder removed: $dir" . PHP_EOL; + echo "- Folder removed: $dir" . PHP_EOL; } else { - echo "[ERROR] Folder cannot be removed: $dir" . PHP_EOL; + echo "- Folder cannot be removed: $dir" . PHP_EOL; exit; } } diff --git a/install.php b/install.php index c61ec7f81..72bd12068 100644 --- a/install.php +++ b/install.php @@ -7,7 +7,7 @@ * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License */ -define('BB_ROOT', __DIR__ . '/'); +define('BB_ROOT', __DIR__ . DIRECTORY_SEPARATOR); // Check CLI mode if (php_sapi_name() !== 'cli') { @@ -185,7 +185,7 @@ if (!defined('EXTENSIONS_NOT_INSTALLED')) { if (is_file(BB_ROOT . '.env')) { out('- TorrentPier already installed', 'warning'); echo 'Are you sure want to re-install TorrentPier? [y/N]: '; - if (str_starts_with(mb_strtolower(readline()), 'y')) { + if (str_starts_with(mb_strtolower(trim(readline())), 'y')) { out("\n- Re-install process started...", 'info'); // environment if (is_file(BB_ROOT . '.env')) { @@ -415,5 +415,23 @@ if (!empty($DB_HOST) && !empty($DB_DATABASE) && !empty($DB_USERNAME)) { } } + // Cleanup... + if (is_file(BB_ROOT . '_cleanup.php')) { + out("\n--- Finishing installation (Cleanup) ---\n", 'info'); + out('The cleanup process will remove:'); + out('- Development documentation (README, CHANGELOG)', 'debug'); + out('- Git configuration files', 'debug'); + out('- CI/CD pipelines and code analysis tools', 'debug'); + out('- Translation and contribution guidelines', 'debug'); + echo 'Do you want to delete these files permanently? [y/N]: '; + if (str_starts_with(mb_strtolower(trim(readline())), 'y')) { + out("\n- Cleanup...", 'info'); + require_once BB_ROOT . '_cleanup.php'; + unlink(BB_ROOT . '_cleanup.php'); + } else { + out('- Skipping...', 'info'); + } + } + out("\n- Voila! Good luck & have fun!", 'success'); }