Skip to content
Snippets Groups Projects
Select Git revision
  • f93f964e4ed56abeb4c7bf7cc31aec49cbd52bfc
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

autodetect-os

Blame
  • installer.php 4.76 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$myosextension";
    $doneBuild="__done_build-micro__.txt";
    $incfile="$selfdir/src/include_checks.php";
    
    /*
    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   *   U P D A T E R
    
        - gets appmonitor sources or updates it
        - gets spc binary
        - spc downloads PHP and libs
        - spc builds micro
    
    ";
    
    // ----------------------------------------------------------------------
    
    if ($argc > 1) {
        parse_str(implode('&', array_slice($argv, 1)), $ARGS);
    }
    
    if(isset($ARGS['-h']) || isset($ARGS['--help'])){
        echo "
        HELP
    
        -h, --help     Show this help
        -r, --reset    Reset; delete created folders of installer or build
    
    ";
        exit(0);
    }
    
    _chdir($selfdir);
    
    if(isset($ARGS['-r']) || isset($ARGS['--reset'])){
        _h1("Reset data");
        _rm($dirBuild);
        _rm($dirExternal);
        _rm($dirPackages);
        _rm($incfile);
    }
    
    // ----------------------------------------------------------------------
    _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");
    
    _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");
    
    $bDoBild=true;
    $sDoneData="PHP version $php_version\nExtensions: $php_libs";
    if(file_exists($doneBuild)){
    
        $sDone=file_get_contents($doneBuild);
        if (strstr($sDone, $sDoneData)>=0){
            $bDoBild=false;
        }
    }
    
    if ($bDoBild){    
        _exec("$SPC --no-interaction doctor");
    
        echo "💡 Hint: this can take a minute on a fresh install ...\n";
        _exec($cmdSpcDownload);
    
        echo "💡 Hint: this can take 4 minutes on a fresh install or less on module changes ...\n";
        _exec($cmdSpcBuild);
        file_put_contents("$doneBuild", date("Y-m-d H:i:s") . "\n$sDoneData\n");
    } else {
        _skip("Micro already built - php $php_version - extensions \"$php_libs\"");
    }
    
    _h1("Done.");