Updated autloader generation process

This commit is contained in:
Netkas 2022-08-11 14:04:33 -04:00
parent e52a05bc8f
commit 8f32ad0076
12 changed files with 297 additions and 162 deletions

View file

@ -0,0 +1,60 @@
<?php
// Check for NCC
if(!file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php'))
{
print('Could not find \'autoload.php\', this script is intended to be executed during the redistribution process');
exit(1);
}
require(__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php');
// Start script
function scanContents($dir, &$results = array())
{
$files = scandir($dir);
foreach ($files as $key => $value)
{
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (!is_dir($path))
{
$results[] = str_ireplace(__DIR__ . DIRECTORY_SEPARATOR, (string)null, $path);
}
else if ($value != '.' && $value != '..')
{
$results[] = str_ireplace(__DIR__ . DIRECTORY_SEPARATOR, (string)null, $path);
scanContents($path, $results);
}
}
return $results;
}
$excluded_files = [
'hash_check.php',
'generate_build_files.php',
'installer',
'checksum.bin'.
'build_files'
];
ncc\Utilities\Console::out('Creating build_files ...');
if(file_exists('build_files'))
{
unlink('build_files');
}
$build_files_content = [];
foreach(scanContents(__DIR__) as $path)
{
if(!in_array($path, $excluded_files))
{
$build_files_content[] = $path;
}
}
$build_files = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'build_files', 'a+');
fwrite($build_files, implode("\n", $build_files_content));
fclose($build_files);
ncc\Utilities\Console::out('Created build_files');
exit(0);

View file

@ -33,7 +33,9 @@
$excluded_files = [
'hash_check.php',
'checksum.bin'
'generate_build_files.php',
'checksum.bin',
'build_files'
];
$hash_values = [];

View file

@ -11,12 +11,16 @@
# ------------------------------------------------------------------
<?PHP
// TODO: Check for root before proceeding
# Global Variables
$NCC_INSTALL_PATH='/etc/ncc';
$NCC_INSTALL_PATH='/etc/ncc-lib';
$NCC_DATA_PATH='/etc/ncc';
$NCC_UPDATE_SOURCE='https://updates.nosial.com/ncc/check_updates?current_version=$VERSION'; # Unused
$NCC_CHECKSUM=__DIR__ . DIRECTORY_SEPARATOR . 'checksum.bin';
$NCC_AUTOLOAD=__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
// Require NCC
if(!file_exists($NCC_AUTOLOAD))
{
print('The file \'autoload.php\' was not found, installation cannot proceed.' . PHP_EOL);
@ -24,6 +28,20 @@
}
require($NCC_AUTOLOAD);
// Check for the required files
$required_files = [
'LICENSE',
'build_files'
];
foreach($required_files as $file)
{
if(!file_exists($file))
{
\ncc\Utilities\Console::outError('Missing file \'' . $file . '\', installation failed.', true, 1);
}
}
// Preform the checksum validation
if(!file_exists($NCC_CHECKSUM))
{
\ncc\Utilities\Console::outWarning('The file \'checksum.bin\' was not found, the contents of the program cannot be verified to be safe');
@ -37,7 +55,12 @@
foreach($checksum as $file => $hash)
{
if(hash_file('sha256', __DIR__ . DIRECTORY_SEPARATOR . $file) !== $hash)
if(file_exists(__DIR__ . DIRECTORY_SEPARATOR . $file) == false)
{
\ncc\Utilities\Console::outError('Cannot check file, \'' . $file . '\' not found.');
$checksum_failed = true;
}
elseif(hash_file('sha256', __DIR__ . DIRECTORY_SEPARATOR . $file) !== $hash)
{
\ncc\Utilities\Console::outWarning('The file \'' . $file . '\' does not match the original checksum');
$checksum_failed = true;
@ -55,6 +78,62 @@
}
}
// Check for required extensions
foreach(\ncc\Utilities\Validate::requiredExtensions() as $ext => $installed)
{
if(!$installed)
{
\ncc\Utilities\Console::outWarning('The extension \'' . $ext . '\' is not installed, compatibility without it is not guaranteed');
}
}
// Start of installer
\ncc\Utilities\Console::out('Started NCC installer');
// Determine the installation path
// TODO: Add the ability to change the data path as well
while(true)
{
$user_input = null;
$user_input = \ncc\Utilities\Console::getInput("Installation Path (Default: $NCC_INSTALL_PATH): ");
if(strlen($user_input) > 0)
{
if(file_exists($user_input))
{
if(file_exists($user_input . DIRECTORY_SEPARATOR . 'ncc'))
{
\ncc\Utilities\Console::out('NCC Seems to already be installed, the installer will repair/upgrade your current install');
break;
}
else
{
\ncc\Utilities\Console::outError('The given directory already exists, it must be deleted before proceeding');
}
}
else
{
break;
}
}
else
{
break;
}
}
\ncc\Utilities\Console::out("Note: This doesn't affect your current install of composer (if you have composer installed)");
$update_composer = \ncc\Utilities\Console::getBooleanInput('Do you want to install composer for NCC? (Recommended)');
// Prepare installation
if(file_exists($NCC_INSTALL_PATH))
{
// TODO: Implement recursive directory removal
}
mkdir($NCC_INSTALL_PATH);
mkdir($NCC_DATA_PATH);
// Install composer
// Install NCC
?>

1
src/installer/ncc.sh Executable file
View file

@ -0,0 +1 @@
php ncc --ncc-cli "$@"