61 lines
2.1 KiB
PowerShell
61 lines
2.1 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$SourcePath,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$InstallPath,
|
|
|
|
[string]$EventSource = "HostAvailabilityMonitor",
|
|
[string]$EventLogName = "Application",
|
|
[switch]$RegisterEventSource,
|
|
[switch]$CreateBackup
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function Write-Info {
|
|
param([string]$Message)
|
|
Write-Host "[INFO] $Message"
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath $SourcePath)) {
|
|
throw "SourcePath '$SourcePath' existiert nicht."
|
|
}
|
|
|
|
$sourceFullPath = (Resolve-Path -LiteralPath $SourcePath).Path
|
|
$installFullPath = [System.IO.Path]::GetFullPath($InstallPath)
|
|
|
|
Write-Info "Quelldateien: $sourceFullPath"
|
|
Write-Info "Zielverzeichnis: $installFullPath"
|
|
|
|
if (Test-Path -LiteralPath $installFullPath) {
|
|
if ($CreateBackup) {
|
|
$backupRoot = Join-Path -Path ([System.IO.Path]::GetDirectoryName($installFullPath)) -ChildPath ((Split-Path -Path $installFullPath -Leaf) + '_backup_' + (Get-Date -Format 'yyyyMMdd_HHmmss'))
|
|
Write-Info "Erstelle Backup unter $backupRoot"
|
|
Copy-Item -Path (Join-Path $installFullPath '*') -Destination $backupRoot -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
else {
|
|
New-Item -Path $installFullPath -ItemType Directory | Out-Null
|
|
}
|
|
|
|
Write-Info "Kopiere Dateien..."
|
|
Copy-Item -Path (Join-Path $sourceFullPath '*') -Destination $installFullPath -Recurse -Force
|
|
|
|
New-Item -Path (Join-Path $installFullPath 'logs') -ItemType Directory -Force | Out-Null
|
|
New-Item -Path (Join-Path $installFullPath 'state') -ItemType Directory -Force | Out-Null
|
|
|
|
if ($RegisterEventSource) {
|
|
$registerScript = Join-Path -Path $PSScriptRoot -ChildPath 'register-event-source.ps1'
|
|
if (-not (Test-Path -LiteralPath $registerScript)) {
|
|
throw "register-event-source.ps1 wurde nicht gefunden: $registerScript"
|
|
}
|
|
|
|
Write-Info "Registriere Event Source '$EventSource' im Log '$EventLogName'"
|
|
& $registerScript -Source $EventSource -LogName $EventLogName
|
|
}
|
|
|
|
Write-Info 'Installation abgeschlossen.'
|
|
Write-Info "Prüfen Sie nun appsettings.json, Task Scheduler und Servicekonto-Berechtigungen."
|