74 lines
3.4 KiB
PowerShell
74 lines
3.4 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
Vorbereitung auf dem Windows-Verwaltungsrechner. Keine Serverzugriffe.
|
|
Beispiel: .\PreScript.ps1 -Platform Windows
|
|
Prueft nur vorhandene Ordner und Dateien. Bei Erfolg wird das Hauptskript gestartet.
|
|
Fehlende Ordner und Dateien muessen vorab bereitgestellt werden.
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[ValidateSet('Windows','Linux','Both')]
|
|
[string]$Platform = 'Windows',
|
|
[string]$BasePath = 'C:\SCAN'
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
try {
|
|
$scriptFolder = Join-Path $BasePath 'SCRIPT'
|
|
$sourceFolder = Join-Path $BasePath 'NDTRACK'
|
|
$resultFolder = Join-Path $BasePath 'RESULTS'
|
|
$logFolder = Join-Path $scriptFolder 'Logs'
|
|
foreach ($path in @($scriptFolder,$sourceFolder,$resultFolder,$logFolder)) {
|
|
if (Test-Path -LiteralPath $path) {
|
|
if (-not (Test-Path -LiteralPath $path -PathType Container)) {
|
|
throw "Pfad ist eine Datei statt eines Ordners: $path"
|
|
}
|
|
Write-Host "VORHANDEN: $path"
|
|
} else {
|
|
throw "Benoetigter Ordner fehlt: $path. Bitte vor dem Start bereitstellen."
|
|
}
|
|
}
|
|
|
|
$issues = [System.Collections.Generic.List[string]]::new()
|
|
$mainScript = Join-Path $scriptFolder 'NDTrack-Geprueft.ps1'
|
|
if (-not (Test-Path -LiteralPath $mainScript -PathType Leaf)) {
|
|
$issues.Add("Hauptskript fehlt: $mainScript. Bitte die erstellte Skriptdatei dorthin kopieren.")
|
|
} elseif ((Get-Item -LiteralPath $mainScript).Length -eq 0) {
|
|
$issues.Add("Hauptskript ist leer: $mainScript")
|
|
} else {
|
|
$tokens=$null; $parseErrors=$null
|
|
[void][System.Management.Automation.Language.Parser]::ParseFile($mainScript,[ref]$tokens,[ref]$parseErrors)
|
|
if ($parseErrors.Count) { $issues.Add("Hauptskript enthaelt PowerShell-Syntaxfehler: $($parseErrors -join '; ')") }
|
|
}
|
|
|
|
$files = @(Get-ChildItem -LiteralPath $sourceFolder -File -Recurse -Force)
|
|
if (-not $files.Count) {
|
|
$issues.Add("Keine Dateien in $sourceFolder. Bitte das vollstaendige NDTrack-Paket entpackt dort ablegen; leere Unterordner reichen nicht aus.")
|
|
} else {
|
|
Write-Host "DATEIEN: $($files.Count) in $sourceFolder (inklusive Unterordner)."
|
|
}
|
|
$launchers = @()
|
|
if ($Platform -in @('Windows','Both')) { $launchers += 'RunNdTrackWindows_Local.cmd' }
|
|
if ($Platform -in @('Linux','Both')) { $launchers += 'RunNdTrackLinuxUnix_Local.sh' }
|
|
foreach ($name in $launchers) {
|
|
$path = Join-Path $sourceFolder $name
|
|
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
|
|
$issues.Add("Startdatei fehlt direkt im Quellordner: $path")
|
|
} elseif ((Get-Item -LiteralPath $path).Length -eq 0) {
|
|
$issues.Add("Startdatei ist leer: $path")
|
|
} else { Write-Host "STARTDATEI VORHANDEN: $name" }
|
|
}
|
|
if ($issues.Count) {
|
|
foreach ($issue in $issues) { Write-Warning $issue }
|
|
Write-Host 'VORBEREITUNG UNVOLLSTAENDIG. Fehlende Dateien ergaenzen und PreScript erneut ausfuehren.' -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
Write-Host 'VORBEREITUNG OK: Ordner und benoetigte Startdateien vorhanden; Hauptskript syntaktisch gueltig.' -ForegroundColor Green
|
|
Write-Host 'Paketvollstaendigkeit, CMD-/SH-Inhalt und Zielserver-Erreichbarkeit wurden nicht geprueft.'
|
|
Write-Host "Starte Hauptskript: $mainScript"
|
|
& $mainScript
|
|
exit 0
|
|
} catch {
|
|
Write-Warning "Vorbereitung fehlgeschlagen: $($_.Exception.Message)"
|
|
exit 1
|
|
}
|