Fix mit ScriptVersion im Skript

This commit is contained in:
2026-04-09 16:49:23 +02:00
parent aacdd9c39f
commit facccc8ac4

View File

@@ -6,11 +6,11 @@ param(
<#
.SYNOPSIS
KANBAN-Rational-Druck mit Self-Update, Private-Config-Ladung, SQL-Abfrage und n8n-Webhook.
KANBAN-Rational-Druck mit Versionspruefung, Self-Update, Private-Config-Ladung, SQL-Abfrage und n8n-Webhook.
.DESCRIPTION
Ablauf:
1. Optional Self-Update aus dem Public-Repo
1. Optional Self-Update aus dem Public-Repo per Versionsvergleich
2. AZ_GITHUB_TOKEN pruefen
3. Private Konfiguration aus dem Private-Repo laden
4. Genau eine Datei aus Input-Ordner lesen
@@ -25,6 +25,7 @@ param(
$ErrorActionPreference = 'Stop'
$script:ScriptName = 'KANBAN-Rational-Druck'
$script:ScriptVersion = '1.0.0'
$script:PublicRawUrl = 'https://git.az-gruppe.com/AZ-Intec-GmbH/AZ-PowerShell-Pub/raw/branch/main/scripts/KANBAN-Rational-Druck/KANBAN-Rational-Druck.ps1'
$script:PrivateRawUrl = 'https://git.az-gruppe.com/AZ-Intec-GmbH/AZ-PowerShell-Prv/raw/branch/main/scripts/KANBAN-Rational-Druck/KANBAN-Rational-Druck.ps1'
$script:LogFilePath = $null
@@ -67,25 +68,6 @@ function Write-Log
}
}
function Get-StringHashSha256
{
param(
[Parameter(Mandatory = $true)]
[string]$Text
)
$sha = [System.Security.Cryptography.SHA256]::Create()
try
{
$bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)
$hashBytes = $sha.ComputeHash($bytes)
return ([System.BitConverter]::ToString($hashBytes)).Replace('-', '')
} finally
{
$sha.Dispose()
}
}
function Test-AzGithubToken
{
if ([string]::IsNullOrWhiteSpace($env:AZ_GITHUB_TOKEN))
@@ -94,6 +76,22 @@ function Test-AzGithubToken
}
}
function Get-ScriptVersionFromContent
{
param(
[Parameter(Mandatory = $true)]
[string]$Content
)
$match = [regex]::Match($Content, "\`$script:ScriptVersion\s*=\s*'([^']+)'")
if (-not $match.Success)
{
throw "ERROR: ScriptVersion konnte aus dem Remote-Skript nicht gelesen werden."
}
return $match.Groups[1].Value
}
function Start-SelfUpdateIfNeeded
{
param(
@@ -125,12 +123,12 @@ function Start-SelfUpdateIfNeeded
throw "Remote-Skriptinhalt ist leer."
}
$localContent = Get-Content -Path $localScriptPath -Raw -Encoding UTF8
$remoteVersion = Get-ScriptVersionFromContent -Content $remoteContent
$localVersion = $script:ScriptVersion
$localHash = Get-StringHashSha256 -Text $localContent
$remoteHash = Get-StringHashSha256 -Text $remoteContent
Write-ConsoleLog "Lokale Version: $localVersion | Remote Version: $remoteVersion" "INFO"
if ($localHash -eq $remoteHash)
if ($remoteVersion -eq $localVersion)
{
Write-ConsoleLog "OK: Public-Skript ist bereits aktuell." "SUCCESS"
return