Main ConvertTo-Zip with a few additions and fixes
+ ConvertTo-Zip, originally created to mass convert CBRs to CBZs It will only be avilable when 7-zip is available (7z executable) Features: Shows progress, can work recursively (preserving folder structure), knows to move completed files. + Show-Progress: Shorthand for common progress related output manipulation (calculation of completion based on time, or item count, and verbose output if needeed) + ConvertFrom-TimeSpan: string output from timespan, used by Show-Progress + Get-Path updated to be more efficient (no need for exception handling) + PathProcessingFunctions loads a utility function GetShellSafePath * Repair-Permissions added some status reporting
This commit is contained in:
parent
d1e24fa7eb
commit
449a297d8b
7 changed files with 276 additions and 19 deletions
|
@ -19,9 +19,16 @@ begin {
|
|||
$User = $env:SZ_DOCKER_PUID ?? $env:USER;
|
||||
}
|
||||
$User = "$(& id --user --name $User)";
|
||||
|
||||
if( [string]::IsNullOrWhiteSpace($User) ) {
|
||||
$User = $env:USER;
|
||||
}
|
||||
$User = "$(& id --user --name $User)";
|
||||
|
||||
if( [string]::IsNullOrWhiteSpace($Group) ) {
|
||||
$Group = $env:SZ_DOCKER_GUID ?? "$(& id --group --name $User)"
|
||||
}
|
||||
if( [string]::IsNullOrWhiteSpace($Group) ) {
|
||||
$Group = "$(& id --group --name $User)"
|
||||
}
|
||||
|
||||
if( [string]::IsNullOrWhiteSpace($FilePermission) ) {
|
||||
|
@ -36,23 +43,37 @@ begin {
|
|||
}
|
||||
|
||||
process {
|
||||
$local:Dirs = @()
|
||||
$local:Files = @()
|
||||
$local:item = $Path | Get-Item
|
||||
|
||||
$Path | Get-Item | ForEach-Object {
|
||||
$local:p = $_.FullName
|
||||
$local:nextCmd = ""
|
||||
if( $_.Attributes -band [System.IO.FileAttributes]::Directory ) {
|
||||
$nextCmd = "Get-ChildItem $p $cmdArgs | ForEach-Object { & chown ${User}:${Group} `$_ }"
|
||||
if( $PSCmdlet.ShouldProcess( "Set $p ownership to ${User}:${Group}`n$nextCmd`n" ) ) {
|
||||
Invoke-ExpressionEx -sudo:$sudo $nextCmd
|
||||
}
|
||||
}
|
||||
|
||||
$nextCmd = "Get-ChildItem $p -Directory $cmdArgs | ForEach-Object { & chmod $DirPermission `$_ }"
|
||||
if( $PSCmdlet.ShouldProcess( "Set $p dirs permissions to $DirPermission`n$nextCmd`n" ) ) {
|
||||
|
||||
$nextCmd = "(@(Get-Item '$p') + (Get-ChildItem '$p' $cmdArgs)) | " +
|
||||
"ForEach-Object { & chown ${User}:${Group} `$_.FullName }"
|
||||
$local:msg = "Set $p ownership to ${User}:${Group}"
|
||||
if( $PSCmdlet.ShouldProcess( "$msg`n$nextCmd`n" ) ) {
|
||||
Write-Host -ForegroundColor Cyan $msg
|
||||
Invoke-ExpressionEx -sudo:$sudo $nextCmd
|
||||
}
|
||||
|
||||
$nextCmd = "Get-ChildItem $p -File $cmdArgs | ForEach-Object { & chmod $FilePermission `$_ }"
|
||||
if( $PSCmdlet.ShouldProcess( "Set $p file permissions to $FilePermission`n$nextCmd`n" ) ) {
|
||||
$nextCmd = "(Get-ChildItem '$p' -Directory $cmdArgs)) | ForEach-Object { & chmod $DirPermission `$_ }"
|
||||
if( $_.Attributes -band 'Directory' ) { $nextCmd = "@(Get-Item '$p') + $nextCmd" }
|
||||
$nextCmd = "($nextCmd"
|
||||
$msg = "Set $p dirs permissions to $DirPermission"
|
||||
if( $PSCmdlet.ShouldProcess( "$msg`n$nextCmd`n" ) ) {
|
||||
Write-Host -ForegroundColor Cyan $msg
|
||||
Invoke-ExpressionEx -sudo:$sudo $nextCmd
|
||||
}
|
||||
|
||||
$nextCmd = "(Get-ChildItem '$p' -File $cmdArgs)) | ForEach-Object { & chmod $FilePermission `$_ }"
|
||||
if( -not ($_.Attributes -band 'Directory') ) { $nextCmd = "@(Get-Item '$p') + $nextCmd" }
|
||||
$nextCmd = "($nextCmd"
|
||||
$msg = "Set $p file permissions to $FilePermission"
|
||||
if( $PSCmdlet.ShouldProcess( "$msg`n$nextCmd`n" ) ) {
|
||||
Write-Host -ForegroundColor Cyan $msg
|
||||
Invoke-ExpressionEx -sudo:$sudo $nextCmd
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue