mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 14:23:57 -07:00
misc(cliff): Added automated script for releases creation
This commit is contained in:
parent
c9aff2a152
commit
ac5996f764
3 changed files with 184 additions and 160 deletions
47
_cleanup.php
47
_cleanup.php
|
@ -16,6 +16,12 @@ if (php_sapi_name() !== 'cli') {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get all constants
|
||||||
|
require_once BB_PATH . '/library/defines.php';
|
||||||
|
|
||||||
|
// Include CLI functions
|
||||||
|
require INC_DIR . '/functions_cli.php';
|
||||||
|
|
||||||
$items = [
|
$items = [
|
||||||
'.github',
|
'.github',
|
||||||
'.cliffignore',
|
'.cliffignore',
|
||||||
|
@ -41,44 +47,3 @@ foreach ($items as $item) {
|
||||||
removeDir($path);
|
removeDir($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove target file
|
|
||||||
*
|
|
||||||
* @param string $file Path to file
|
|
||||||
*/
|
|
||||||
function removeFile(string $file): void
|
|
||||||
{
|
|
||||||
if (unlink($file)) {
|
|
||||||
echo "- File removed: $file" . PHP_EOL;
|
|
||||||
} else {
|
|
||||||
echo "- File cannot be removed: $file" . PHP_EOL;
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove folder (recursively)
|
|
||||||
*
|
|
||||||
* @param string $dir Path to folder
|
|
||||||
*/
|
|
||||||
function removeDir(string $dir): void
|
|
||||||
{
|
|
||||||
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
|
||||||
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file->isDir()) {
|
|
||||||
removeDir($file->getPathname());
|
|
||||||
} else {
|
|
||||||
removeFile($file->getPathname());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rmdir($dir)) {
|
|
||||||
echo "- Folder removed: $dir" . PHP_EOL;
|
|
||||||
} else {
|
|
||||||
echo "- Folder cannot be removed: $dir" . PHP_EOL;
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
125
install.php
125
install.php
|
@ -14,6 +14,12 @@ if (php_sapi_name() !== 'cli') {
|
||||||
die('Please run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">php ' . basename(__FILE__) . '</code> in CLI mode');
|
die('Please run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">php ' . basename(__FILE__) . '</code> in CLI mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get all constants
|
||||||
|
require_once BB_PATH . '/library/defines.php';
|
||||||
|
|
||||||
|
// Include CLI functions
|
||||||
|
require INC_DIR . '/functions_cli.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System requirements
|
* System requirements
|
||||||
*/
|
*/
|
||||||
|
@ -34,125 +40,6 @@ define('CHECK_REQUIREMENTS', [
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
|
||||||
* Colored console output
|
|
||||||
*
|
|
||||||
* @param string $str
|
|
||||||
* @param string $type
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function out(string $str, string $type = ''): void
|
|
||||||
{
|
|
||||||
echo match ($type) {
|
|
||||||
'error' => "\033[31m$str \033[0m\n",
|
|
||||||
'success' => "\033[32m$str \033[0m\n",
|
|
||||||
'warning' => "\033[33m$str \033[0m\n",
|
|
||||||
'info' => "\033[36m$str \033[0m\n",
|
|
||||||
'debug' => "\033[90m$str \033[0m\n",
|
|
||||||
default => "$str\n",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run process with realtime output
|
|
||||||
*
|
|
||||||
* @param string $cmd
|
|
||||||
* @param string|null $input
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function runProcess(string $cmd, string $input = null): void
|
|
||||||
{
|
|
||||||
$descriptorSpec = [
|
|
||||||
0 => ['pipe', 'r'],
|
|
||||||
1 => ['pipe', 'w'],
|
|
||||||
2 => ['pipe', 'w'],
|
|
||||||
];
|
|
||||||
|
|
||||||
$process = proc_open($cmd, $descriptorSpec, $pipes);
|
|
||||||
|
|
||||||
if (!is_resource($process)) {
|
|
||||||
out('- Could not start subprocess', 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write input if provided
|
|
||||||
if ($input !== null) {
|
|
||||||
fwrite($pipes[0], $input);
|
|
||||||
fclose($pipes[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read and print output in real-time
|
|
||||||
while (!feof($pipes[1])) {
|
|
||||||
echo stream_get_contents($pipes[1], 1);
|
|
||||||
flush(); // Flush output buffer for immediate display
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read and print error output
|
|
||||||
while (!feof($pipes[2])) {
|
|
||||||
echo stream_get_contents($pipes[2], 1);
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($pipes[1]);
|
|
||||||
fclose($pipes[2]);
|
|
||||||
|
|
||||||
proc_close($process);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove directory recursively
|
|
||||||
*
|
|
||||||
* @param string $dir
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function rmdir_rec(string $dir): void
|
|
||||||
{
|
|
||||||
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
|
||||||
$files = new RecursiveIteratorIterator($it,
|
|
||||||
RecursiveIteratorIterator::CHILD_FIRST);
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file->isDir()) {
|
|
||||||
rmdir($file->getPathname());
|
|
||||||
} else {
|
|
||||||
unlink($file->getPathname());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rmdir($dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setting permissions recursively
|
|
||||||
*
|
|
||||||
* @param string $dir
|
|
||||||
* @param int $dirPermissions
|
|
||||||
* @param int $filePermissions
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function chmod_r(string $dir, int $dirPermissions, int $filePermissions): void
|
|
||||||
{
|
|
||||||
$dp = opendir($dir);
|
|
||||||
while ($file = readdir($dp)) {
|
|
||||||
if (($file == '.') || ($file == '..')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fullPath = realpath($dir . '/' . $file);
|
|
||||||
if (is_dir($fullPath)) {
|
|
||||||
out("- Directory: $fullPath");
|
|
||||||
chmod($fullPath, $dirPermissions);
|
|
||||||
chmod_r($fullPath, $dirPermissions, $filePermissions);
|
|
||||||
} elseif (is_file($fullPath)) {
|
|
||||||
// out("- File: $fullPath");
|
|
||||||
chmod($fullPath, $filePermissions);
|
|
||||||
} else {
|
|
||||||
out("- Cannot find target path: $fullPath", 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir($dp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Welcoming message
|
// Welcoming message
|
||||||
out("--- TorrentPier Installer ---\n", 'info');
|
out("--- TorrentPier Installer ---\n", 'info');
|
||||||
|
|
||||||
|
|
172
library/includes/functions_cli.php
Normal file
172
library/includes/functions_cli.php
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2005-2025 TorrentPier (https://torrentpier.com)
|
||||||
|
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||||
|
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('BB_ROOT')) {
|
||||||
|
die(basename(__FILE__));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove target file
|
||||||
|
*
|
||||||
|
* @param string $file Path to file
|
||||||
|
*/
|
||||||
|
function removeFile(string $file): void
|
||||||
|
{
|
||||||
|
if (unlink($file)) {
|
||||||
|
echo "- File removed: $file" . PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo "- File cannot be removed: $file" . PHP_EOL;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove folder (recursively)
|
||||||
|
*
|
||||||
|
* @param string $dir Path to folder
|
||||||
|
*/
|
||||||
|
function removeDir(string $dir): void
|
||||||
|
{
|
||||||
|
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
||||||
|
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if ($file->isDir()) {
|
||||||
|
removeDir($file->getPathname());
|
||||||
|
} else {
|
||||||
|
removeFile($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rmdir($dir)) {
|
||||||
|
echo "- Folder removed: $dir" . PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo "- Folder cannot be removed: $dir" . PHP_EOL;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Colored console output
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* @param string $type
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function out(string $str, string $type = ''): void
|
||||||
|
{
|
||||||
|
echo match ($type) {
|
||||||
|
'error' => "\033[31m$str \033[0m\n",
|
||||||
|
'success' => "\033[32m$str \033[0m\n",
|
||||||
|
'warning' => "\033[33m$str \033[0m\n",
|
||||||
|
'info' => "\033[36m$str \033[0m\n",
|
||||||
|
'debug' => "\033[90m$str \033[0m\n",
|
||||||
|
default => "$str\n",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run process with realtime output
|
||||||
|
*
|
||||||
|
* @param string $cmd
|
||||||
|
* @param string|null $input
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function runProcess(string $cmd, string $input = null): void
|
||||||
|
{
|
||||||
|
$descriptorSpec = [
|
||||||
|
0 => ['pipe', 'r'],
|
||||||
|
1 => ['pipe', 'w'],
|
||||||
|
2 => ['pipe', 'w'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$process = proc_open($cmd, $descriptorSpec, $pipes);
|
||||||
|
|
||||||
|
if (!is_resource($process)) {
|
||||||
|
out('- Could not start subprocess', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write input if provided
|
||||||
|
if ($input !== null) {
|
||||||
|
fwrite($pipes[0], $input);
|
||||||
|
fclose($pipes[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read and print output in real-time
|
||||||
|
while (!feof($pipes[1])) {
|
||||||
|
echo stream_get_contents($pipes[1], 1);
|
||||||
|
flush(); // Flush output buffer for immediate display
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read and print error output
|
||||||
|
while (!feof($pipes[2])) {
|
||||||
|
echo stream_get_contents($pipes[2], 1);
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($pipes[1]);
|
||||||
|
fclose($pipes[2]);
|
||||||
|
|
||||||
|
proc_close($process);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove directory recursively
|
||||||
|
*
|
||||||
|
* @param string $dir
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function rmdir_rec(string $dir): void
|
||||||
|
{
|
||||||
|
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
||||||
|
$files = new RecursiveIteratorIterator($it,
|
||||||
|
RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if ($file->isDir()) {
|
||||||
|
rmdir($file->getPathname());
|
||||||
|
} else {
|
||||||
|
unlink($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rmdir($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting permissions recursively
|
||||||
|
*
|
||||||
|
* @param string $dir
|
||||||
|
* @param int $dirPermissions
|
||||||
|
* @param int $filePermissions
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function chmod_r(string $dir, int $dirPermissions, int $filePermissions): void
|
||||||
|
{
|
||||||
|
$dp = opendir($dir);
|
||||||
|
while ($file = readdir($dp)) {
|
||||||
|
if (($file == '.') || ($file == '..')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fullPath = realpath($dir . '/' . $file);
|
||||||
|
if (is_dir($fullPath)) {
|
||||||
|
out("- Directory: $fullPath");
|
||||||
|
chmod($fullPath, $dirPermissions);
|
||||||
|
chmod_r($fullPath, $dirPermissions, $filePermissions);
|
||||||
|
} elseif (is_file($fullPath)) {
|
||||||
|
// out("- File: $fullPath");
|
||||||
|
chmod($fullPath, $filePermissions);
|
||||||
|
} else {
|
||||||
|
out("- Cannot find target path: $fullPath", 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir($dp);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue