From 8339cb30066dbac52343b4d6faa90bcf6db5d795 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 16 Mar 2024 01:04:56 +0100 Subject: [PATCH] Detect entrypoint automatically --- profiles/DerGeret/Windows/Restore.ps1 | 1 - profiles/Generic/Windows/Install.ps1 | 1 - scripts/Windows/OS/Install.ps1 | 2 ++ scripts/Windows/Scripts/Entrypoints.ps1 | 14 ++++++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 scripts/Windows/Scripts/Entrypoints.ps1 diff --git a/profiles/DerGeret/Windows/Restore.ps1 b/profiles/DerGeret/Windows/Restore.ps1 index 7027962a..bc5a1d7a 100644 --- a/profiles/DerGeret/Windows/Restore.ps1 +++ b/profiles/DerGeret/Windows/Restore.ps1 @@ -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; diff --git a/profiles/Generic/Windows/Install.ps1 b/profiles/Generic/Windows/Install.ps1 index 56017417..e693af4f 100644 --- a/profiles/Generic/Windows/Install.ps1 +++ b/profiles/Generic/Windows/Install.ps1 @@ -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; diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index b7c78e1d..bc784a07 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -3,10 +3,12 @@ . "$PSScriptRoot/Upgrade.ps1"; . "$PSScriptRoot/User.ps1"; . "$PSScriptRoot/../Scripts/Context.ps1"; +. "$PSScriptRoot/../Scripts/Entrypoints.ps1"; . "$PSScriptRoot/../Software/Firefox/Install.ps1"; function Invoke-WindowsInstallation([Context] $context) { + $context.EntryPoint = Get-Entrypoint; $configPath = "$PSScriptRoot/../Config"; $softwarePath = "$PSScriptRoot/../Software"; diff --git a/scripts/Windows/Scripts/Entrypoints.ps1 b/scripts/Windows/Scripts/Entrypoints.ps1 new file mode 100644 index 00000000..fc4c3b04 --- /dev/null +++ b/scripts/Windows/Scripts/Entrypoints.ps1 @@ -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."; +} \ No newline at end of file