system_configuration/capture.ps1
2023-04-15 01:27:31 -07:00

36 lines
1.1 KiB
PowerShell

$path = $PSScriptRoot
Write-Host "Capturing files begin"
$rootCaptureFolder = Join-Path -Path $path -ChildPath "root"
if (-not (Test-Path -Path $rootCaptureFolder)) {
Write-Host "Could not find [$rootCaptureFolder]"
return
}
$captureListFile = Join-Path -Path $path -ChildPath "capture.filelist"
$fileList = Get-Content -Path $captureListFile
foreach ($file in $fileList) {
if ([string]::IsNullOrWhiteSpace($file)) { continue }
$files = @()
if ($file.IndexOf('/*') -gt -1) {
$files = Get-ChildItem -Path $file -Recurse
} else {
$files = Get-ChildItem -Path $file
}
foreach ($file in $files) {
Write-Host "Found $($file.FullName)"
$targetCopy = Join-Path $rootCaptureFolder -ChildPath $file.FullName
$targetParent = Split-Path -Path $targetCopy -Parent
if (-not (Test-Path -Path $targetParent)) {
New-Item -ItemType Directory -Path $targetParent -Force | Out-Null
}
Write-Host "Copy-Item -Path '$($file.FullName)' -Destination '$($targetParent)'"
Copy-Item -Path $file.FullName -Destination $targetParent
}
}
chown go:go ./* -R