From c9d13f5c4d876fe60644a89628fef5f135dd2325 Mon Sep 17 00:00:00 2001 From: lksz Date: Fri, 16 Apr 2021 17:07:00 +0000 Subject: [PATCH] package defintion improvements Added CmdletExists and AppExeExists conditions Cleanup of existing package description files --- 7zip/_.package.json | 6 +----- ansible/_.package.json | 6 +----- base.win/_.package.json | 6 +----- base/Add-PackageCondition.ps1 | 8 ++++++-- base/src/Packagesz.class.inc.ps1 | 9 +++++++++ docker/_.package.json | 6 +----- git/_.package.json | 6 +----- scoop/_.package.json | Bin 1238 -> 758 bytes 8 files changed, 20 insertions(+), 27 deletions(-) diff --git a/7zip/_.package.json b/7zip/_.package.json index e5a62e8..7b33a9e 100644 --- a/7zip/_.package.json +++ b/7zip/_.package.json @@ -2,11 +2,7 @@ "package": { "Condition": [ { - "custom": "Get-Command 7z | Where-Object CommandType -eq 'Application'", - "System": null, - "Hostname": null, - "Username": null, - "Logic": 0 + "AppExeExists": "7z" } ], "Name": "7zip" diff --git a/ansible/_.package.json b/ansible/_.package.json index 08b8b1a..9506815 100644 --- a/ansible/_.package.json +++ b/ansible/_.package.json @@ -2,11 +2,7 @@ "package": { "Condition": [ { - "custom": "Get-Command ansible -Type Application", - "System": null, - "Hostname": null, - "Username": null, - "Logic": 0 + "AppExeExists": "ansible" } ], "Name": "ansible" diff --git a/base.win/_.package.json b/base.win/_.package.json index b1f2cf8..cc175ac 100644 --- a/base.win/_.package.json +++ b/base.win/_.package.json @@ -3,13 +3,9 @@ "Name": "base.win", "Condition": [ { - "custom": null, "System": [ "Desktop" - ], - "Hostname": null, - "Username": null, - "Logic": 0 + ] } ] } diff --git a/base/Add-PackageCondition.ps1 b/base/Add-PackageCondition.ps1 index 34a57b0..848d6b3 100644 --- a/base/Add-PackageCondition.ps1 +++ b/base/Add-PackageCondition.ps1 @@ -5,7 +5,9 @@ [ScriptBlock]$CustomCondition, [string[]]$System = $null, [string[]]$Hostname = $null, - [string[]]$Username = $null + [string[]]$Username = $null, + [string[]]$CmdletExists = $null, + [string[]]$AppExeExists = $null ) process { @@ -13,7 +15,9 @@ process { $newCond.custom = $CustomCondition $newCond.System = $System $newCond.Hostname = $Hostname - $newCond.Username = $null + $newCond.Username = $Username + $newCond.CmdletExists = $CmdletExists + $newCond.AppExeExists = $AppExeExists $newCond.Logic = [szLogic]::and $InputObject.Condition += $newCond diff --git a/base/src/Packagesz.class.inc.ps1 b/base/src/Packagesz.class.inc.ps1 index b50da69..26a9f3e 100644 --- a/base/src/Packagesz.class.inc.ps1 +++ b/base/src/Packagesz.class.inc.ps1 @@ -23,6 +23,7 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator { $local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot) $local:currentSys = [SystemName]::_GetValidValues('',$true,$true); $local:hostname = $(hostname) + $local:allCmdlets = Get-Command | Select-Object -ExpandProperty Name $local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } ) @@ -39,6 +40,14 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator { if( $v -and $c.Username ) { $v = $v -and $($c.Username | Where-Object { $username -match $_ }) } + if( $v -and $c.CmdletExists ) { + $v = $v -and -not $($c.CmdletExists | Where-Object { $allCmdlets -notcontains $_ }) + } + if( $v -and $c.AppExeExists ) { + $v = $v -and -not $($c.AppExeExists | Where-Object { + -not ( Get-Command $_ -Type Application -ErrorAction SilentlyContinue ) + }) + } if( $v -and $c.custom ) { $v = $v -and ([bool]$(& ([ScriptBlock]::Create($c.custom)))) } diff --git a/docker/_.package.json b/docker/_.package.json index d790eb8..ef463e3 100644 --- a/docker/_.package.json +++ b/docker/_.package.json @@ -2,11 +2,7 @@ "package": { "Condition": [ { - "custom": "Get-Command docker -Type Application", - "System": null, - "Hostname": null, - "Username": null, - "Logic": 0 + "AppExeExists": "docker" } ], "Name": "docker" diff --git a/git/_.package.json b/git/_.package.json index fa2c07c..f1e1bb6 100644 --- a/git/_.package.json +++ b/git/_.package.json @@ -2,11 +2,7 @@ "package": { "Condition": [ { - "custom": "Get-Command git -Type Application", - "System": null, - "Hostname": null, - "Username": null, - "Logic": 0 + "AppExeExists": "git" } ], "Name": "git" diff --git a/scoop/_.package.json b/scoop/_.package.json index 8c4ee64f0c872896791335ed598c20ca6cf7d955..8390926a968531855ed6148604a5dc307ce3a0b9 100644 GIT binary patch delta 14 Vcmcb{`Hgjh7SqH-0h6OxY5*=#1;+pY delta 166 zcmeyydW~~~789e+#Djqo9XRBb7=jrp8HyQ77*ZK>8I%~T7!-gokD-(y2MD36l$97f w81liY@)#0<>QeEj3