waypoint debug

This commit is contained in:
2026-09-25 16:01:49 -06:00
parent 4377cc6a45
commit 4fea9dbccc
+59 -28
View File
@@ -5,10 +5,15 @@ param(
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
[string[]]$FilePath,
# Output file (-o / -OutFile)
# Custom output file (-f / -OutFile)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('f')]
[string]$OutFile,
# Auto output file switch (-o)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('o')]
[string]$OutFile,
[switch]$AutoOut,
# File containing checksums to verify (-c / -Check)
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
@@ -44,7 +49,7 @@ NAME
checksum - Compute and verify message digests / file checksums
SYNOPSIS
.\checksum.ps1 [-FilePath] <string[]> [-o [<string>]] [-Algorithm <string>] [-r]
.\checksum.ps1 [-FilePath] <string[]> [-o] [-f <string>] [-Algorithm <string>] [-r]
.\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>] [-r]
.\checksum.ps1 -Check <string> [-Algorithm <string>] [-r]
.\checksum.ps1 -Help
@@ -58,40 +63,43 @@ PARAMETERS
-FilePath <string[]>
Specifies the target file(s) or wildcard pattern (*).
-o, -OutFile <string>
Enables auto-saving checksum results to file(s).
- If passed with an argument (e.g. -o custom.txt), writes to 'custom.txt'.
- If passed with NO argument (or empty string ""), automatically outputs to 'checksums.<algo>'.
When combined with -r and *, recursively auto-generates checksum files per directory.
-o, -O
Auto-saves checksum results. (Takes no arguments).
- If input filename contains a wildcard (*), saves to 'checksums.<algo>'.
- If input filename does NOT contain a wildcard, saves to '<filename>.<algo>'.
When combined with -r and *, recursively auto-generates checksums per directory.
-c, -Check <string>
-f, -F, -OutFile <string>
Saves checksum results to a specific custom filename.
Overrides the auto-naming behavior of -o if both are passed.
-c, -C, -Check <string>
Reads hashes from a specified checksum file and verifies target files on disk.
If -r is specified, recursively looks for and validates checksum files by name across subdirectories.
-m, -Match <string>
-m, -M, -Match <string>
Compares the computed hash of target file(s) directly against a given hash string.
-a, -algo, -Algorithm <string>
-a, -A, -Algo, -Algorithm <string>
Specifies the hash algorithm to use.
Supported options: SHA1, SHA256 (default), SHA384, SHA512, MD5.
Supported options: MD5, SHA1, SHA256 (default), SHA384, SHA512.
In -c or -m mode, auto-detects algorithm from hash length if omitted.
-r, -Recursive <switch>
-r, -R, -Recursive <switch>
Processes target files or verification files recursively across directory structures.
-h, -Help <switch>
-h, -H, -Help <switch>
Displays this help documentation.
EXAMPLES
1. Compute SHA256 for a single file:
.\checksum.ps1 myfile.iso
1. Compute SHA256 for a single file and auto-save as 'myfile.iso.sha256':
.\checksum.ps1 myfile.iso -o
2. Compute SHA512 checksums recursively and auto-save (prompts for filename, hit Enter for auto):
2. Compute SHA512 recursively and auto-save as 'checksums.sha512' in each folder:
.\checksum.ps1 * -r -o -a SHA512
.\checksum.ps1 * -Recursive -OutFile "" -Algorithm SHA512
3. Compute SHA256 checksums and save to custom file:
.\checksum.ps1 * -o my_hashes.txt
3. Compute SHA256 checksums and save to a specific custom file:
.\checksum.ps1 * -f my_hashes.txt
4. Verify checksums against a verification file:
.\checksum.ps1 -c checksums.sha256
@@ -296,10 +304,11 @@ process {
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256';
};
$wantOutFile =$PSBoundParameters.ContainsKey('OutFile');
$isAutoFile = [string]::IsNullOrWhiteSpace($OutFile);
$wantCustomOut =$PSBoundParameters.ContainsKey('OutFile');
$wantAutoOut =$AutoOut.IsPresent;
if ($wantOutFile) {
if ($wantCustomOut -or$wantAutoOut) {
# Recursive wildcard auto-saves per directory
if ($Recursive -and$isWildcardGlobal) {
$groupedItems =$allItems | Group-Object DirectoryName;
@@ -307,10 +316,9 @@ process {
$dirPath =$group.Name;
$filesInDir =$group.Group;
if ($isAutoFile) {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())";
if ($wantCustomOut) {$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile);
} else {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile);
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())";
};
$linesToWrite = @();
@@ -326,9 +334,12 @@ process {
};
}
else {
if ($isAutoFile) {$singleOutFile = "checksums.$($Algorithm.ToLower())";
} else {
# Custom file OR Auto file with a wildcard
if ($wantCustomOut -or ($wantAutoOut -and$isWildcardGlobal)) {
if ($wantCustomOut) {
$singleOutFile =$OutFile;
} else {
$singleOutFile = "checksums.$($Algorithm.ToLower())";
};
$linesToWrite = @();
@@ -346,8 +357,28 @@ process {
};
Set-Content -Path ($singleOutFile) -Value$linesToWrite -Encoding utf8;
}
# Auto file for explicit individual files (No wildcard)
else {
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
$relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue';
if (-not $relativePath) { $relativePath =$item.Name; };
if ($relativePath.StartsWith(".\") -or $relativePath.StartsWith("./")) {
$relativePath =$relativePath.Substring(2);
};
$outputLine = "${hash}${relativePath}";
Write-Output $outputLine;
# Save directly next to the original file: <filename>.<algo>
$itemOutFile = "$($item.FullName).$($Algorithm.ToLower())";
Set-Content -Path ($itemOutFile) -Value$outputLine -Encoding utf8;
};
};
};
}
# Standard console output (No save flags passed)
else {
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();