Add a separate script for injecting values into scripts

This commit is contained in:
Manuel Thalmann 2024-07-31 14:55:00 +02:00
parent 90675f3e14
commit be4ee90f7d
2 changed files with 20 additions and 7 deletions

View file

@ -1,5 +1,8 @@
#!/bin/pwsh #!/bin/pwsh
. "$PSScriptRoot/../Scripts/Scripting.ps1";
function Start-Setup { function Start-Setup {
. "$PSScriptRoot/../Scripts/Scripting.ps1";
$Global:InformationPreference = "Continue"; $Global:InformationPreference = "Continue";
$Global:ErrorActionPreference = "Inquire"; $Global:ErrorActionPreference = "Inquire";
$null = $env:WIN_COMPUTER_NAME; $null = $env:WIN_COMPUTER_NAME;
@ -53,14 +56,8 @@ function Start-Setup {
Join-Path $env:REMOTE_PROJECT_PATH $relativePath; Join-Path $env:REMOTE_PROJECT_PATH $relativePath;
} }
function Get-Injection($value) {
"([System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String('$(
[System.Convert]::ToBase64String([System.Text.Encoding]::Default.GetBytes($value))
)')))"
}
function Get-PathInjection($path) { function Get-PathInjection($path) {
"(Join-Path `$env:SystemDrive $(Get-Injection $path))" "(Join-Path `$env:SystemDrive $(ConvertTo-Injection $path))"
} }
function Get-ScriptPathInjection($path) { function Get-ScriptPathInjection($path) {

View file

@ -0,0 +1,16 @@
<#
.SYNOPSIS
Converts the specified value into a form to safle inject it into a script.
.PARAMETER value
The value to convert for injection.
#>
function ConvertTo-Injection {
param(
$Value
)
"([System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String('$(
[System.Convert]::ToBase64String([System.Text.Encoding]::Default.GetBytes($value))
)')))"
}