Detect entrypoint automatically

This commit is contained in:
Manuel Thalmann 2024-03-16 01:04:56 +01:00
parent e6d400ef11
commit f75f8a3fee
4 changed files with 16 additions and 2 deletions

View file

@ -16,7 +16,6 @@ function Restore-Apps {
Write-Host "Starting Restoration of Windows";
. "$PSScriptRoot/../../../scripts/Windows/OS/Install.ps1";
[Context]$context = [Context]::new();
$context.EntryPoint = "$($MyInvocation.MyCommand.Path)";
$context.UserName = "Manuel";
Invoke-WindowsInstallation $context;
Restart-Computer -Force;

View file

@ -10,7 +10,6 @@ function Restore-Apps {
}
[Context]$context = [Context]::new();
$context.EntryPoint = "$($MyInvocation.MyCommand.Path)";
$context.UserName = "Manuel";
Invoke-WindowsInstallation $context;
Restart-Computer -Force;

View file

@ -1,5 +1,6 @@
#!/bin/pwsh
. "$PSScriptRoot/../Scripts/Context.ps1";
. "$PSScriptRoot/../Scripts/Entrypoints.ps1";
. "$PSScriptRoot/../Software/Firefox/Install.ps1";
. "$PSScriptRoot/Manage.ps1";
. "$PSScriptRoot/Upgrade.ps1";
@ -7,6 +8,7 @@
function Invoke-WindowsInstallation([Context] $context)
{
$context.EntryPoint = Get-Entrypoint;
$configPath = "$PSScriptRoot/../Config";
$softwarePath = "$PSScriptRoot/../Software";

View file

@ -0,0 +1,14 @@
function Get-Entrypoint() {
$stackTrace = Get-PSCallStack
$call = $stackTrace[$stackTrace.Count - 1];
if ($null -ne $call.ScriptName) {
return $call.ScriptName;
} else {
$call = $CallStack[$CallStack.Count - 2];
return $call.ScriptName;
}
throw "No PowerShell entry point script could be found.";
}