Some general shortcuts

DockerCompose, Edit AdditionalFiles shortcut #/, #tr and #lsi created
Set-MyPackage -LocalUser / -LocalHost shorthand.
This commit is contained in:
lksz 2021-01-23 21:25:39 -05:00
parent 0b644b7fdd
commit 6549d8683d
2 changed files with 35 additions and 6 deletions

View File

@ -1,14 +1,27 @@
[CmdletBinding(SupportsShouldProcess)]param( [CmdletBinding(SupportsShouldProcess)]param(
[Parameter(mandatory=$true, ValueFromPipeline=$true)] [Parameter(mandatory=$true, ValueFromPipeline=$true, ParameterSetName="Pipe")]
[szPackage]$InputObject, [szPackage]$InputObject,
[Parameter(mandatory=$true, ParameterSetName="LocalHost")]
[switch]$LocalHost,
[Parameter(mandatory=$true, ParameterSetName="LocalUser")]
[switch]$LocalUser,
[switch]$Force, [switch]$Force,
[switch]$PassThru, [switch]$PassThru,
[switch]$DryRun [switch]$DryRun
) )
process { process {
$local:outObj = @{ package = @{ Name = $InputObject.Name; Condition = @() } } $local:iObj = $_
foreach( $local:c in $InputObject.Condition ) { if( $LocalHost ) {
$iObj = New-MyPackage -Name "$(hostname).local" |
Add-PackageCondition -Hostname "$(hostname)"
} elseif( $LocalUser ) {
$iObj = New-MyPackage -Name "$($USER).local" |
Add-PackageCondition -Username $USER
}
Write-Verbose "Set-MyPackage called with $($iObj | Out-String)..."
$local:outObj = @{ package = @{ Name = $iObj.Name; Condition = @() } }
foreach( $local:c in $iObj.Condition ) {
$local:newC = [ordered]@{} $local:newC = [ordered]@{}
foreach( $local:p in $c.PSObject.Properties ) { foreach( $local:p in $c.PSObject.Properties ) {
if( $p.TypeNameOfValue -match 'ScriptBlock' -and $p.Value ) { if( $p.TypeNameOfValue -match 'ScriptBlock' -and $p.Value ) {
@ -22,11 +35,18 @@ process {
$local:jsonOut = $outObj | ConvertTo-Json -Depth 4 $local:jsonOut = $outObj | ConvertTo-Json -Depth 4
if( -not $DryRun ) { if( -not $DryRun ) {
$local:jsonPath = Join-Path $MyPSScriptRoot $_.name $local:pkgPath = Join-Path $MyPSScriptRoot $iObj.name
if( -not (Test-Path $jsonPath) ) { $null = New-Item -Type Directory $jsonPath -Force:$Force } Write-Verbose "pkgPath=$pkgPath"
$jsonPath = Join-Path $jsonPath '_.package.json' if( -not (Test-Path $pkgPath) ) { $null = New-Item -Type Directory $pkgPath -Force:$Force }
$jsonPath = Join-Path $pkgPath '_.package.json'
if( $Force -or -not (Test-Path $jsonPath) ) { if( $Force -or -not (Test-Path $jsonPath) ) {
$jsonOut | Out-File $jsonPath -Force:$Force $jsonOut | Out-File $jsonPath -Force:$Force
$local:profilePath = $(Join-Path $pkgPath 'profile.d')
if( $LocalHost -or $LocalUser -and -not (Test-Path $profilePath) ) {
$null = New-Item -Type Directory $profilePath -Force:$Force
$null = New-Item -Type File $(Join-Path $profilePath env.ps1) -Value "# local environment"
}
} elseif ( Test-Path $jsonPath ) { } elseif ( Test-Path $jsonPath ) {
throw 'Package already exists!' throw 'Package already exists!'
} }

View File

@ -34,6 +34,15 @@ foreach( $local:ext in @('.yml', '.yaml') ) {
} }
} }
$AdditionalFiles = $AdditionalFiles | ForEach-Object {
$_ -replace
'^#lsi$','#/*linuxserver.yml' -replace
'^#tr?$','#/*traefik.yml' -replace
'^#/',"$env:SZ_DOCKER_SYSTEM_PATH"
} |
Get-ChildItem -Force |
Select-Object -ExpandProperty FullName
$local:FinalEditList = $editFiles | Where-Object {$_} | Sort-Object { $local:FinalEditList = $editFiles | Where-Object {$_} | Sort-Object {
$local:n = [System.IO.Path]::GetFileName($_) $local:n = [System.IO.Path]::GetFileName($_)
Join-Path [PSystem.IO.ath]::GetDirectoryName($_) "$(if( $n[0] -eq '.' ) { "9" } else { "1" })$n" Join-Path [PSystem.IO.ath]::GetDirectoryName($_) "$(if( $n[0] -eq '.' ) { "9" } else { "1" })$n"