Created
April 22, 2021 00:25
-
-
Save awakecoding/f1147a80373d6bc691e9896b031fa1e5 to your computer and use it in GitHub Desktop.
Windows Alpine Overlay Expand/Compress functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Expand-AlpineOverlay | |
{ | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true,Position=0)] | |
[string] $InputFile, | |
[Parameter(Mandatory=$true,Position=1)] | |
[string] $Destination, | |
[switch] $Force | |
) | |
if (Test-Path $Destination) { | |
if ($Force) { | |
Remove-Item $Destination -Recurse -ErrorAction SilentlyContinue | Out-Null | |
} else { | |
throw "`"$Destination`" already exists!" | |
} | |
} | |
cmd.exe /c "7z.exe x $InputFile -so | 7z x -si -ttar -o`"$Destination`"" | |
Push-Location | |
Set-Location $Destination | |
$RootPath = Get-Item . | |
$ReparsePoints = Get-ChildItem . -Recurse | ` | |
Where-Object { $_.Attributes -band [IO.FileAttributes]::ReparsePoint } | |
$ReparsePoints | ForEach-Object { | |
$Source = $_.FullName | |
$Target = $_.Target.Replace('/','\') | |
$Target = $Target.Substring($RootPath.FullName.Length) | |
Push-Location | |
Set-Location $_.Directory | |
Remove-Item $Source | |
New-Item -ItemType SymbolicLink -Path $Source -Target $Target | |
Pop-Location | |
} | |
Pop-Location | |
} | |
function Compress-AlpineOverlay | |
{ | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true,Position=0)] | |
[string] $InputPath, | |
[Parameter(Mandatory=$true,Position=1)] | |
[string] $Destination, | |
[switch] $Force | |
) | |
if (-Not (Test-Path $InputPath -PathType 'Container')) { | |
throw "`"$InputPath`" does not exist or is not a directory" | |
} | |
if (-Not $Destination.EndsWith(".tar.gz")) { | |
throw "`"$Destination`" does not end in .tar.gz" | |
} | |
if (-Not $Destination.EndsWith(".apkovl.tar.gz")) { | |
Write-Warning -Message "`"$Destination`" does not end in .apkovl.tar.gz" | |
} | |
if (Test-Path $Destination) { | |
if ($Force) { | |
Remove-Item $Destination -ErrorAction SilentlyContinue | Out-Null | |
} else { | |
throw "VM `"$Destination`" already exists!" | |
} | |
} | |
$TarFileName = $Destination.TrimEnd(".gz") | Split-Path -Leaf | |
cmd.exe /c "7z a -ttar -snl -so $TarFileName `"$InputPath/*`" | 7z a -si $Destination" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment