-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathGet-OPNsenseImage.ps1
50 lines (38 loc) · 1.38 KB
/
Get-OPNsenseImage.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
[CmdletBinding()]
param(
[string]$OutputPath
)
$ErrorActionPreference = 'Stop'
$urlRoot = 'https://mirror.dns-root.de/opnsense/releases/mirror/'
$urlFile = 'OPNsense-23.7-dvd-amd64.iso.bz2'
$url = "$urlRoot/$urlFile"
if (-not $OutputPath) {
$OutputPath = Get-Item '.\'
}
$isoFile = Join-Path $OutputPath $urlFile
$uncompressedUrlFile = [System.IO.Path]::GetFileNameWithoutExtension($urlFile)
$uncompressedIsoFile = Join-Path $OutputPath $uncompressedUrlFile
if ([System.IO.File]::Exists($uncompressedIsoFile)) {
Write-Verbose "File '$uncompressedIsoFile' already exists. Nothing to do."
} else {
if ([System.IO.File]::Exists($isoFile)) {
Write-Verbose "File '$isoFile' already exists."
} else
{
Write-Verbose "Downloading file '$isoFile'..."
$client = New-Object System.Net.WebClient
$client.DownloadFile($url, $isoFile)
}
$7zCommand = Get-Command "7z.exe" -ErrorAction SilentlyContinue
if (-not $7zCommand)
{
throw "7z.exe not found. Please install it with 'choco install 7zip -y'."
}
Write-Verbose "Extracting file '$isoFile' to '$OutputPath'..."
& 7z.exe e $isoFile "-o$($OutputPath)" | Out-Null
$fileExists = Test-Path -Path $uncompressedisoFile
if (-not $fileExists) {
throw "Image '$uncompressedUrlFile' not found after extracting .bz2 file."
}
}
$uncompressedIsoFile