Make all config scripts platform independent

This commit is contained in:
Manuel Thalmann 2024-08-23 01:57:53 +02:00
parent fc2bf2276c
commit 3aa6967734

View file

@ -156,6 +156,14 @@ $null = New-Module {
Invoke-ConfigScript "getConfig $Name --json $ArgumentList"; Invoke-ConfigScript "getConfig $Name --json $ArgumentList";
} }
<#
.SYNOPSIS
Gets the name of the config root.
#>
function Get-ConfigRootName {
return "valhalla$($IsWindows ? ".windows" : '')";
}
<# <#
.SYNOPSIS .SYNOPSIS
Gets a user configuration. Gets a user configuration.
@ -168,13 +176,13 @@ $null = New-Module {
#> #>
function Get-UserConfig { function Get-UserConfig {
param( param(
[string] $UserName = $env:UserName, [string] $UserName = ($IsWindows ? $env:UserName : $env:USER),
[Parameter(Mandatory, Position = 0)] [Parameter(Mandatory, Position = 0)]
[string] $Name [string] $Name
) )
if ((Get-Users) -contains $UserName) { if ((Get-Users) -contains $UserName) {
Get-Config "valhalla.windows.users.$UserName.$Name"; Get-Config "$(Get-ConfigRootName).users.$UserName.$Name";
} else { } else {
return $null; return $null;
} }
@ -202,7 +210,7 @@ $null = New-Module {
function Get-Users { function Get-Users {
[OutputType([string[]])] [OutputType([string[]])]
param() param()
Get-Attributes "valhalla.windows.users"; Get-Attributes "$(Get-ConfigRootName).users";
} }
<# <#
@ -212,7 +220,7 @@ $null = New-Module {
function Get-SetupUser { function Get-SetupUser {
[OutputType([string])] [OutputType([string])]
param() param()
Get-Config "valhalla.windows.setupUser"; Get-Config "$(Get-ConfigRootName).setupUser";
} }
<# <#
@ -416,7 +424,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 {
($IsWindows ? $env:UserName : $env:USER) -eq (Get-Config "valhalla.windows.setupUser"); ($IsWindows ? $env:UserName : $env:USER) -eq (Get-SetupUser);
} }
<# <#