Server/build/build-phar.php

86 lines
2.4 KiB
PHP
Raw Normal View History

2024-01-31 13:32:14 +00:00
<?php
2024-03-14 14:51:49 +00:00
2024-01-31 13:32:14 +00:00
function builderLog(string $message){
echo(date("Y-m-d h:m", time())." ".$message."\n");
}
echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
echo "[LonaDB Phar compiler]\n";
$config = json_decode(file_get_contents("build_config.json"));
$path = $config->{"path"};
$filename = $config->{"filename"};
$version = $config->{"version"};
$branch = "debug";
if($config->{"debug"}) {
$path = $path."/debug";
$debug = "True";
}
2024-01-31 13:32:14 +00:00
else {
$debug = "False";
2024-01-31 13:32:14 +00:00
$path = $path."/release";
$branch = "release";
}
echo "[CONF] Debug=".$debug."\n";
2024-01-31 13:32:14 +00:00
echo "[CONF] Path=".$path."\n";
echo "[CONF] Filename=".$filename."\n";
echo "[CONF] Version=".$version."\n";
echo "\nBuild? (Y/n)\n";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim(strtolower($line)) === 'no' || trim(strtolower($line)) === "n"){
echo "ABORTING!\n";
exit;
}
$start = time();
builderLog("[COMPOSER] Running 'composer install'");
2024-02-02 23:59:53 +00:00
exec("cd src ; printf '\n' | ./composer.phar install");
2024-01-31 13:32:14 +00:00
if(file_exists($path."/".$filename."-".$version.".phar")){
unlink($path."/".$filename."-".$version.".phar");
builderLog("[CLEANUP] Deleted an old build");
}
if(file_exists("build/run-phar.sh")){
unlink(__DIR__."/run-phar.sh");
builderLog("[CLEANUP] Deleted an old runner");
}
try {
builderLog("[BUILD] Creating a new Phar object");
$phar = new Phar($path."/".$filename."-".$version.".phar", 0, $path."/".$filename."-".$version.".phar");
builderLog("[BUILD] Adding files to the Phar archive");
$phar->buildFromDirectory(__DIR__ . '/../src');
2024-03-14 14:51:49 +00:00
builderLog("[BUILD] Set default stub file");
2024-01-31 13:32:14 +00:00
$phar->setDefaultStub('LonaDB/LonaDB.php', 'LonaDB/LonaBD.php');
2024-03-14 14:51:49 +00:00
builderLog("[BUILD] Set alias file");
2024-01-31 13:32:14 +00:00
$phar->setAlias($filename."-".$version.".phar");
2024-03-14 14:51:49 +00:00
builderLog("[BUILD] Set signature algorithm");
$phar->setSignatureAlgorithm(Phar::SHA512);
2024-01-31 13:32:14 +00:00
builderLog("[BUILD] Saving the new Phar archive");
$phar->stopBuffering();
builderLog("[INFO] Phar archive created successfully");
builderLog("[RUN] Generating run script");
2024-03-14 14:51:49 +00:00
file_put_contents("./build/run-phar.sh", 'cd '.$path.' ; printf "test\n" | php -dphar.readonly=0 '.$filename.'-'.$version.'.phar');
2024-01-31 13:32:14 +00:00
builderLog("[RUN] Adding Permissions to run script");
exec("chmod 777 ./build/run-phar.sh");
echo "Done!\nBuilt in ".(time() - $start) ." ms!\n";
} catch (Exception $e) {
builderLog('[ERROR] '.$e->getMessage());
}