Magick, choco packages + more
This commit is contained in:
parent
0f84a2f136
commit
c8b9f5d2dc
|
@ -0,0 +1,87 @@
|
|||
[CmdletBinding(SupportsShouldProcess,ConfirmImpact="Medium")]param(
|
||||
[Parameter(ParameterSetName="Normal",ValueFromPipeline,ValueFromPipelineByPropertyName)]
|
||||
[string[]]$ImageMagickPath,
|
||||
[Parameter(ParameterSetName="Normal",ValueFromPipelineByPropertyName)]
|
||||
[string]$PageOutputName,
|
||||
[Parameter(ParameterSetName="Normal")]
|
||||
[string]$OutputPath,
|
||||
[Parameter(ParameterSetName="Normal")]
|
||||
[string]$OutputImageFormat = "png",
|
||||
[Parameter(ParameterSetName="Normal")]
|
||||
[string]$OutputImageExtension,
|
||||
[Parameter(ParameterSetName="Normal")]
|
||||
[string[]]$MagickArgs,
|
||||
[Parameter(ParameterSetName="Normal")]
|
||||
[switch]$Force,
|
||||
[Parameter(ParameterSetName="Reset")]
|
||||
[switch]$ResetConfirm
|
||||
)
|
||||
|
||||
BEGIN{
|
||||
if( $ResetConfirm ) {
|
||||
Remove-Variable imagemagick_* -Force
|
||||
Remove-Variable imagemagick_* -Force
|
||||
return
|
||||
}
|
||||
|
||||
if( -not $OutputImageExtension ) {
|
||||
$OutputImageExtension = $OutputImageFormat.ToLower()
|
||||
}
|
||||
$OutputImageExtension = $OutputImageExtension -replace '\.*(.+)$','.$1'
|
||||
|
||||
if( ! (Test-Path variable:global:imagemagick_noToAll) ) {
|
||||
$imagemagick_noToAll = $PSBoundParameters.ContainsKey('WhatIf');
|
||||
$imagemagick_yesToAll = $ConfirmPreference -gt 'Low' -and -not $imagemagick_noToAll
|
||||
}
|
||||
}
|
||||
PROCESS{
|
||||
if( $ResetConfirm ) { return }
|
||||
$ImageMagickPath | ForEach-Object {
|
||||
$local:i = [PSCustomObject]@{
|
||||
ImageMagickPath = $_
|
||||
PageOutputName = $(
|
||||
if( $PageOutputName ) {
|
||||
"$($PageOutputName)$OutputImageExtension"
|
||||
} else {
|
||||
[System.IO.Path]::GetFileName($_) -replace "(\.[A-Z]+)(?:\[(\d+)\])?$",'_$2.' -replace '_?\.$',$OutputImageExtension
|
||||
}
|
||||
)
|
||||
OutputPath = $OutputPath
|
||||
}
|
||||
|
||||
if( -not $i.OutputPath ) {
|
||||
$i.OutputPath = Join-Path ([System.IO.Path]::GetDirectoryName($i.ImageMagickPath)) $OutputImageFormat
|
||||
}
|
||||
|
||||
if( !$imagemagick_noToAll ) { try {
|
||||
if( -not (Test-Path -LiteralPath $i.OutputPath) ) {
|
||||
if( $Force ) {
|
||||
New-Item -ItemType Directory -Path $i.OutputPath -Force
|
||||
} else {
|
||||
throw "Output directory $($i.OutputPath) does not exist!"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Error $_
|
||||
$imagemagick_noToAll = $true
|
||||
return
|
||||
}}
|
||||
|
||||
$local:outFilePath = Join-Path $i.OutputPath $i.PageOutputName
|
||||
$local:magickCmdLine=@("convert",$i.ImageMagickPath)+$MagickArgs+@($outFilePath) | Where-Object {$_}
|
||||
Write-Verbose "$(if( $imagemagick_noToAll ) { "Skipping" } else {"Running"} ): & magick $magickCmdLine"
|
||||
if( $PSCmdlet.ShouldContinue( "Convert", "$($i.ImageMagickPath) to $outFilePath", [ref]$imagemagick_yesToAll, [ref]$imagemagick_noToAll ) ) {
|
||||
& magick $magickCmdLine
|
||||
|
||||
Write-Verbose "Error state: $?"
|
||||
if( $? -and (Test-Path $outFilePath) ) {
|
||||
Get-Item $outFilePath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
END{
|
||||
if( $ResetConfirm ) { return }
|
||||
$global:imagemagick_yesToAll = $imagemagick_yesToAll
|
||||
$global:imagemagick_noToAll = $imagemagick_noToAll
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
[CmdletBinding()]param(
|
||||
[string[]]$SrcPath,
|
||||
[string]$FilePattern="*.tif",
|
||||
[int]$PageNumberDigits=3,
|
||||
[switch]$Force
|
||||
)
|
||||
|
||||
Remove-TypeData -TypeName "ImageMagickPagesz" -ErrorAction Ignore -Confirm:$false
|
||||
Update-TypeData -TypeName "ImageMagickPagesz" -DefaultDisplayPropertySet 'ImageMagickPath', 'Page' -Force -Confirm:$false
|
||||
|
||||
$local:PageNumberFormat="D$PageNumberDigits"
|
||||
Get-ChildItem $(Join-Path $SrcPath $FilePattern) -Force:$Force |
|
||||
ForEach-Object {
|
||||
$local:f = $_;
|
||||
& magick identify $f.FullName | ForEach-Object {
|
||||
$local:p = [ordered]@{
|
||||
PSTypeName = "ImageMagickPagesz"
|
||||
PSFile = $f
|
||||
BaseName = $f.BaseName
|
||||
ImageMagickPath = $_ -ireplace " TIFF \d+x\d+ \d+x\d+\+\d+\+\d .*$",""
|
||||
Page = 0
|
||||
PageOutputName = [string]::Empty
|
||||
}
|
||||
if( $p.ImageMagickPath -match '.*\[(\d+)\]$' ) {
|
||||
$p.Page = $matches[1]
|
||||
}
|
||||
|
||||
$p.Page = $(0+$($p.Page)).ToString($PageNumberFormat)
|
||||
$p.PageOutputName = "$($p.BaseName)_$($p.Page)"
|
||||
|
||||
[PSCustomObject]$p
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,77 @@
|
|||
function readOsInfoConfig{param([string]$Path)
|
||||
Invoke-Expression "[ordered]@{`n$(cat $Path|% { $_ -replace '=([^"''].*[^"''])$','="$1"' }|out-string)}"
|
||||
}
|
||||
|
||||
$local:osInfo = [ordered]@{
|
||||
Icon =
|
||||
Name = ""
|
||||
OS = [Environment]::OSVersion.VersionString -replace 'Windows NT 10','Windows 10'
|
||||
VER = [Environment]::OSVersion.Version.ToString()
|
||||
Platform = [Environment]::OSVersion.Platform
|
||||
}
|
||||
|
||||
if( $osInfo.OS -eq 'Unix' ) {
|
||||
if( Test-Path /etc/os-release ) {
|
||||
$local:tmpInfo = readOsInfoConfig /etc/os-release
|
||||
$osInfo.OS = $tmpInfo.NAME
|
||||
$osInfo.VER = $tmpInfo.VERSION_ID
|
||||
} elseif( Get-Command lsb_release -ErrorAction Ignore ) {
|
||||
$osInfo.OS = & lsb_release -si
|
||||
$osInfo.VER = & lsb_release -sr
|
||||
} elseif( Test-Path /etc/lsb-release ) {
|
||||
$local:tmpInfo = readOsInfoConfig /etc/os-release
|
||||
$osInfo.OS = $tmpInfo.DISTRIB_ID
|
||||
$osInfo.VER = $tmpInfo.DISTRIB_RELEASE
|
||||
} elseif( Test-Path /etc/debian_version ) {
|
||||
$osInfo.OS = "Debian"
|
||||
$osInfo.VER = Get-Content /etc/debian_version
|
||||
} elseif( Test-Path /etc/SuSe-release ) {
|
||||
#readOsInfoConfig /etc/SuSe-release
|
||||
$osInfo.OS = ""
|
||||
$osInfo.VER = ""
|
||||
} elseif( Test-Path /etc/redhat-release ) {
|
||||
#readOsInfoConfig /etc/redhat-release
|
||||
$osInfo.OS = ""
|
||||
$osInfo.VER = ""
|
||||
} else {
|
||||
$osInfo.OS = $(unmae -s)
|
||||
$osInfo.VER = $(unmae -r)
|
||||
}
|
||||
} elseif( $osInfo.OS -ne "MacOSX" ) {
|
||||
$osInfo.OS = {
|
||||
if($osInfo.OS -match "Windows 10")
|
||||
{
|
||||
switch ($buildnumber)
|
||||
{
|
||||
10240 {"Win10 1507"}
|
||||
10586 {"Win10 1511"}
|
||||
14393 {"Win10 1607"}
|
||||
15063 {"Win10 1703"}
|
||||
16299 {"Win10 1709"}
|
||||
17134 {"Win10 1803"}
|
||||
17763 {"Win10 1809"}
|
||||
18362 {"Win10 1903"}
|
||||
18363 {"Win10 1909"}
|
||||
19041 {"Win10 20H1"}
|
||||
19042 {"Win10 20H2"}
|
||||
19043 {"Win10 21H1"}
|
||||
default {"Unkown Win10"}
|
||||
}
|
||||
} elseif ($osInfo.OS -match "Windows Server")
|
||||
{
|
||||
switch ($buildnumber)
|
||||
{
|
||||
3790 {$OS = "Windows Server 2003 R2"}
|
||||
6001 {$OS = "Windows Server 2008"}
|
||||
7600 {$OS = "Windows Server 2008 SP1"}
|
||||
7601 {$OS = "Windows Server 2008 R2"}
|
||||
9200 {$OS = "Windows Server 2012"}
|
||||
9600 {$OS = "Windows Server 2012 R2"}
|
||||
14393 {$OS = "Windows Server 2016"}
|
||||
17763 {$OS = "Windows Server 2019"}
|
||||
}
|
||||
}
|
||||
Write-Host "Server system: $OS | $osversion | $buildnumber" -foregroundcolor Green
|
||||
|
||||
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,5 @@
|
|||
# Chocolatey profile
|
||||
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
||||
if (Test-Path($ChocolateyProfile)) {
|
||||
Import-Module "$ChocolateyProfile"
|
||||
}
|
Loading…
Reference in New Issue