diff --git a/ansible/Update-ViaAnsible.ps1 b/ansible/Update-ViaAnsible.ps1 index 7433136..e3957be 100644 --- a/ansible/Update-ViaAnsible.ps1 +++ b/ansible/Update-ViaAnsible.ps1 @@ -1,3 +1,7 @@ -[CmdletBinding()]param([string[]]$Remotes = 'All') +[CmdletBinding()]param( + [string[]]$Remotes = 'All', + [switch]$OneLine -Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) +) + +Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -OneLine:$OneLine diff --git a/base.linux/Repair-Permissions.ps1 b/base.linux/Repair-Permissions.ps1 index 39c148e..3cf76db 100644 --- a/base.linux/Repair-Permissions.ps1 +++ b/base.linux/Repair-Permissions.ps1 @@ -29,7 +29,7 @@ begin { } if( [string]::IsNullOrWhiteSpace($DirPermission) ) { - $DirPermission = $env:SZ_DIR_PERM ?? "664" + $DirPermission = $env:SZ_DIR_PERM ?? "775" } $cmdArgs = "-Recurse:`$$(-not $NonRecursive) -Force:`$$Force" diff --git a/base.linux/Update-ArchOSz.ps1 b/base.linux/Update-ArchOSz.ps1 index 2c8e0b2..66985fe 100644 --- a/base.linux/Update-ArchOSz.ps1 +++ b/base.linux/Update-ArchOSz.ps1 @@ -5,8 +5,8 @@ param( $script:yayCli = "cat /run/check.yay.updates/list" switch( $Mode ){ - 'Update' { $yayCli = "yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux" } - 'Auto' { $yayCli = "yay -Syu --needed --noconfirm --ignore docker || yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux --noconfirm" } + 'Update' { $yayCli = "yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux,zfs-utils" } + 'Auto' { $yayCli = "yay -Syu --needed --noconfirm --ignore docker || yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux,zfs-utils --noconfirm" } 'All' { $yayCli = "yay -Syu --needed" } } diff --git a/docker/Aliases/dcall.ps1 b/docker/Aliases/dcall.ps1 new file mode 100644 index 0000000..2168c3e --- /dev/null +++ b/docker/Aliases/dcall.ps1 @@ -0,0 +1 @@ +Invoke-DockerCompose diff --git a/base/Aliases/dcedit.ps1 b/docker/Aliases/dcedit.ps1 similarity index 100% rename from base/Aliases/dcedit.ps1 rename to docker/Aliases/dcedit.ps1 diff --git a/base/Aliases/dco.ps1 b/docker/Aliases/dco.ps1 similarity index 100% rename from base/Aliases/dco.ps1 rename to docker/Aliases/dco.ps1 diff --git a/base/Aliases/dps.ps1 b/docker/Aliases/dps.ps1 similarity index 100% rename from base/Aliases/dps.ps1 rename to docker/Aliases/dps.ps1 diff --git a/base/Aliases/vidc.ps1 b/docker/Aliases/vidc.ps1 similarity index 100% rename from base/Aliases/vidc.ps1 rename to docker/Aliases/vidc.ps1 diff --git a/docker/Edit-DockerCompose.ps1 b/docker/Edit-DockerCompose.ps1 index cb715a9..0215876 100644 --- a/docker/Edit-DockerCompose.ps1 +++ b/docker/Edit-DockerCompose.ps1 @@ -14,7 +14,7 @@ ) -$local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml') +$local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml','Dockerfile') $local:editFiles = @() foreach( $local:fileName in $EditCandidates ) { foreach( $local:path in $ProjectPath ) { diff --git a/docker/Invoke-DockerCompose.ps1 b/docker/Invoke-DockerCompose.ps1 new file mode 100644 index 0000000..1a8cc54 --- /dev/null +++ b/docker/Invoke-DockerCompose.ps1 @@ -0,0 +1,114 @@ +[CmdletBinding(SupportsShouldProcess)]param( + [ArgumentCompleter({ param ( + $commandName, + $parameterName, + $wordToComplete, + $commandAst, + $fakeBoundParameters + ) + [DockerComposeDirs]::_GetValidValues($wordToComplete,$true) + })] + [string[]]$ProjectPath=@($PWD), + [switch]$Recurse, + [int]$Depth=1, + [switch]$Force, + [switch]$OneLine, + [Parameter(Position = 0, ValueFromRemainingArguments = $true, mandatory)] + [array]$CliParams +) + +$script:JobQueue = @() +$script:CleanupJobQueue = @() +function CompleteJobs{ + if( -not $JobQueue ) { return } + $local:currentJobQueue = $JobQueue + $JobQueue = @() + $CleanupJobQueue += $currentJobQueue + + Wait-Job $currentJobQueue | ForEach-Object { + $_ | Receive-Job | ForEach-Object { + Write-Host "---: $($_.Path) | $($_.Params)" -ForegroundColor Cyan + $_.Results + } + } + Write-Host '--- Background jobs completed' -ForegroundColor Green +} + +if( $CliParams[0] -is [string] ) { + $CliParams = @($CliParams,@($null)) +} + +$local:dcPathList = $ProjectPath | ForEach-Object { + if( (Test-Path (Join-Path $_ 'docker-compose.yml')) -and -not $Recurse ) { + Resolve-Path $_ + } elseif( $Recurse ) { + $local:gciParams = [ordered]@{ + Recurse = $true + } + if( $Depth ) { + $gciParams.Depth = $Depth + } + Get-ChildItem -Path $_ -Include 'docker-compose.yml' @gciParams | + Select-Object -ExpandProperty Directory | + Where-Object { $Force -or -not (Test-Path $(Join-Path $_ .noauto.all)) } + + # _DIRS_=$( find . -mindepth 1 -maxdepth 1 -type d -exec test -f {}/docker-compose.yml \; -exec test -f {}/.ask.all \; -print | sort ) + # _DIRS_="$_DIRS_ $( find . -mindepth 1 -maxdepth 1 -type d -exec test -f {}/docker-compose.yml \; -not -exec test -f {}/.ask.all \; -not -exec test -f {}/.noauto.all \; -print | sort )" + } + } +if( -not $dcPathList ) { return } +Write-Verbose "$dcPathList" + +foreach( $local:p in $CliParams ) { + if( -not $p ) { continue } + + $local:AsJob = $false; + $local:Wait = $false; + + if( $p -isnot [String] ) { + $local:skipFirst = $true + switch( $p[0] ) { + '&' { $AsJob = $true } + '!' { $Wait = $true } + default { $skipFirst = $false } + } + if( $skipFirst ) { $p = $p | Select-Object -Skip 1 } + } + + $dcParams = $p | ForEach-Object { + if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ } + else { "'$($_.Replace( "'", "''" ))'" } + } + + $dcPathList | ForEach-Object { + $local:dcPath = Join-Path $_ 'docker-compose.yml' + if( -not (Test-Path $dcPath) ) { if( $Recurse ) { return } else { throw "ERROR: dcPath ($dcPath) does not exists" } } + + Write-Verbose "& docker-compose --file $dcPath $dcParams" + if( $Wait ) { + CompleteJobs + } + + if( -not $dcParams ) { continue } + + if( $AsJob ) { + $JobQueue += Start-Job -ArgumentList @($dcPath,$dcParams) -ScriptBlock { + param($dcPath,$dcParams) + [PSCustomObject] $([ordered]@{ + Path = $dcPath + Params = $dcParams + Results = $(& docker-compose --file $dcPath $dcParams) + }) + } + } else { + & docker-compose --file $dcPath $dcParams + } + + } + } + + +CompleteJobs +if( $CleanupJobQueue ) { + $CleanupJobQueue | Remove-Job +} diff --git a/docker/dcrefresh.ps1 b/docker/dcrefresh.ps1 new file mode 100644 index 0000000..f8f38e2 --- /dev/null +++ b/docker/dcrefresh.ps1 @@ -0,0 +1,29 @@ +[CmdletBinding(SupportsShouldProcess)]param( + [ArgumentCompleter({ param ( + $commandName, + $parameterName, + $wordToComplete, + $commandAst, + $fakeBoundParameters + ) + [DockerComposeDirs]::_GetValidValues($wordToComplete,$true) + })] + [string[]]$ProjectPath, + [switch]$Recurse, + [int]$Depth=1, + [switch]$Force, + [switch]$OneLine, + [Parameter(Position = 0, ValueFromRemainingArguments = $true)] + [array]$CliParams=@('&','up','-d') +) + +$local:passParams = [ordered]@{ + Depth = $Depth + Force = $Force + OneLine = $OneLine + CliParams = $CliParams +} +if( -not $ProjectPath -and -not $Recurse ) { $Recurse = $true } +if( $ProjectPath ) { $passParams.ProjectPath = $ProjectPath } +if( $Recurse ) { $passParams.Recurse = $Recurse } +Invoke-DockerCompose @passParams diff --git a/docker/dcreup.ps1 b/docker/dcreup.ps1 index 052c0d5..5019d06 100644 --- a/docker/dcreup.ps1 +++ b/docker/dcreup.ps1 @@ -1,11 +1,26 @@ -#[CmdletBinding(SupportsShouldProcess)]param() +[CmdletBinding(SupportsShouldProcess)]param( + [ArgumentCompleter({ param ( + $commandName, + $parameterName, + $wordToComplete, + $commandAst, + $fakeBoundParameters + ) + [DockerComposeDirs]::_GetValidValues($wordToComplete,$true) + })] + [string[]]$ProjectPath=@($PWD), + [string[]]$UpCliParams, + [Parameter(Position = 0, ValueFromRemainingArguments = $true)] + [string[]]$CliParams +) -$local:dcParams = [string]::Empty -if( $args ) { - $dcParams = $args | ForEach-Object { - if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ } - else { "'$($_.Replace( "'", "''" ))'" } - } +$local:passParams = [ordered]@{ + ProjectPath=$ProjectPath + UpCliParams=@('--force-recreate') } -docker-compose up -d --force-recreate --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams +if( $UpCliParams ) { $passParams.UpCliParams += $UpCliParams } +if( $CliParams ) { $passParams.CliParams = $CliParams } +dcup @passParams + +# docker-compose --file $dcPath up -d --force-recreate --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams diff --git a/docker/dcup.ps1 b/docker/dcup.ps1 index 47cc001..6ec1160 100644 --- a/docker/dcup.ps1 +++ b/docker/dcup.ps1 @@ -9,6 +9,7 @@ [DockerComposeDirs]::_GetValidValues($wordToComplete,$true) })] [string[]]$ProjectPath=@($PWD), + [string[]]$UpCliParams, [Parameter(Position = 0, ValueFromRemainingArguments = $true)] [string[]]$CliParams ) @@ -20,9 +21,11 @@ if( $CliParams ) { else { "'$($_.Replace( "'", "''" ))'" } } } +$local:dcUpParams = $UpCliParams + $dcParams + $ProjectPath | ForEach-Object { $local:dcPath = $(Resolve-Path $(Join-Path $_ docker-compose.yml)) - Write-Verbose "docker-compose --file $dcPath up -d --remove-orphans $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams" - docker-compose --file $dcPath up -d --remove-orphans $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams + Write-Verbose "docker-compose --file $dcPath up -d --remove-orphans $dcUpParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams" + docker-compose --file $dcPath up -d --remove-orphans $dcUpParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams } diff --git a/docker/dcx.ps1 b/docker/dcx.ps1 index 130dda9..7e25a31 100644 --- a/docker/dcx.ps1 +++ b/docker/dcx.ps1 @@ -1 +1 @@ -docker-compose exec "$args" +docker-compose exec $args