-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
installer.php 3.99 KiB
#!/bin/env php
<?php
/*
I N S T A L L E R
*/
require("inc_vars.php");
require("inc_functions.php");
$gitAppmonitor="https://github.com/iml-it/appmonitor.git";
$spcUrl="https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-$myos-$myarchitecture";
$doneBuild="__done_build-micro__".md5($php_version.$php_libs).".txt";
/*
Filename Last Modified Size Download Count
spc-linux-aarch64 2025-02-15 17:30:46 3.4M 451
spc-linux-aarch64.tar.gz 2025-02-15 17:30:46 3.3M 54
spc-linux-x86_64 2025-02-15 17:30:46 3.5M 937
spc-linux-x86_64.tar.gz 2025-02-15 17:30:46 3.3M 282
spc-macos-aarch64 2025-02-15 17:31:40 7.8M 669
spc-macos-aarch64.tar.gz 2025-02-15 17:31:38 3.8M 211
spc-macos-x86_64 2025-02-15 17:31:46 7.8M 463
spc-macos-x86_64.tar.gz 2025-02-15 17:31:45 3.9M 89
spc-windows-x64.exe 2025-02-15 17:30:46 3.9M 551
*/
// ----------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------
echo "
I N S T A L L E R
- gets appmonitor sources
- gets spc binary
- spc downloads PHP and libs
- spc builds micro (1..2 min)
";
_chdir($selfdir);
// ----------------------------------------------------------------------
_h1("Create directories");
_mkdir($dirExternal);
_mkdir("$dirExternal/bin");
_mkdir($dirBuild);
// ----------------------------------------------------------------------
_h1("Get / update Appmonitor repo");
_chdir("$selfdir/$dirExternal");
if(!is_dir("appmonitor")){
_exec("git clone $gitAppmonitor");
} else {
_chdir("$selfdir/$dirExternal/appmonitor");
_exec("git pull -f $gitAppmonitor");
}
// ----------------------------------------------------------------------
_h1("Generate include file with all available checks...");
// _exec("ln -s $selfdir/$dirExternal/appmonitor/public_html/client $selfdir/src");
$incfile="$selfdir/src/include_checks.php";
_chdir("$selfdir");
$aFiles2Merge=array_merge(
[
"$dirExternal/appmonitor/public_html/client/classes/appmonitor-checks.class.php",
"$dirExternal/appmonitor/public_html/client/classes/appmonitor-client.class.php",
],
glob("$dirExternal/appmonitor/public_html/client/plugins/checks/*php")
);
$out="<?php
/*
This file was generated by
".__FILE__."
at ".(date("Y-m-d H:i:s"))."
merged files:
".implode("\n ", $aFiles2Merge)."
*/
";
foreach($aFiles2Merge as $sMyFile){
$sSource=file_get_contents($sMyFile);
$sSource=preg_replace(
[
"/(require[\ \_].*;)/",
"/(\<\?php)/"
],
[
"// REMOVED-BY-MERGER: $1",
"",
],
$sSource
);
$out.="$sSource\n";
}
if(file_put_contents($incfile, $out)){
_ok("$incfile was written");
}
_exec("php -l '$incfile'");
// ----------------------------------------------------------------------
_h1("Get / update spc");
_chdir("$selfdir/$dirExternal/bin");
if(!file_exists($SPC)){
_exec("wget -O $SPC '$spcUrl'");
} else {
_skip("download of spc.");
}
if (PHP_OS == "Linux") {
_exec("chmod +x $SPC");
}
// ----------------------------------------------------------------------
_h1("Spc - prepare environment");
_chdir("$selfdir/$dirBuild");
if(!file_exists("$doneBuild")){
_exec("$SPC --no-interaction doctor");
_exec("$SPC download --no-interaction --with-php=$php_version --for-extensions '$php_libs'");
echo "💡 Hint: this can take 2 minutes ...\n";
_exec("$SPC build --no-interaction --build-micro '$php_libs'");
touch("$doneBuild");
} else {
_skip("Micro already built - php $php_version - extensions '$php_libs'");
}
_h1("Done.");