Compare commits
No commits in common. "master" and "v0.0.4" have entirely different histories.
|
@ -1,5 +0,0 @@
|
||||||
## v0.0.7
|
|
||||||
- Setting proper PATH when checking for dotnet during composer post-install step
|
|
||||||
|
|
||||||
## v0.0.6
|
|
||||||
- Initial working version
|
|
|
@ -6,6 +6,6 @@
|
||||||
"php": ">=8.3"
|
"php": ">=8.3"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": ["support.inc.php", "dotnet.inc.php"]
|
"classmap": ["dotnet.inc.php"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
namespace taskman;
|
namespace taskman;
|
||||||
use Exception;
|
|
||||||
|
class DotnetSupport
|
||||||
|
{
|
||||||
|
static function install()
|
||||||
|
{
|
||||||
|
dotnet_install("8.0.0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
task('dotnet_set_env', ['always' => true], function() {
|
task('dotnet_set_env', ['always' => true], function() {
|
||||||
dotnet_set_env();
|
dotnet_set_env();
|
||||||
});
|
});
|
||||||
|
|
||||||
task('dotnet_install', function(array $args) {
|
task('dotnet_install', function() {
|
||||||
DotnetSupport::installEx(isset($args[0]) && $args[0] === '--force');
|
DotnetSupport::install();
|
||||||
});
|
});
|
||||||
|
|
||||||
function dotnet_shell($cmd)
|
function dotnet_shell($cmd)
|
||||||
|
@ -20,10 +27,65 @@ function dotnet_shell_get($cmd)
|
||||||
return shell_get('dotnet ' . $cmd);
|
return shell_get('dotnet ' . $cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dotnet_install(string $version)
|
||||||
|
{
|
||||||
|
$has_dotnet = true;
|
||||||
|
|
||||||
|
$dotnet_curr_ver = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$dotnet_curr_ver = shell_get("dotnet --version");
|
||||||
|
print("DOTNET CURRENT VERSION: $dotnet_curr_ver\n");
|
||||||
|
}
|
||||||
|
catch(\Throwable $th)
|
||||||
|
{
|
||||||
|
$has_dotnet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
print("DOTNET VERSION MISMATCH: $dotnet_curr_ver < $version\n");
|
||||||
|
|
||||||
|
$install_file_path = dotnet_get_installer_path();
|
||||||
|
|
||||||
|
$version_parts = explode('.', $version);
|
||||||
|
$channel = $version_parts[0].'.'.$version_parts[1];
|
||||||
|
if(is_win())
|
||||||
|
shell("powershell -NoProfile -ExecutionPolicy unrestricted Invoke-Expression '\"$install_file_path\" -Channel $channel'");
|
||||||
|
else
|
||||||
|
shell("\"$install_file_path\" --channel $channel");
|
||||||
|
}
|
||||||
|
|
||||||
function dotnet_set_env()
|
function dotnet_set_env()
|
||||||
{
|
{
|
||||||
//TODO: do we need this one?
|
|
||||||
putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1");
|
putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1");
|
||||||
|
|
||||||
DotnetSupport::addEnvPath();
|
$dotnet_path = dotnet_get_path();
|
||||||
|
if(is_win())
|
||||||
|
putenv("PATH=$dotnet_path;".getenv('PATH'));
|
||||||
|
else
|
||||||
|
putenv("PATH=$dotnet_path:".getenv('PATH'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dotnet_get_path()
|
||||||
|
{
|
||||||
|
if(is_win())
|
||||||
|
{
|
||||||
|
$appdata_path = getenv('LOCALAPPDATA');
|
||||||
|
return "$appdata_path\\Microsoft\\dotnet\\";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return getenv("HOME")."/.dotnet/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function dotnet_get_installer_path() : string
|
||||||
|
{
|
||||||
|
if(is_win())
|
||||||
|
return __DIR__ . "/dotnet-install.ps1";
|
||||||
|
else
|
||||||
|
return __DIR__ . "/dotnet-install.sh";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
121
support.inc.php
121
support.inc.php
|
@ -1,121 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace taskman;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
//NOTE: this class must not have any dependencies on any packages
|
|
||||||
class DotnetSupport
|
|
||||||
{
|
|
||||||
const VERSION = "8.0.0";
|
|
||||||
|
|
||||||
//NOTE: this is a composer event, it doesn't accept any arguments
|
|
||||||
static function install()
|
|
||||||
{
|
|
||||||
self::installEx(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
static function installEx(bool $force = false)
|
|
||||||
{
|
|
||||||
$version = self::VERSION;
|
|
||||||
|
|
||||||
$dotnet_curr_ver = "";
|
|
||||||
//let's add to PATH
|
|
||||||
$prev_path = self::addEnvPath();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$dotnet_curr_ver = self::shellGet("dotnet --version");
|
|
||||||
print("DOTNET CURRENT VERSION: $dotnet_curr_ver\n");
|
|
||||||
}
|
|
||||||
catch(\Throwable $th)
|
|
||||||
{
|
|
||||||
$force = true;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
//let's restore prev PATH
|
|
||||||
self::setEnvPath($prev_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$force)
|
|
||||||
{
|
|
||||||
$dotnet_ver_items = explode('.', $dotnet_curr_ver);
|
|
||||||
$target_ver_items = explode('.', $version);
|
|
||||||
//let's force install if current major version is not equal
|
|
||||||
$force = isset($dotnet_ver_items[0]) && $dotnet_ver_items[0] !== $target_ver_items[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$force)
|
|
||||||
return;
|
|
||||||
|
|
||||||
print("DOTNET VERSION MISMATCH: $dotnet_curr_ver is not compatible with $version\n");
|
|
||||||
|
|
||||||
$install_file_path = self::getInstallerPath();
|
|
||||||
|
|
||||||
$version_parts = explode('.', $version);
|
|
||||||
$channel = $version_parts[0].'.'.$version_parts[1];
|
|
||||||
if(self::isWin())
|
|
||||||
self::shell("powershell -NoProfile -ExecutionPolicy unrestricted Invoke-Expression '\"$install_file_path\" -Channel $channel'");
|
|
||||||
else
|
|
||||||
self::shell("\"$install_file_path\" --channel $channel");
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getInstallerPath() : string
|
|
||||||
{
|
|
||||||
if(self::isWin())
|
|
||||||
return __DIR__ . "/dotnet-install.ps1";
|
|
||||||
else
|
|
||||||
return __DIR__ . "/dotnet-install.sh";
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getPath() : string
|
|
||||||
{
|
|
||||||
if(self::isWin())
|
|
||||||
{
|
|
||||||
$appdata_path = getenv('LOCALAPPDATA');
|
|
||||||
return "$appdata_path\\Microsoft\\dotnet\\";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return getenv("HOME")."/.dotnet/";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function addEnvPath(string $path = '') : string
|
|
||||||
{
|
|
||||||
$prev_path = getenv('PATH');
|
|
||||||
|
|
||||||
if(!$path)
|
|
||||||
$path = DotnetSupport::getPath();
|
|
||||||
|
|
||||||
if(self::isWin())
|
|
||||||
self::setEnvPath("$path;$prev_path");
|
|
||||||
else
|
|
||||||
self::setEnvPath("$path:$prev_path");
|
|
||||||
|
|
||||||
return $prev_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function setEnvPath(string $path)
|
|
||||||
{
|
|
||||||
putenv("PATH=$path");
|
|
||||||
}
|
|
||||||
|
|
||||||
static function isWin() : bool
|
|
||||||
{
|
|
||||||
return !(DIRECTORY_SEPARATOR == '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
static function shellGet(string $cmd, bool $as_string = true)
|
|
||||||
{
|
|
||||||
exec($cmd, $out, $code);
|
|
||||||
if($code !== 0)
|
|
||||||
throw new Exception("Error($code) executing shell cmd '$cmd'");
|
|
||||||
return $as_string ? implode("", $out) : $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function shell(string $cmd)
|
|
||||||
{
|
|
||||||
system($cmd, $ret);
|
|
||||||
if($ret != 0)
|
|
||||||
throw new Exception("Shell execution error(exit code $ret)");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue