Make scripts platform independent

This commit is contained in:
Manuel Thalmann 2024-08-23 01:52:04 +02:00
parent c56af0e6ca
commit 38c3c84ba4
2 changed files with 26 additions and 18 deletions

View file

@ -109,25 +109,33 @@ $null = New-Module {
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish"; $scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
if (-not $IsWindows) { if ($env:CONFIG_MODULE) {
$escapedPath = (fish -c 'string escape $argv' "$scriptPath"); $output = & {
fish -c ". $escapedPath; $Script"; if (-not $IsWindows) {
} else { $escapedPath = (fish -c 'string escape $argv' "$scriptPath");
function fish { fish -c ". $escapedPath; $Script";
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args
}
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
if (-not $?) {
Write-Error "The configuration could not be retrieved!";
} else {
if (-not ($output | Test-Json)) {
Write-Error "The value ``$output`` is not valid JSON.";
} else { } else {
$output | ConvertFrom-Json; function fish {
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args
}
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
if (-not $?) {
Write-Error "The configuration could not be retrieved!";
} else {
$output;
}
} }
} }
if (-not ($output | Test-Json)) {
Write-Error "The value ``$output`` is not valid JSON.";
} else {
$output | ConvertFrom-Json;
}
} else {
$null;
} }
} }
@ -408,7 +416,7 @@ $null = New-Module {
Checks whether the current user is the setup user. Checks whether the current user is the setup user.
#> #>
function Test-SetupUser { function Test-SetupUser {
$env:UserName -eq (Get-Config "valhalla.windows.setupUser"); ($IsWindows ? $env:UserName : $env:USER) -eq (Get-Config "valhalla.windows.setupUser");
} }
<# <#

View file

@ -255,7 +255,7 @@ $null = New-Module {
} }
} elseif ($Action -eq ([InstallerAction]::ConfigureUser)) { } elseif ($Action -eq ([InstallerAction]::ConfigureUser)) {
if ((-not $Arguments.ContainsKey($userArgument)) -or (-not $Arguments[$userArgument])) { if ((-not $Arguments.ContainsKey($userArgument)) -or (-not $Arguments[$userArgument])) {
$Arguments.Add($userArgument, ($env:UserName)); $Arguments.Add($userArgument, ($IsWindows ? $env:UserName : $env:USER));
} }
if ($UserConfigurator) { if ($UserConfigurator) {