PowerShell/docs/install-h2static.md
2025-01-23 12:15:35 +01:00

94 lines
2.3 KiB
Markdown

The *install-h2static.ps1* Script
===========================
This PowerShell script installs the tiny static Web server 'h2static'.
Parameters
----------
```powershell
/Repos/PowerShell/scripts/install-h2static.ps1 [[-port] <Int32>] [[-pathToMedia] <String>] [<CommonParameters>]
-port <Int32>
Required? false
Position? 1
Default value 8070
Accept pipeline input? false
Accept wildcard characters? false
-pathToMedia <String>
Required? false
Position? 2
Default value /media/
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
Example
-------
```powershell
PS> ./install-h2static.ps1
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
Script Content
--------------
```powershell
<#
.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
}
```
*(page generated by convert-ps2md.ps1 as of 01/23/2025 12:15:21)*