diff --git a/scripts/Arch/Config/SecureBoot/main.fish b/scripts/Arch/Config/SecureBoot/main.fish index be5c3fcc..9dfc6636 100755 --- a/scripts/Arch/Config/SecureBoot/main.fish +++ b/scripts/Arch/Config/SecureBoot/main.fish @@ -9,8 +9,8 @@ begin function configureSW -V dir source "$dir/../../../Common/Scripts/config.fish" - set -l label (getConfig valhalla.boot.label) - set -l efiDir (getConfig valhalla.boot.efiMountPoint) + set -l label (getOSConfig boot.label) + set -l efiDir (getOSConfig boot.efiMountPoint) set -l bootNums (efibootmgr | sed "/$label/{ s/^.*Boot\([[:digit:]]\+\)\*.*\$/\1/; p; }; d") for bootNum in $bootNums diff --git a/scripts/Arch/OS/setup.fish b/scripts/Arch/OS/setup.fish index 6ba76609..29c53e7b 100755 --- a/scripts/Arch/OS/setup.fish +++ b/scripts/Arch/OS/setup.fish @@ -4,7 +4,7 @@ begin source "$dir/../../Common/OS/setup.fish" source "$dir/../../Common/Scripts/config.fish" - set -l mountDir (getConfig valhalla.partition.rootDir) + set -l mountDir (getOSConfig partition.rootDir) function runChroot -S arch-chroot $argv @@ -15,7 +15,7 @@ begin end function installDrivers -V mountDir - if isEnabled valhalla.linux.hardware.surfaceBook + if isOSEnabled hardware.surfaceBook pacstrap -K "$mountDir" linux-firmware-marvell; end end @@ -33,11 +33,11 @@ begin set -l relativeDir (realpath --relative-to "$dir/../../.." "$dir") set -l tempDir "$PROJECT_CLONE_ROOT/$relativeDir" - if set -l keyMap (getConfig valhalla.keyMap) + if set -l keyMap (getOSConfig keyMap) loadkeys "$keyMap" end - and if set -l timezone (getConfig valhalla.timeZone) + and if set -l timezone (getOSConfig timeZone) timedatectl set-timezone "$timezone" end @@ -63,7 +63,7 @@ begin and arch-chroot "$mountDir" hwclock --systohc and begin - getConfig valhalla.i18n.localeSettings --json | \ + getOSConfig i18n.localeSettings --json | \ jq --raw-output '[.[] | split(".") | .[0]] | unique | join("\\\\|")' end | begin read LOCALES @@ -72,7 +72,7 @@ begin end and begin - getConfig valhalla.i18n.localeSettings --json | \ + getOSConfig i18n.localeSettings --json | \ jq --raw-output '[keys[] as $key | "\($key)=\(.[$key])"] | join("\n")' end | arch-chroot "$mountDir" tee /etc/locale.conf > /dev/null @@ -80,13 +80,13 @@ begin echo "KEYMAP=$keyMap" | arch-chroot "$mountDir" tee /etc/vconsole.conf > /dev/null end - and echo (getConfig valhalla.hostname) | arch-chroot "$mountDir" tee /etc/hostname > /dev/null + and echo (getOSConfig hostname) | arch-chroot "$mountDir" tee /etc/hostname > /dev/null and arch-chroot "$mountDir" mkinitcpio -P and runHook installDrivers "Installing drivers..." || true and runInOS fish "$tempDir/../Software/GRUB/main.fish" - and if set -l keyLayout (getConfig valhalla.keyboardLayout) + and if set -l keyLayout (getOSConfig keyboardLayout) set -l serviceName set-keymap.service and set -l serviceFile "$mountDir/etc/systemd/system/$serviceName" and cp "$dir/$serviceName" "$serviceFile" diff --git a/scripts/Arch/Scripts/deploy.fish b/scripts/Arch/Scripts/deploy.fish index 47e0da7e..bff83e67 100644 --- a/scripts/Arch/Scripts/deploy.fish +++ b/scripts/Arch/Scripts/deploy.fish @@ -14,23 +14,23 @@ function deploySoftware -d "Deploys a the specified software action" -a action end ) - if isEnabled valhalla.linux.secureBoot + if isOSEnabled secureBoot source "$dir/../Config/SecureBoot/main.fish" $argv end - and if isEnabled valhalla.linux.hardware.surfaceBook + and if isOSEnabled hardware.surfaceBook source "$dir/../Drivers/SurfaceBook2/main.fish" $argv end - and if isEnabled valhalla.linux.hardware.nvidiaGPU + and if isOSEnabled hardware.nvidiaGPU source "$dir/../Software/nvidia-dkms/main.fish" $argv end - and if isEnabled valhalla.linux.hardware.xoneReceiver + and if isOSEnabled hardware.xoneReceiver source "$dir/../Software/xone/main.fish" $argv end - and for component in (getConfig valhalla.linux.hardware.components --json | jq '.[]' --raw-output0 | string split0) + and for component in (getOSConfig hardware.components --json | jq '.[]' --raw-output0 | string split0) if [ "$component" = "Logitech G903" ] source "$dir/../../Common/Drivers/Logitech G903/main.fish" $argv end diff --git a/scripts/Arch/Software/steam/main.fish b/scripts/Arch/Software/steam/main.fish index f645bc2c..5195dba3 100644 --- a/scripts/Arch/Software/steam/main.fish +++ b/scripts/Arch/Software/steam/main.fish @@ -11,7 +11,7 @@ begin function configureSW -V dir . "$dir/../../../Common/Scripts/config.fish" - if isEnabled valhalla.hidpi + if isOSEnabled hidpi begin printf %s\n \ "#!/bin/bash" \ diff --git a/scripts/Common/OS/install.fish b/scripts/Common/OS/install.fish index 2a8f87ab..a922cff7 100755 --- a/scripts/Common/OS/install.fish +++ b/scripts/Common/OS/install.fish @@ -4,7 +4,7 @@ source "$dir/../Scripts/config.fish" source "$dir/../Scripts/hooks.fish" if [ (id -u) -eq 0 ] - set -l name (getConfig valhalla.setupUser.name) + set -l name (getOSConfig setupUser.name) set -l sudoConfig "/etc/sudoers.d/PortValhalla" rm ~/.bash_profile @@ -16,7 +16,7 @@ if [ (id -u) -eq 0 ] --no-user-group \ --groups nix-users \ --create-home \ - --uid (getConfig valhalla.setupUser.id --json) \ + --uid (getOSConfig setupUser.id --json) \ "$name" end diff --git a/scripts/Common/OS/setup.fish b/scripts/Common/OS/setup.fish index 03cfe308..14b5d914 100755 --- a/scripts/Common/OS/setup.fish +++ b/scripts/Common/OS/setup.fish @@ -3,7 +3,7 @@ function runSetup set -l dir (status dirname) source "$dir/../Scripts/config.fish" source "$dir/../Scripts/hooks.fish" - set -l mountDir (getConfig valhalla.partition.rootDir) + set -l mountDir (getOSConfig partition.rootDir) set -l projectRoot (realpath "$dir/../../..") set -l projectName (basename "$projectRoot") set -l PROJECT_CLONE_ROOT "/opt/$(basename "$projectName")" @@ -43,7 +43,7 @@ function runSetup "$argv" end - getConfig valhalla.partition.script > "$script" + getOSConfig partition.script > "$script" and "$script" and rm "$script" diff --git a/scripts/Common/OS/users.fish b/scripts/Common/OS/users.fish index 997cc048..493af494 100755 --- a/scripts/Common/OS/users.fish +++ b/scripts/Common/OS/users.fish @@ -5,13 +5,13 @@ set -l users (getUsers) for name in (echo "$users" | jq '.[]' --raw-output0 | string split0) - function getUserConfig -V name -a config - getConfig "valhalla.linux.users.$name.$config" $argv[2..] + function getUserInfo -V name -a config + getUserConfig "$name" "$config" $argv[2..] end - set -l groups (getUserConfig groups --apply 'builtins.concatStringsSep ","'); - set -l displayName (getUserConfig displayName --json) - set -l shell (getUserConfig defaultShell --json) + set -l groups (getUserInfo groups --apply 'builtins.concatStringsSep ","'); + set -l displayName (getUserInfo displayName --json) + set -l shell (getUserInfo defaultShell --json) sudo useradd --create-home ( if echo "$displayName" | jq --exit-status > /dev/null diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index 9d2d7908..e6a86173 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -226,7 +226,10 @@ $null = New-Module { Gets a configuration option. .PARAMETER Name - The name of the option to get. + The name of the configuration value to get. + + .PARAMETER ArgumentList + The arguments to send to the configuration script. #> function Get-Config { param( @@ -242,16 +245,36 @@ $null = New-Module { .SYNOPSIS Gets the name of the config root. #> - function Get-ConfigRootName { + function Get-OSConfigRoot { return "valhalla.$($IsWindows ? "windows" : "linux")"; } + <# + .SYNOPSIS + Gets the configuration value for the current operating system. + + .PARAMETER Name + The name of the configuration value to get. + + .PARAMETER ArgumentList + The arguments to send to the configuration script. + #> + function Get-OSConfig { + param( + [string] $Name, + [Parameter(ValueFromRemainingArguments)] + [string[]] $ArgumentList + ) + + return Get-Config -Name "$(Get-OSConfigRoot).$Name" @PSBoundParameters; + } + <# .SYNOPSIS Gets the name of the user root. #> - function Get-UserRootName { - return "$(Get-ConfigRootName).$($IsWindows ? "winUsers" : "users")"; + function Get-UserConfigRoot { + return "$(Get-OSConfigRoot).$($IsWindows ? "winUsers" : "users")"; } <# @@ -272,7 +295,7 @@ $null = New-Module { ) if ((Get-Users) -contains $UserName) { - Get-Config "$(Get-UserRootName).$UserName.$Name"; + Get-Config "$(Get-UserConfigRoot).$UserName.$Name"; } else { return $null; } @@ -300,7 +323,7 @@ $null = New-Module { function Get-Users { [OutputType([string[]])] param() - Get-Attributes "$(Get-UserRootName)"; + Get-Attributes "$(Get-UserConfigRoot)"; } <# @@ -310,7 +333,7 @@ $null = New-Module { function Get-SetupUser { [OutputType([string])] param() - Get-Config "$(Get-ConfigRootName).setupUser.name"; + Get-OSConfig "setupUser.name"; } <# diff --git a/scripts/Common/Scripts/config.fish b/scripts/Common/Scripts/config.fish index 95802c10..e40c5cf3 100755 --- a/scripts/Common/Scripts/config.fish +++ b/scripts/Common/Scripts/config.fish @@ -13,22 +13,46 @@ function getConfig -S -a property evalFlake "$CONFIG_NAME" "$property" $argv[2..] end +function getOSConfigRoot + echo "valhalla.linux" +end + +function getOSConfig -S -a property + getConfig "$(getOSConfigRoot).$property" $argv[2..] +end + function getAttributes -S -a property getConfig "$property" --apply "builtins.attrNames" --json end function getUsers -S - getAttributes "valhalla.users" + getAttributes "$(getOSConfigRoot).users" +end + +function getUserConfig -S -a name property + getOSConfig "users.$name.$property" $argv[3..] end function isSet -S -a property not test "$(getConfig "$property" --json)" = "null" end +function isOSSet -S -a property + isSet "$(getOSConfigRoot).$property" +end + +function isUserSet -S -a name property + isOSSet "users.$name.$property" +end + function isEnabled -S -a property getConfig "$property" --json | jq --exit-status > /dev/null end -function collectionActive -S -a name - [ "$(getConfig "valhalla.software.$name" --json)" = "true" ] +function isOSEnabled -S -a property + isEnabled "$(getOSConfigRoot).$property" +end + +function collectionActive -S -a name + [ "$(getOSConfig "software.$name" --json)" = "true" ] end diff --git a/scripts/Common/Software/GRUB/main.fish b/scripts/Common/Software/GRUB/main.fish index 5948c21f..40c501f6 100755 --- a/scripts/Common/Software/GRUB/main.fish +++ b/scripts/Common/Software/GRUB/main.fish @@ -5,13 +5,13 @@ begin source "$dir/../../Scripts/software.fish" function configureSW - set -l efiDir (getConfig valhalla.boot.efiMountPoint) + set -l efiDir (getOSConfig boot.efiMountPoint) sudo sed -i \ -e "s/#\(GRUB_DISABLE_OS_PROBER\)/\1/" \ /etc/default/grub - sudo grub-install --target=x86_64-efi --efi-directory="$efiDir" --bootloader-id="$(getConfig valhalla.boot.label)" + sudo grub-install --target=x86_64-efi --efi-directory="$efiDir" --bootloader-id="$(getOSConfig boot.label)" sudo grub-mkconfig -o "$efiDir/grub/grub.cfg" end diff --git a/scripts/Common/Software/git/Manage.ps1 b/scripts/Common/Software/git/Manage.ps1 index 2ce44307..3fc9f424 100644 --- a/scripts/Common/Software/git/Manage.ps1 +++ b/scripts/Common/Software/git/Manage.ps1 @@ -17,18 +17,19 @@ param ( [string] $User ) - $root = "valhalla"; + $getConfig = $null; if ($User) { - $root = "$root$($IsWindows ? ".windows" : '').users.$User"; + $getConfig = { Get-UserConfig -UserName $User @args }; $sudoArgs = @("-u", $User); $configArgs = @("--global"); } else { + $getConfig = { Get-OSConfig @args }; $sudoArgs = @(); $configArgs = @("--system"); } - $config = Get-Config "$root.git"; + $config = & $getConfig "git"; <# .SYNOPSIS diff --git a/scripts/Common/Software/rclone/main.fish b/scripts/Common/Software/rclone/main.fish index 587a889a..837adf44 100755 --- a/scripts/Common/Software/rclone/main.fish +++ b/scripts/Common/Software/rclone/main.fish @@ -9,8 +9,8 @@ begin function userConfig -V dir -a name source "$dir/../../Scripts/config.fish" - set -l key "valhalla.linux.users.$name.rclone.configurations" - set -l configs (getConfig "$key" --apply "builtins.attrNames" --json) + set -l key "rclone.configurations" + set -l configs (getUserConfig "$name" "$key" --apply "builtins.attrNames" --json) if [ (echo "$configs" | jq "length") -gt 0 ] if [ "$XDG_SESSION_TYPE" = "tty" ] @@ -89,10 +89,10 @@ begin set -l configKey "$key.$config" set -l duration "$configKey.cacheDuration" - set -l serviceName "rclone@$config:$(getConfig "$configKey.dirName")" + set -l serviceName "rclone@$config:$(getUserConfig "$name" "$configKey.dirName")" - if isSet "$duration" - set serviceName "$serviceName:$(getConfig "$duration")" + if isUserSet "$name" "$duration" + set serviceName "$serviceName:$(getUserConfig "$name" "$duration")" end echo "Please create a remote called `$config`." diff --git a/scripts/Windows/Scripts/Deployment.ps1 b/scripts/Windows/Scripts/Deployment.ps1 index 374fd86f..fb8655c4 100644 --- a/scripts/Windows/Scripts/Deployment.ps1 +++ b/scripts/Windows/Scripts/Deployment.ps1 @@ -25,8 +25,8 @@ function Deploy-SoftwareAction { $install = $true; } - $hardware = Get-Config "valhalla.hardware"; - $collections = Get-Config "valhalla.windows.software"; + $hardware = Get-OSConfig "hardware"; + $collections = Get-OSConfig "software"; # Drivers & { @@ -108,7 +108,7 @@ function Deploy-SoftwareAction { & "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments; & "$softwarePath/Oh My Posh/Manage.ps1" @arguments; - if (Get-Config "valhalla.windows.dualboot") { + if (Get-OSConfig "dualboot") { & "$softwarePath/Ext4Fsd/Main.ps1" @arguments; } diff --git a/scripts/Windows/Software/Windows/Manage.ps1 b/scripts/Windows/Software/Windows/Manage.ps1 index 20d3c296..f49e4ef4 100644 --- a/scripts/Windows/Software/Windows/Manage.ps1 +++ b/scripts/Windows/Software/Windows/Manage.ps1 @@ -44,19 +44,11 @@ param( $dir = New-TemporaryDirectory; Push-Location $dir; - function Get-WinConfig { - param( - [string] $Name - ) - - Get-Config "valhalla.windows.$Name"; - } - # Copy keyboard layout # ToDo: Why not NewUser? Investiagte! Copy-UserInternationalSettingsToSystem -WelcomeScreen $True -NewUser $False; - if (Get-WinConfig "legacyIconSpacing") { + if (Get-OSConfig "legacyIconSpacing") { Write-Host "Setting up old-school Desktop Icon spacing"; Edit-DefaultUserKey { @@ -73,7 +65,7 @@ param( }; } - if (-not (Get-WinConfig "dynamicLighting")) { + if (-not (Get-OSConfig "dynamicLighting")) { Write-Host "Disabling Dynamic Lighting"; Edit-DefaultUserKey { @@ -87,7 +79,7 @@ param( }; } - if (-not (Get-WinConfig "adware")) { + if (-not (Get-OSConfig "adware")) { $startLayoutFile = "start.json"; Write-Host "Removing adware"; @@ -151,7 +143,7 @@ param( $startLayout | ConvertTo-Json -Compress | Set-Content "$env:SystemDrive\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.json"; } - if (Get-WinConfig "showFileExt") { + if (Get-OSConfig "showFileExt") { Edit-DefaultUserKey { param ( [RegistryKey] $Key diff --git a/scripts/Windows/Software/git/Manage.ps1 b/scripts/Windows/Software/git/Manage.ps1 index 4328ba79..320c0f93 100644 --- a/scripts/Windows/Software/git/Manage.ps1 +++ b/scripts/Windows/Software/git/Manage.ps1 @@ -18,7 +18,7 @@ param ( Start-SoftwareInstaller @Parameters ` -Installer { $params = "/WindowsTerminalProfile"; - $defaultBranch = Get-Config "valhalla.git.defaultBranch"; + $defaultBranch = Get-OSConfig "git.defaultBranch"; if ($defaultBranch) { $params += " /DefaultBranchName:`"$defaultBranch`"";