Compare commits

...

17 commits

Author SHA1 Message Date
Manuel Thalmann 770445ea95 Add scripts for installing drivers 2024-08-07 16:17:49 +02:00
Manuel Thalmann 3e57070f4e Add script for installing AMD packages 2024-08-07 15:25:12 +02:00
Manuel Thalmann 8b921112e2 Add missing package for selenium 2024-08-07 15:24:56 +02:00
Manuel Thalmann 6ca8369d08 Ensure correct types for setting download dir 2024-08-07 15:24:37 +02:00
Manuel Thalmann 979e77a95d Add a script for installing ASUS packages 2024-08-07 14:40:24 +02:00
Manuel Thalmann 81db7a4bca Refactor browser automation scripts 2024-08-07 14:28:26 +02:00
Manuel Thalmann 46c30157a0 Execute winget script in a module 2024-08-07 13:36:47 +02:00
Manuel Thalmann d6f58f3185 Install components for browser automation 2024-08-07 13:36:31 +02:00
Manuel Thalmann a1c094dba5 Add functions for installing choco and winget packages 2024-08-07 13:22:12 +02:00
Manuel Thalmann 82a365a14a Add a function for checking winget packages 2024-08-07 13:18:29 +02:00
Manuel Thalmann cd822fc916 Enhance the winget install check 2024-08-07 03:34:12 +02:00
Manuel Thalmann 35867a0016 Add a function for checking NuGet packages 2024-08-07 03:23:59 +02:00
Manuel Thalmann ff48173d0d Fix non-functioning script 2024-08-07 03:23:21 +02:00
Manuel Thalmann 143b4d86fb Install PowerShell modules after removing old copy 2024-08-06 18:19:33 +02:00
Manuel Thalmann 639eb26da1 Add config for declaring hardware 2024-08-06 17:23:20 +02:00
Manuel Thalmann 4a5c658315 Silence unnecessary output 2024-08-06 17:07:57 +02:00
Manuel Thalmann 9cbf51fe45 Add a separate function for executing software actions 2024-08-06 16:54:11 +02:00
19 changed files with 536 additions and 111 deletions

43
lib/modules/hardware.nix Normal file
View file

@ -0,0 +1,43 @@
{ lib, ... }:
let
inherit (lib)
mkOption
types
;
in {
options = {
valhalla = {
hardware = {
components = mkOption {
type = types.listOf types.str;
description = "The names of the hardware components of the computer.";
default = [];
};
eyeX = mkOption {
type = types.bool;
description = "A value indicating whether a Tobii EyeX device is present.";
default = false;
};
amdCPU = mkOption {
type = types.bool;
description = "A value indicating whether an AMD CPU is present.";
default = false;
};
nvidiaGPU = mkOption {
type = types.bool;
description = "A value indicating whether an NVIDIA GPU is present.";
default = false;
};
elgatoWave = mkOption {
type = types.bool;
description = "A value indicating whether an Elgato Wave device is present.";
default = false;
};
};
};
};
}

View file

@ -7,6 +7,7 @@
in {
imports = [
./git.nix
./hardware.nix
./i18n.nix
./partition.nix
./software.nix

View file

@ -24,6 +24,17 @@
keepExisting = true;
};
};
hardware = {
components = [
"ROG Zenith Extreme Alpha"
];
eyeX = true;
amdCPU = true;
nvidiaGPU = true;
elgatoWave = true;
};
};
};
}

View file

@ -0,0 +1,11 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-AmdPackage "https://www.amd.com/en/support/downloads/drivers.html/chipsets/tr4/x399.html";
};

View file

@ -0,0 +1,21 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../Scripts/Software.ps1";
. "$PSScriptRoot/../../Scripts/System.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
$dir = New-TemporaryDirectory;
$file = "driver.zip";
$null = Push-Location $dir;
Invoke-WebRequest "https://global-download.acer.com/GDFiles/Driver/Monitor/Monitor_Acer_1.0_W7x86W7x64W8x86W8x64_A.zip?acerid=636092441703392074" -OutFile $file;
Expand-Archive $file;
$null = Start-Process -Wait -FilePath "pnputil" -ArgumentList "/add-driver","*.inf","/install","/subdirs";
$null = Pop-Location;
Remove-Item -Recurse $dir;
};

View file

@ -0,0 +1,11 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../../Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-AsusPackage "https://dlcdnets.asus.com/pub/ASUS/mb/03CHIPSET/DRV_Chipset_AMD_TRX40_TP_TSD_W10_64_V30901140_20211006R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA";
};

View file

@ -0,0 +1,11 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../../Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-AsusPackage "https://dlcdnets.asus.com/pub/ASUS/mb/02BT/DRV_Bluetooth_Intel_9260_TP_W11_64_V2210002_20211222R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA";
};

View file

@ -0,0 +1,11 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../../Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-AsusPackage "https://dlcdnets.asus.com/pub/ASUS/mb/08WIRELESS/DRV_WiFi_Intel_TP_W11_64_V2219004_20230130R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA";
};

View file

@ -0,0 +1,11 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../../Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-AsusPackage "https://dlcdnets.asus.com/pub/ASUS/mb/04LAN/DRV_LAN_Marvell_TP_TSD_W11_64_V3130_20211118R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA";
};

View file

@ -0,0 +1,11 @@
param(
$Action,
[hashtable] $Arguments
)
. "$PSScriptRoot/../../Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
Install-SetupPackage -Source "https://files.update.tech.tobii.com/Tobii_Eye_Tracking_Core_v2.16.8.214_x86.exe";
};

View file

@ -10,8 +10,10 @@ $null = New-Module {
. "$PSScriptRoot/../Scripts/Hooks.ps1";
. "$PSScriptRoot/../Scripts/Operations.ps1";
. "$PSScriptRoot/../Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../Scripts/Software.ps1";
. "$PSScriptRoot/../Scripts/SoftwareManagement.ps1";
. "$PSScriptRoot/../Scripts/Update.ps1";
. "$PSScriptRoot/../Types/InstallerAction.ps1";
<#
.SYNOPSIS
@ -53,21 +55,30 @@ $null = New-Module {
return;
}
Invoke-Hook "Install-PSModules" -Fallback {
Install-Module -AcceptLicense -Force PSWindowsUpdate;
};
if (Test-Path $env:PWSH_PATH) {
attrib "-R" "$env:PWSH_PATH\*" /S /D;
Remove-Item -Recurse -Force $env:PWSH_PATH;
continue;
}
if (-not (Test-Command winget)) {
Invoke-Hook "Install-PSModules" -Fallback {
Install-Module -AcceptLicense -Force PSWindowsUpdate;
};
if (-not (Test-Winget)) {
. "$PSScriptRoot/../Software/winget/Manage.ps1";
continue;
}
if (-not (Test-PSPackage Selenium.WebDriver)) {
Install-Module -AcceptLicense -Force NuGet;
Import-Module NuGet;
$null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies;
continue;
}
Install-ChocoPackage selenium-gecko-driver firefox;
if (-not (& { wsl --status; $?; })) {
wsl --install --no-launch;
Restart-Intermediate;
@ -93,6 +104,78 @@ $null = New-Module {
return;
}
<#
.SYNOPSIS
Deploys an action for each software.
.PARAMETER Action
The action to execute by default.
#>
function Deploy-SoftwareAction {
param(
[InstallerAction] $Action
)
$arguments = [hashtable]@{ };
if ($Action) {
$arguments.Add("action", $Action);
}
# Drivers
$null = New-Module {
$driverPath = "$PSScriptRoot/../Drivers";
$mbPath = "$driverPath/ROG Zenith Extreme Alpha";
foreach ($component in (Get-Config "valhalla.hardware.components")) {
switch ($component) {
("ROG Zenith Extreme Alpha") {
. "$mbPath/MarvellEthernet/Manage.ps1" @arguments;
. "$mbPath/IntelWiFi/Manage.ps1" @arguments;
. "$mbPath/IntelBluetooth/Manage.ps1" @arguments;
. "$mbPath/AMDChipsetX399/Manage.ps1" @arguments;
. "$driverPath/AMDChipsetX399/Manage.ps1" @arguments;
}
("Predator Z301C") {
. "$driverPath/Predator Z301C/Manage.ps1" @arguments;
}
}
}
if (Get-Config "valhalla.hardware.amdCPU") {
Install-ChocoPackage amd-ryzen-master;
# ToDo: backup Ryzen energy saving plan
}
if (Get-Config "valhalla.hardware.nvidiaGPU") {
Install-ChocoPackage geforce-game-ready-driver;
Remove-DesktopIcon "*Geforce*";
}
if (Get-Config "valhalla.hardware.corsairLighting") {
Install-ChocoPackage icue;
}
if (Get-Config "valhalla.hardware.elgatoWave") {
Install-ChocoPackage wavelink;
Remove-DesktopIcon "*Wave Link*";
}
if (Get-Config "valhalla.hardware.eyeX") {
. "$driverPath/Tobii EyeX/Manage.ps1" @arguments;
}
};
# Windows Config
. "$PSScriptRoot/../Software/Windows/Manage.ps1" @arguments;
if (Test-Collection "essential") {
# Essentials
. "$PSScriptRoot/../Software/OpenSSH/Manage.ps1" @arguments;
}
}
switch (Get-Stage) {
([SetupStage]::Configure) {
if (Get-Config "valhalla.windows.dualboot.enable") {
@ -114,15 +197,7 @@ $null = New-Module {
}
([SetupStage]::Install) {
Write-Host "Entering install phase";
# Windows Config
. "$PSScriptRoot/../Software/Windows/Manage.ps1";
if (Test-Collection "essential") {
# Essentials
. "$PSScriptRoot/../Software/OpenSSH/Manage.ps1";
}
Deploy-SoftwareAction;
Set-IsFinished $true;
}
}

View file

@ -36,7 +36,7 @@ function Install-AmdSoftwarePackage() {
}
}
$file = Start-CustomDownload $context $url $action $tempDir;
$file = Start-CustomBrowserDownload $context $url $action $tempDir;
Start-Process -Wait -FilePath $file -ArgumentList "/S";
Remove-Item -Recurse $tempDir;

View file

@ -1,47 +1,80 @@
#!/bin/bash
. "$PSScriptRoot/Context.ps1";
if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) {
if ((Get-Package Selenium.WebDriver -ErrorAction "SilentlyContinue")) {
$null = New-Module {
. "$PSScriptRoot/System.ps1";
<#
.SYNOPSIS
Runs an action involving browser automation.
.PARAMETER Action
The action to execute.
#>
function Start-BrowserAutomation {
param(
[scriptblock] $Action
)
if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) {
$zipFile = [System.IO.Compression.ZipFile]::OpenRead((Get-Package Selenium.WebDriver).Source);
$webDriver = ($zipFile.Entries | Where-Object { $_.FullName -like "lib/net6.0/WebDriver.dll" })[0];
$stream = [System.IO.MemoryStream]::new();
$reader = [System.IO.StreamReader]($zipFile.Entries[2]).Open();
$reader = [System.IO.StreamReader]($webDriver).Open();
$reader.BaseStream.CopyTo($stream);
[byte[]]$bytes = $stream.ToArray();
$reader.Close();
$reader.Dispose();
$stream.Close();
$stream.Dispose();
$zipFile.Dispose();
$null = [System.Reflection.Assembly]::Load($bytes);
}
}
function Start-CustomDownload() {
& $Action;
}
<#
.SYNOPSIS
Downloads a file from the specified url using browser automation.
.PARAMETER URL
The url to download the file from.
.PARAMETER Action
The action to execute in the browser for initiating the download.
.PARAMETER OutDir
The directory to download the file to.
#>
function Start-CustomBrowserDownload {
param(
[Context] $context,
[string] $url,
[Action[OpenQA.Selenium.Firefox.FirefoxDriver]] $action,
[string] $outDir = $null
[string] $URL,
[scriptblock] $Action,
[string] $OutDir
)
$tempDir = $context.GetTempDirectory();
if (-not $OutDir) {
$OutDir = ".";
}
$dir = New-TemporaryDirectory;
Write-Host "Downloading ``$URL`` using browser automation…";
$options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new();
$options.SetPreference("browser.download.folderList", 2);
$options.SetPreference("browser.download.dir", $tempDir);
# $options.AddArgument("--headless");
$options.SetPreference("browser.download.dir", "$dir");
$downloadChecker = {
param()
$files = Get-ChildItem $dir;
$files = Get-ChildItem $tempDir;
if ($(@($files)).Count -gt 0) {
foreach ($file in Get-ChildItem $tempDir) {
if ((@($files)).Count -gt 0) {
foreach ($file in $files) {
try {
$stream = [System.IO.File]::Open($file.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None);
if ($stream) {
$stream.Close();
}
}
catch {
return $true;
@ -52,41 +85,50 @@ function Start-CustomDownload() {
} else {
return $true;
}
}
};
$browser = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($options);
$browser.Navigate().GoToUrl($url);
$action.Invoke($browser);
$browser.Navigate().GoToUrl($URL);
& $Action -Browser $browser;
while ($downloadChecker.Invoke()) {
Write-Information "Waiting for download to finish...";
while (& $downloadChecker) {
Write-Host "Waiting for the download to finish…";
Start-Sleep 1;
}
$file = Get-ChildItem $tempDir;
if (-not $outDir) {
$outDir = ".";
$file = Get-ChildItem $dir;
$result = Move-Item $file $OutDir -PassThru;
$browser.Quit();
Remove-Item -Recurse $dir;
$result;
}
$result = Move-Item $file $outDir -PassThru;
$browser.Quit();
Remove-Item -Recurse $tempDir;
return $result;
}
<#
.SYNOPSIS
Downloads a file from the specified url using browser automation.
function Start-AutomatedDownload() {
.PARAMETER URL
The url to download the file from.
.PARAMETER ButtonSelector
The jQuery selector for finding the download button.
.PARAMETER OutDir
The directory to download the file to.
#>
function Start-BrowserDownload {
param(
[Context] $context,
[string] $url,
[string] $buttonSelector,
[string] $outDir = $null
[string] $URL,
[string] $ButtonSelector,
[string] $OutDir = $null
)
$action = {
param([OpenQA.Selenium.Firefox.FirefoxDriver] $browser)
$browser.FindElement([OpenQA.Selenium.By]::CssSelector("$buttonSelector")).Click();
}
Start-CustomBrowserDownload @PSBoundParameters -Action {
param(
[OpenQA.Selenium.Firefox.FirefoxDriver] $Browser
)
return Start-CustomDownload $context $url $action $outDir;
}
$Browser.FindElement([OpenQA.Selenium.By]::CssSelector($ButtonSelector)).Click();
};
}
};

View file

@ -1,11 +1,134 @@
. "$PSScriptRoot/Config.ps1";
. "$PSScriptRoot/Operations.ps1";
. "$PSScriptRoot/System.ps1";
. "$PSScriptRoot/../Types/InstallerAction.ps1";
$null = New-Module {
. "$PSScriptRoot/BrowserAutomation.ps1";
. "$PSScriptRoot/SoftwareManagement.ps1";
. "$PSScriptRoot/../Types/InstallerAction.ps1";
$userArgument = "name";
<#
.SYNOPSIS
Installs the specified packages using chocolatey.
.PARAMETER Names
The names of the packages to install.
#>
function Install-ChocoPackage {
param(
[switch] $Force,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $Names
)
[System.Collections.ArrayList] $Names = $Names;
if (-not ($Force.IsPresent)) {
for ($i = $Names.Count - 1; $i -ge 0; $i--) {
if (Test-ChocoPackage $Names[$i]) {
$Names.RemoveAt($i);
}
}
}
if ($Names.Count -ge 1) {
choco install -y $Names;
}
}
<#
.SYNOPSIS
Installs the specified packages using `winget`.
.PARAMETER Names
The names of the packages to install.
#>
function Install-WingetPackage {
param(
[switch] $Force,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $Names
)
foreach ($name in $Names) {
if ($Force.IsPresent -and -not (Test-WingetPackage $name)) {
winget install --accept-source-agreements --accept-package-agreements -e --id $name;
}
}
}
<#
.SYNOPSIS
Installs a package downloaded from ASUS.
.PARAMETER URL
The URL to download the package from.
#>
function Install-AsusPackage {
param(
[string] $URL
)
$file = "AsusPackage.zip";
$dir = New-TemporaryDirectory;
$unpackDir = New-TemporaryDirectory;
$null = Push-Location $dir;
Invoke-WebRequest $URL -OutFile $file;
Expand-Archive $file $unpackDir;
$null = Pop-Location;
Remove-Item -Recurse $dir;
$null = Start-Process -Wait -WorkingDirectory $unpackDir -FilePath (Join-Path $unpackDir "AsusSetup.exe") -ArgumentList "/S";
Remove-Item -Recurse $unpackDir;
}
<#
.SYNOPSIS
Downloads and installs a package from the AMD website.
.PARAMETER URL
The URL to download the package from.
#>
function Install-AmdPackage {
param(
[string] $URL
)
$dir = New-TemporaryDirectory;
$cookieBannerSelector = "#onetrust-consent-sdk";
$osSelector = "div[id$='oscategory']>div[id$='-0']";
$downloadSelector = "$osSelector div[id$='panel'] .button a";
$file = Start-CustomBrowserDownload @PSBoundParameters -OutDir $dir -Action {
param(
[OpenQA.Selenium.Firefox.FirefoxDriver] $Browser
)
$osContainer = $Browser.FindElement([OpenQA.Selenium.By]::CssSelector($osSelector));
if (-not ([bool] $osContainer.GetAttribute("cmp-expanded"))) {
$osContainer.Click();
}
$download = {
$browser.FindElement([OpenQA.Selenium.By]::CssSelector($downloadSelector)).Click();
};
try {
& $download;
} catch {
$Browser.ExecuteScript("document.querySelector('$cookieBannerSelector').remove()");
& $download;
}
};
Start-Process -Wait -WorkingDirectory $dir -FilePath $file -ArgumentList "/S";
Remove-Item -Recurse $dir;
}
function Start-SoftwareInstaller {
param(
[string] $Name,

View file

@ -43,6 +43,22 @@ function Test-ChocoPackage {
-not [string]::IsNullOrEmpty((choco list --limit-output --exact $name));
}
<#
.SYNOPSIS
Checks whether a `winget` package with the specified id is installed.
.PARAMETER ID
The id of the package to check.
#>
function Test-WingetPackage {
[OutputType([bool])]
param(
[string] $ID
)
-not (& { $null = winget list --accept-source-agreements -e --id $ID; $?; });
}
<#
.SYNOPSIS
Checks whether a command with the specified name exists.
@ -57,3 +73,29 @@ function Test-Command {
[bool] (Get-Command $Name -ErrorAction SilentlyContinue);
}
<#
.SYNOPSIS
Checks whether `winget` is working properly.
#>
function Test-Winget {
(Test-Command winget) -and -not (
[System.Linq.Enumerable]::Any(
[string[]](winget source update winget),
[System.Func[string,bool]]{ param($line) $line -eq "Cancelled"; }));
}
<#
.SYNOPSIS
Checks whether a package with the specified name is installed.
.PARAMETER Name
The name of the package to check.
#>
function Test-PSPackage {
param(
[string] $Name
)
[bool] (Get-Package $Name -ErrorAction SilentlyContinue);
}

View file

@ -25,7 +25,7 @@ $action = {
}
Write-Information "Downloading GPU-Z";
$file = Start-CustomDownload $context "https://www.techpowerup.com/download/techpowerup-gpu-z/" $action $tempDir;
$file = Start-CustomBrowserDownload $context "https://www.techpowerup.com/download/techpowerup-gpu-z/" $action $tempDir;
Write-Information "Launching GPU-Z installer";
Start-Process -Wait -FilePath $file.FullName -ArgumentList "-installSilent";

View file

@ -17,7 +17,7 @@ Start-SoftwareInstaller @PSBoundParameters `
} `
-Configurator {
$nativeProfile = powershell -c '$PROFILE';
New-Item -Force $nativeProfile;
$null = New-Item -Force $nativeProfile;
choco install -y --force chocolatey;
Copy-Item -Force $nativeProfile $PROFILE;

View file

@ -16,7 +16,7 @@ $null = New-Module {
$tempDir = $context.GetTempDirectory();
Write-Information "Downloading reWASD";
$file = Start-AutomatedDownload $context "https://rewasd.com/" 'a.btn-default[href="#"]' $tempDir;
$file = Start-BrowserDownload $context "https://rewasd.com/" 'a.btn-default[href="#"]' $tempDir;
Write-Information "Installing reWASD";
Start-Process -Wait -FilePath $file.FullName -ArgumentList "/S";

View file

@ -3,10 +3,10 @@ param(
[hashtable] $Arguments
)
. "$PSScriptRoot/../../Scripts/Software.ps1";
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
$null = New-Module {
. "$PSScriptRoot/../../Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters `
Start-SoftwareInstaller @PSBoundParameters `
-Installer {
$xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx";
$downloadLink = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle";
@ -18,3 +18,4 @@ Start-SoftwareInstaller @PSBoundParameters `
Add-AppxPackage "$file";
Remove-Item $file;
};
};