This commit is contained in:
Rodweil, Theodor 2023-07-30 16:16:55 +02:00
commit 17266ecb99
No known key found for this signature in database
GPG key ID: F8BC1B0EB1F9CCF5
30 changed files with 1731 additions and 0 deletions

View file

@ -0,0 +1,74 @@
#!/usr/bin/env pwsh
$ErrorActionPreference = "Stop"
$script:schema = Get-Content (
Join-Path $PSScriptRoot 'manifest.schema.json'
) | Out-String
function Get-Manifest
{
<#
.SYNOPSIS
Load the archive manifest
.EXAMPLE
Get-Manifest 'manifest.json'
#>
Param(
# filesystem location of manifest
[Parameter(Mandatory)] [string] $File
)
Process
{
try
{
$raw = Get-Content $File
}
catch
{
$raw = '{"pages":{}, "attachments": {}}'
}
$raw | Test-JSON -Schema $script:schema | Out-Null
$data = $raw | ConvertFrom-JSON
}
}
function Set-Manifest
{
<#
.SYNOPSIS
Dump the archive manifest
.EXAMPLE
Set-Manifest 'manifest.json'
#>
Param(
# manifest object
[Parameter(Mandatory)] [PSObject] $Manifest,
# filesystem location of manifest
[Parameter(Mandatory)] [string] $File,
# create a backup first
[Parameter()] [bool] $Backup = $false
)
Process
{
$raw = $Manifest | ConvertTo-JSON
$raw | Test-JSON -Schema $script:schema
if ($Backup)
{
Copy-Item -Path $File -Destination "$(Split-Path -Leaf $File).bck"
}
Set-Content -Path $File -Value $raw
}
}