Add dedicated functions for creating startup scripts

This commit is contained in:
Manuel Thalmann 2024-08-09 23:23:29 +02:00
parent c42b30b52e
commit bd2dc90463

View file

@ -38,6 +38,32 @@ $null = New-Module {
}
}
<#
.SYNOPSIS
Generates a script for executing the installer.
#>
function Get-StartupScript {
"pwsh " + (Get-StartupArguments);
}
<#
.SYNOPSIS
Generates arguments for running the installer using `pwsh`.
#>
function Get-StartupArguments {
"-Command " +
(& {
if ($env:PWSH_PATH) {
"`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);"
} else {
""
}
}) +
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
"`$env:CONFIG_MODULE = $(ConvertTo-Injection ($env:CONFIG_MODULE));" +
"& `$env:INSTALLER_SCRIPT;";
}
<#
.SYNOPSIS
Registers a task to run the setup once after the next reboot.
@ -65,20 +91,7 @@ $null = New-Module {
$key = Get-RunOnceKey;
}
Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value (
"pwsh -Command " +
(& {
if ($env:PWSH_PATH) {
"`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);"
} else {
""
}
}) +
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
"`$env:CONFIG_MODULE = $(ConvertTo-Injection $env:CONFIG_MODULE);" +
"& `$env:INSTALLER_SCRIPT;"
);
Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value (Get-StartupScript);
$key.Handle.Close();
}