package defintion improvements

Added CmdletExists and AppExeExists conditions
Cleanup of existing package description files
This commit is contained in:
lksz 2021-04-16 17:07:00 +00:00
parent 2b51f37cb7
commit c9d13f5c4d
8 changed files with 20 additions and 27 deletions

View File

@ -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"

View File

@ -2,11 +2,7 @@
"package": {
"Condition": [
{
"custom": "Get-Command ansible -Type Application",
"System": null,
"Hostname": null,
"Username": null,
"Logic": 0
"AppExeExists": "ansible"
}
],
"Name": "ansible"

View File

@ -3,13 +3,9 @@
"Name": "base.win",
"Condition": [
{
"custom": null,
"System": [
"Desktop"
],
"Hostname": null,
"Username": null,
"Logic": 0
]
}
]
}

View File

@ -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

View File

@ -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))))
}

View File

@ -2,11 +2,7 @@
"package": {
"Condition": [
{
"custom": "Get-Command docker -Type Application",
"System": null,
"Hostname": null,
"Username": null,
"Logic": 0
"AppExeExists": "docker"
}
],
"Name": "docker"

View File

@ -2,11 +2,7 @@
"package": {
"Condition": [
{
"custom": "Get-Command git -Type Application",
"System": null,
"Hostname": null,
"Username": null,
"Logic": 0
"AppExeExists": "git"
}
],
"Name": "git"

Binary file not shown.