/** * build source package with more simple form of install. * @param array $options */ function cos_build_simple($options = null) { $dir = getcwd(); $name = basename($dir); if (file_exists("./build/{$name}")) { common::execCommand("sudo rm -rf ./build/{$name}*"); } common::execCommand("mkdir ./build/{$name}"); $htdocs = "cp -rf htdocs/* ./build/{$name}"; common::execCommand($htdocs); $domain = conf::getMainIni('domain'); if (!$domain) { $domain = 'default'; } $files_rm = "sudo rm -rf ./build/{$name}/files/{$domain}/*"; common::execCommand($files_rm); $config = "mkdir ./build/{$name}/config"; common::execCommand($config); $tmp_dir = "mkdir ./build/{$name}/tmp"; common::execCommand($tmp_dir); $profiles = "cp -rf profiles ./build/{$name}"; common::execCommand($profiles); $sql_scripts = "cp -rf scripts ./build/{$name}"; common::execCommand($sql_scripts); $cli = "cp -rf coscli.sh ./build/{$name}"; common::execCommand($cli); $composer = "cp -rf composer.json ./build/{$name}"; common::execCommand($composer); // reset database password $ary = conf::getIniFileArray("./config/config.ini"); $profile = new profile(); $ary = $profile->iniArrayPrepare($ary); // clean ini settings for secrets $ini_settings = conf::arrayToIniFile($ary); // add ini dist file file_put_contents("./build/{$name}/config/config.ini-dist", $ini_settings); $index = "cp -rf htdocs/index.php ./build/{$name}/index.php"; common::execCommand($index); $phar_cli = "cp -rf phar-cli.php ./build/{$name}/"; common::execCommand($phar_cli); $phar_web = "cp -rf phar-web.php ./build/{$name}/"; common::execCommand($phar_web); $module_dir = conf::pathModules(); $modules = "cp -rf {$module_dir} ./build/{$name}"; common::execCommand($modules); $vendor = "cp -rf vendor ./build/{$name}"; common::execCommand($vendor); $rm_git = "rm `find ./build/{$name} -name '.git'` -rf"; common::execCommand($rm_git); $rm_ignore = "rm `find ./build/{$name} -name '.gitignore'` -rf"; common::execCommand($rm_ignore); $rm_doc = "rm -rf ./build/vendor/doc"; common::execCommand($rm_doc); $output = array(); exec('git tag -l', $output); $version = array_pop($output); $command = "cd ./build && tar -Pczf {$name}-{$version}.tar.gz {$name} "; common::execCommand($command); }
function cos_phar_web_create() { // move sources to build dir. // e.g. build/coscms cos_build_simple(); // some base values $dir = getcwd(); $base = basename($dir); // dir we build phar from $build_from_dir = "{$dir}/build/{$base}"; // when creating a web phar we add // config.ini // this is done so that on first exectution of the // phar archive we will create this file and a .sqlite database. $build_phar_dir = "build/phar"; if (!file_exists($build_phar_dir)) { common::execCommand("mkdir {$build_phar_dir}"); } // hidden .config file // cos_exec("cp -f config/config.ini $build_from_dir/tmp/.config.ini"); // reset database password $ary = conf::getIniFileArray("./config/config.ini"); $profile = new profile(); // rm secrets $ary = $profile->iniArrayPrepare($ary); // add sqlite database to build phar dir if (conf::getMainIni('phar_sqlite')) { db_to_sqlite(); // mv sqlite database into hidden file common::execCommand("cp -R sqlite/database.sql {$build_from_dir}/tmp/.database.sql"); common::execCommand("chmod 777 {$build_from_dir}/tmp/.database.sql"); common::execCommand("mkdir {$build_from_dir}/sqlite"); unset($ary['db_init']); $ary['url'] = 'sqlite:.database.sql'; } // no caching of assets. Place css and js in file $ary['cached_assets'] = 0; $ary['cashed_assets_reload'] = 0; $ary['cached_assets_minify'] = 0; $ary['cached_assets_compress'] = 0; $ary['cached_assets_inline'] = 1; if (conf::getMainIni('phar_files')) { common::execCommand("cp -rf htdocs/files {$build_from_dir}"); common::execCommand("sudo chown -R 777 {$build_from_dir}/files"); } $ini_settings = conf::arrayToIniFile($ary); file_put_contents("{$build_from_dir}/tmp/.config.ini", $ini_settings); chdir($build_phar_dir); $output = "{$base}-web.phar"; $phar = new Phar($output); $phar->buildFromDirectory($build_from_dir); $stub = $phar->createDefaultStub('phar-web.php', 'phar-web.php'); $phar->setStub($stub); $phar->stopBuffering(); echo "Web phar executable file created from current source ({$output})\n"; echo "Serve it e.g. with the built-in server. Like this:\n"; echo "cd {$build_phar_dir}\n"; echo "php -S localhost:8080 {$base}-web.phar\n"; exit(0); }