From 32927260bdf1e4573f4eb18a281b1fc1573e5da6 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sat, 18 Jan 2025 14:03:58 +0100 Subject: [PATCH] Added install-h2static.ps1 --- scripts/install-h2static.ps1 | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/install-h2static.ps1 diff --git a/scripts/install-h2static.ps1 b/scripts/install-h2static.ps1 new file mode 100755 index 00000000..6d9ef0a5 --- /dev/null +++ b/scripts/install-h2static.ps1 @@ -0,0 +1,41 @@ +<# +.SYNOPSIS + Installs h2static +.DESCRIPTION + This PowerShell script installs the tiny static Web server 'h2static'. +.EXAMPLE + PS> ./install-h2static.ps1 +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +param([int]$port = 8070, [string]$pathToMedia = "/media/") + +try { + $stopWatch = [system.diagnostics.stopwatch]::startNew() + + if (-not($IsLinux)) { throw "Sorry, only Linux installation currently supported" } + + "⏳ (1/4) Installing h2static from Snap Store..." + & sudo snap install h2static + + $pathToMedia = Resolve-Path $pathToMedia + "⏳ (2/4) Configuring serve-path = $pathToMedia ..." + & sudo snap set h2static serve-path=$pathToMedia + & sudo snap connect h2static:removable-media + + "⏳ (3/4) Configuring disable-index = false..." + & sudo snap set h2static disable-index=false + + "⏳ (4/4) Configuring listening-port = :$port..." + & sudo snap set h2static listen=:$port + + [int]$elapsed = $stopWatch.Elapsed.TotalSeconds + "✅ h2static installed in $($elapsed)s, Web server runs at :$port, execute 'snap info h2static' for details." + exit 0 # success +} catch { + "Sorry: $($Error[0])" + exit 1 +}