diff --git a/Makefile b/Makefile index 87d9269..bad0bd8 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/installer/hash_check.php b/src/installer/hash_check.php new file mode 100644 index 0000000..5cc03ef --- /dev/null +++ b/src/installer/hash_check.php @@ -0,0 +1,51 @@ + $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); \ No newline at end of file diff --git a/src/installer/installer b/src/installer/installer index 391109f..3035242 100644 --- a/src/installer/installer +++ b/src/installer/installer @@ -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' + $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'); +?> \ No newline at end of file