init
This commit is contained in:
1 parent
6c1c651839
commit
ee6d5b9b1e
5 files changed
+364
-2
No files matched your search
@@ -3,11 +3,14 @@
|
||||
.SYNOPSIS
|
||||
Stellt bestehende Scoop-Installationen von elexis/streichtech auf medelexis um.
|
||||
.DESCRIPTION
|
||||
Ohne -Apply nur ein Probelauf. Keine Sicherungen, Neuinstallationen oder Git-Pushes.
|
||||
Ohne -Apply nur ein Probelauf. Keine Sicherungen oder Git-Pushes.
|
||||
Bearbeitet alle Versionsverzeichnisse der benutzerspezifischen Scoop-Installation.
|
||||
Ein passender bestehender Bucket wird umbenannt. Danach werden elexis und streichtech entfernt.
|
||||
Andere Buckets wie main und extras bleiben bestehen.
|
||||
Alte Paketnamen mit Unterstrich werden auf passende Manifestnamen mit Bindestrich umgestellt.
|
||||
ee-iso/ee_iso und ee-cli werden deinstalliert. MyElexis CLI wird neu installiert.
|
||||
Mit -Apply wird abschliessend gefragt, ob taegliche Auto-Updates um 03:00 Uhr
|
||||
eingerichtet werden sollen. Das separate Skript wird aus dem Repository geladen.
|
||||
.EXAMPLE
|
||||
.\scripts\update-bucket.ps1
|
||||
.EXAMPLE
|
||||
@@ -40,6 +43,7 @@ function Test-MedelexisRepository([string] $Path) {
|
||||
function Get-PackageRenames([string] $BucketPath) {
|
||||
if (-not $BucketPath -or -not (Test-Path -LiteralPath $BucketPath)) { return }
|
||||
foreach ($app in Get-ChildItem -LiteralPath $apps -Directory) {
|
||||
if ($app.Name -in @('ee-iso', 'ee_iso')) { continue }
|
||||
if (-not $app.Name.Contains('_')) { continue }
|
||||
$newName = $app.Name.Replace('_', '-')
|
||||
$newManifest = Join-Path $BucketPath "bucket\$newName.json"
|
||||
@@ -78,6 +82,19 @@ function Get-PackageRenames([string] $BucketPath) {
|
||||
}
|
||||
}
|
||||
|
||||
$installCli = (Test-Path -LiteralPath (Join-Path $apps 'ee-cli')) -or
|
||||
-not (Test-Path -LiteralPath (Join-Path $apps 'myelexis-cli'))
|
||||
$obsoleteApps = @(@('ee-iso', 'ee_iso', 'ee-cli') | Where-Object {
|
||||
Test-Path -LiteralPath (Join-Path $apps $_)
|
||||
})
|
||||
if ($installCli -and (Test-Path -LiteralPath (Join-Path $apps 'myelexis-cli'))) {
|
||||
$obsoleteApps += 'myelexis-cli'
|
||||
}
|
||||
foreach ($obsolete in $obsoleteApps) {
|
||||
Write-Host "Veraltetes Paket deinstallieren: $obsolete"
|
||||
}
|
||||
if ($installCli) { Write-Host 'MyElexis CLI wird aus medelexis neu installiert.' }
|
||||
|
||||
$renameSource = $null
|
||||
if (Test-Path -LiteralPath $target) {
|
||||
if (-not (Test-MedelexisRepository $target)) {
|
||||
@@ -98,6 +115,7 @@ if (Test-Path -LiteralPath $target) {
|
||||
|
||||
$changes = @(
|
||||
foreach ($app in Get-ChildItem -LiteralPath $apps -Directory) {
|
||||
if ($app.Name -in $obsoleteApps) { continue }
|
||||
foreach ($version in Get-ChildItem -LiteralPath $app.FullName -Directory) {
|
||||
# current und andere Verknüpfungen nicht nochmals bearbeiten.
|
||||
if ($version.Attributes -band [IO.FileAttributes]::ReparsePoint) { continue }
|
||||
@@ -127,10 +145,17 @@ if (-not $Apply) {
|
||||
}
|
||||
Write-Host "Probelauf: $($changes.Count) install.json-Dateien würden geändert."
|
||||
Write-Host "Probelauf: $($renames.Count) Paketnamen würden umgestellt."
|
||||
Write-Host "Probelauf: $(@($obsoleteApps).Count) alte Pakete würden deinstalliert."
|
||||
Write-Host 'Mit -Apply wird optional ein Auto-Update um 03:00 Uhr mit Nachholen eingerichtet (y/n).'
|
||||
Write-Host 'Mit -Apply anwenden. Es werden keine Sicherungen erstellt.'
|
||||
return
|
||||
}
|
||||
|
||||
$activeRoot = $(if ($env:SCOOP) { $env:SCOOP } else { Join-Path $env:USERPROFILE 'scoop' })
|
||||
if ([IO.Path]::GetFullPath($ScoopRoot).TrimEnd('\') -ne [IO.Path]::GetFullPath($activeRoot).TrimEnd('\')) {
|
||||
throw 'ScoopRoot muss der aktiven Scoop-Installation entsprechen.'
|
||||
}
|
||||
|
||||
if (-not (Test-Path -LiteralPath $target)) {
|
||||
if ($renameSource) {
|
||||
$bucketRoot = (Resolve-Path -LiteralPath (Join-Path $ScoopRoot 'buckets')).Path
|
||||
@@ -166,6 +191,27 @@ foreach ($change in $changes) {
|
||||
foreach ($change in $changes) {
|
||||
[IO.File]::WriteAllText($change.File, $change.Updated, [Text.UTF8Encoding]::new($false))
|
||||
}
|
||||
if ($installCli -and -not (Test-Path -LiteralPath (Join-Path $target 'bucket\myelexis-cli.json')) -and
|
||||
-not (Test-Path -LiteralPath (Join-Path $target 'myelexis-cli.json'))) {
|
||||
throw 'Manifest myelexis-cli fehlt im Ziel-Bucket. Keine Deinstallation.'
|
||||
}
|
||||
foreach ($obsolete in $obsoleteApps) {
|
||||
$activeRoot = $(if ($env:SCOOP) { $env:SCOOP } else { Join-Path $env:USERPROFILE 'scoop' })
|
||||
if ([IO.Path]::GetFullPath($ScoopRoot).TrimEnd('\') -ne [IO.Path]::GetFullPath($activeRoot).TrimEnd('\')) {
|
||||
throw 'Für Deinstallationen muss ScoopRoot der aktiven Scoop-Installation entsprechen.'
|
||||
}
|
||||
& scoop uninstall $obsolete
|
||||
if ($LASTEXITCODE -ne 0 -or (Test-Path -LiteralPath (Join-Path $apps $obsolete))) {
|
||||
throw "'$obsolete' konnte nicht deinstalliert werden."
|
||||
}
|
||||
}
|
||||
if ($installCli) {
|
||||
Write-Host 'MyElexis CLI aus medelexis neu installieren ...'
|
||||
& scoop install 'medelexis/myelexis-cli'
|
||||
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath (Join-Path $apps 'myelexis-cli\current\myelexis-cli.exe'))) {
|
||||
throw 'MyElexis CLI konnte nicht vollständig installiert werden.'
|
||||
}
|
||||
}
|
||||
foreach ($rename in $renames) {
|
||||
$activeRoot = $(if ($env:SCOOP) { $env:SCOOP } else { Join-Path $env:USERPROFILE 'scoop' })
|
||||
if ([IO.Path]::GetFullPath($ScoopRoot).TrimEnd('\') -ne [IO.Path]::GetFullPath($activeRoot).TrimEnd('\')) {
|
||||
@@ -222,3 +268,47 @@ foreach ($name in @((Get-ChildItem -LiteralPath $apps -Directory).Name)) {
|
||||
Write-Host "Fertig: $($changes.Count) install.json-Dateien auf medelexis umgestellt."
|
||||
Write-Host "Paketnamen umgestellt: $($renames.Count)."
|
||||
Write-Host 'Von elexis/streichtech/medelexis bleibt nur medelexis bestehen. Prüfung: scoop status --local'
|
||||
|
||||
do {
|
||||
$autoUpdateAnswer = (Read-Host 'Scoop Auto-Update einschalten? [y/n]').Trim().ToLowerInvariant()
|
||||
} while ($autoUpdateAnswer -notin @('y', 'n'))
|
||||
|
||||
if ($autoUpdateAnswer -eq 'y') {
|
||||
$autoUpdateDirectory = Join-Path $ScoopRoot 'scripts\medelexis'
|
||||
New-Item -ItemType Directory -Path $autoUpdateDirectory -Force | Out-Null
|
||||
$autoUpdateScript = Join-Path $autoUpdateDirectory 'auto-update.ps1'
|
||||
$downloadPath = Join-Path $autoUpdateDirectory ('auto-update-{0}.download' -f [guid]::NewGuid())
|
||||
try {
|
||||
$autoUpdateUrl = "$repository/raw/branch/master/scripts/auto-update.ps1"
|
||||
Invoke-WebRequest -Uri $autoUpdateUrl -OutFile $downloadPath -UseBasicParsing
|
||||
$parseTokens = $null
|
||||
$parseErrors = $null
|
||||
$downloadedScript = [Management.Automation.Language.Parser]::ParseFile($downloadPath, [ref] $parseTokens, [ref] $parseErrors)
|
||||
if ($parseErrors.Count -gt 0 -or -not $downloadedScript.ParamBlock -or
|
||||
'ScoopRoot' -notin @($downloadedScript.ParamBlock.Parameters.Name.VariablePath.UserPath)) {
|
||||
throw 'Das heruntergeladene Auto-Update-Skript ist kein gueltiges Updateskript.'
|
||||
}
|
||||
Move-Item -LiteralPath $downloadPath -Destination $autoUpdateScript -Force
|
||||
# Nur die Aufgabe einrichten; das Updateskript wird durch die Aufgabe gestartet.
|
||||
$userId = [Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||
$userSid = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value
|
||||
$taskName = "Medelexis-Scoop-AutoUpdate-$userSid"
|
||||
$powershell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
||||
$arguments = '-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File "{0}" -ScoopRoot "{1}"' -f $autoUpdateScript, $ScoopRoot
|
||||
$action = New-ScheduledTaskAction -Execute $powershell -Argument $arguments
|
||||
$trigger = New-ScheduledTaskTrigger -Daily -At '03:00'
|
||||
$principal = New-ScheduledTaskPrincipal -UserId $userId -LogonType Interactive -RunLevel Limited
|
||||
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -RunOnlyIfNetworkAvailable `
|
||||
-AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -MultipleInstances IgnoreNew `
|
||||
-ExecutionTimeLimit (New-TimeSpan -Hours 4)
|
||||
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger `
|
||||
-Principal $principal -Settings $settings -Force `
|
||||
-Description 'Scoop taeglich um 03:00 aktualisieren; verpasste Termine nachholen; elexis* auf hold setzen.' | Out-Null
|
||||
Write-Host "Scoop Auto-Update eingeschaltet: $taskName (taeglich 03:00, verpasste Termine nachholen)."
|
||||
Write-Host "Ausfuehrung verborgen unter $userId, sobald der Benutzer angemeldet ist; kein Aufwecken des PCs."
|
||||
} finally {
|
||||
if (Test-Path -LiteralPath $downloadPath) { Remove-Item -LiteralPath $downloadPath }
|
||||
}
|
||||
} else {
|
||||
Write-Host 'Auto-Update nicht eingerichtet. Eine eventuell bestehende Aufgabe bleibt unveraendert.'
|
||||
}
|
||||
Reference in new issue
Block a user