Make sudo calls cross platform

This commit is contained in:
Manuel Thalmann 2024-09-28 03:40:45 +02:00
parent f5a1b0cb86
commit af57949bf5

View file

@ -68,7 +68,6 @@ $null = New-Module {
if ($IsWindows) {
$env:WSLENV = "CONFIG_NAME";
New-Alias -Force "sudo" gsudo;
Backup-PowerScheme;
}
@ -164,6 +163,33 @@ $null = New-Module {
continue;
}
function global:Invoke-Sudo {
param(
$u,
[Parameter(ValueFromRemainingArguments, Position = 0)]
[string[]] $ArgumentList
)
$params = @();
if ($u) {
$params = @("-u", $u);
}
elseif ($ArgumentList[0] -eq "-u") {
$user = $ArgumentList[1];
$ArgumentList = $ArgumentList | Select-Object -Skip 2;
$params = @("-u", $user);
}
gsudo @params {
$command = $args[0];
$flags = ($args | Select-Object -Skip 1);
& $command @flags;
} -args $ArgumentList
}
New-Alias -Force "sudo" -Scope Global Invoke-Sudo;
if ($env:DEBUG) {
& {
$sys32 = "$env:WINDIR/System32";