Select Git revision
inc_functions.php
-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
inc_functions.php 1.22 KiB
<?php
// ----------------------------------------------------------------------
// SHARED FUNCTIONS FOR INSTALLER AND BUILDER
// ----------------------------------------------------------------------
function _h1($s): void
{
echo "\n>>>>>>>>>> $s\n";
}
function _abort($sMessage, $iExitcode = 1): never
{
echo "❌ $sMessage.\n";
exit($iExitcode);
}
function _chdir($sDir): void
{
if (!is_dir($sDir)) {
_abort("Directory '$sDir' not found.");
}
chdir($sDir);
echo "dir # " . getcwd() . "\n";
}
/**
* Execute shell command and abort if it fails
* @param mixed $cmd
* @return void
*/
function _exec($cmd): void
{
echo "cmd > $cmd\n";
exec("$cmd 2>&1", $aOut, $rc);
if(!count($aOut)) {
$aOut=["-- no output --"];
}
echo implode("\n", $aOut)."\n";
if ($rc != 0) {
echo "rc=$rc ";
_abort("Error: Command failed. Aborting.", $rc);
}
echo "✅ OK\n";
}
function _mkdir(string $sMyDir): void
{
if (!is_dir($sMyDir)) {
echo "DIR > '$sMyDir' ";
if (!mkdir($sMyDir, 0755, true)) {
_abort("ERROR: mkdir failed.");
}
echo "✅ OK\n\n";
} else {
echo "⏩ SKIP mkdir: already exists: '$sMyDir'\n";
}
}