Added installer script (Unfinished)

This commit is contained in:
Netkas 2022-08-05 18:41:35 -04:00
parent 89d50dac6d
commit e52a05bc8f
3 changed files with 103 additions and 7 deletions

View file

@ -5,9 +5,11 @@ redist:
rm -rf build
mkdir build build/src
cp -rf src/ncc/* build/src
cp src/installer/installer build/src/install.sh
cp src/installer/installer build/src/install
chmod +x build/src/install
cp LICENSE build/src/LICENSE
cp README.md build/src/README.md
cp src/installer/hash_check.php build/src/hash_check.php; php build/src/hash_check.php; rm build/src/hash_check.php
tar:
rm -f build/ncc.tar.gz

View file

@ -0,0 +1,51 @@
<?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 != '..')
{
scanContents($path, $results);
}
}
return $results;
}
ncc\Utilities\Console::out('Creating checksum.bin ...');
$excluded_files = [
'hash_check.php',
'checksum.bin'
];
$hash_values = [];
foreach(scanContents(__DIR__) as $file)
{
if(!in_array($file, $excluded_files))
{
$hash_values[$file] = hash_file('sha256', __DIR__ . DIRECTORY_SEPARATOR . $file);
}
}
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'checksum.bin', \ncc\ZiProto\ZiProto::encode($hash_values));
ncc\Utilities\Console::out('Created checksum.bin');
exit(0);

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/php
# ------------------------------------------------------------------
# Nosial Code Compiler (NCC) Installation Script
@ -10,8 +10,51 @@
# PHP 8.0+
# ------------------------------------------------------------------
$NCC_INSTALL_PATH='/etc/ncc'
$NCC_SOURCE_PATH='src/ncc'
$NCC_VERSION_NUMBER='1.0.0'
$NCC_UPDATE_SOURCE='https://updates.nosial.com/ncc/check_updates?current_version=$VERSION'
$NCC_CREATE_SYSTEM='True'
<?PHP
# Global Variables
$NCC_INSTALL_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';
if(!file_exists($NCC_AUTOLOAD))
{
print('The file \'autoload.php\' was not found, installation cannot proceed.' . PHP_EOL);
exit(1);
}
require($NCC_AUTOLOAD);
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');
}
else
{
\ncc\Utilities\Console::out('Running checksum');
$checksum = \ncc\ZiProto\ZiProto::decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'checksum.bin'));
$checksum_failed = false;
foreach($checksum as $file => $hash)
{
if(hash_file('sha256', __DIR__ . DIRECTORY_SEPARATOR . $file) !== $hash)
{
\ncc\Utilities\Console::outWarning('The file \'' . $file . '\' does not match the original checksum');
$checksum_failed = true;
}
}
if($checksum_failed)
{
\ncc\Utilities\Console::outError('Checksum failed, the contents of the program cannot be verified to be safe');
exit(1);
}
else
{
\ncc\Utilities\Console::out('Checksum passed');
}
}
\ncc\Utilities\Console::out('Started NCC installer');
?>