Make all config scripts platform independent

This commit is contained in:
Manuel Thalmann 2024-08-23 01:57:53 +02:00
parent 506786a8ce
commit 87634d394a

View file

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