fixed oniux shit proper and finished checksum for windowz

This commit is contained in:
2026-08-10 21:06:05 -06:00
parent ee6a75de9a
commit 3425139b1f
3 changed files with 278 additions and 33 deletions
+277
View File
@@ -0,0 +1,277 @@
[CmdletBinding(DefaultParameterSetName='Generate')]
param(
# File(s) or wildcard pattern to compute checksum for
[Parameter(Position = 0, ParameterSetName = 'Generate', ValueFromPipeline = $true)]
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
[string[]]$FilePath,
# Output file to save generated checksums (-o mode)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('o')]
[string]$OutFile,
# File containing checksums to verify (-c mode)
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
[Alias('c')]
[string]$Check,
# Direct checksum hash string to match against (-m mode)
[Parameter(Mandatory = $true, ParameterSetName = 'Match')]
[Alias('m')]
[string]$Match,
# Hashing algorithm to use (Defaults to SHA256)
[Parameter(Mandatory = $false)]
[Alias('a')]
[ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5')]
[string]$Algorithm,
# Help flag (-h, -Help)
[Parameter(Mandatory = $false)]
[Alias('h')]
[switch]$Help
)
begin {
function Show-Help {
@'
NAME
checksum - Compute and verify message digests / file checksums
SYNOPSIS
.\checksum.ps1 [-FilePath] <string[]> [-OutFile <string>] [-Algorithm <string>]
.\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>]
.\checksum.ps1 -Check <string> [-Algorithm <string>]
.\checksum.ps1 -Help
DESCRIPTION
Computes or verifies checksums using various cryptographic algorithms.
Outputs hash values in standard Linux utility format (<hash> <filename>).
PARAMETERS
-FilePath <string[]>
Specifies the path to one or more files to hash. Accepts wildcards (*).
-o, -OutFile <string>
Specifies an output file to save the checksum results to, while still
displaying the output on screen.
-c, -Check <string>
Read checksums from the specified file and verify them against files on disk.
-m, -Match <string>
Compare the computed hash of the target file(s) against a specific hash string.
-a, -Algorithm <string>
Specifies the cryptographic hash algorithm to use.
Supported values: SHA1, SHA256 (default), SHA384, SHA512, MD5.
If omitted in -c or -m mode, the algorithm is auto-detected by hash length.
-h, -Help
Display this help message.
EXAMPLES
1. Compute SHA256 checksum for a single file:
.\checksum.ps1 myfile.iso
2. Compute checksums for all files and write to a file while showing output:
.\checksum.ps1 * -o checksums.sha256
3. Verify a file against a explicit hash string:
.\checksum.ps1 myfile.iso -m "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
4. Verify checksums from a verification file (auto-detects algorithm):
.\checksum.ps1 -c checksums.sha256
'@
}
# Helper function to auto-detect hash algorithm based on string character length
function Get-AlgorithmFromHashLength {
param([string]$HashString)
switch ($HashString.Trim().Length) {
32 { return 'MD5' }
40 { return 'SHA1' }
64 { return 'SHA256' }
96 { return 'SHA384' }
128 { return 'SHA512' }
default {
Write-Error "checksum: Could not auto-detect algorithm for hash length $($HashString.Length). Please specify -Algorithm."
return $null
}
}
}
}
process {
# Match help arguments passed either as switch (-h, -Help) or positional string ('help', 'h', '--help', etc.)
$isHelpRequested = $Help.IsPresent -or (
$FilePath -and $FilePath.Count -eq 1 -and (
$FilePath[0] -match '^(?i)[-/]{0,2}(h|help)$'
)
)
if ($isHelpRequested) {
Show-Help
return
}
# Normalize explicit algorithm input if provided
if (-not [string]::IsNullOrWhiteSpace($Algorithm)) {
$Algorithm = $Algorithm.ToUpper()
}
# --- DIRECT MATCH MODE (-m / -Match) ---
if ($PSCmdlet.ParameterSetName -eq 'Match') {
if (-not $FilePath -or $FilePath.Count -eq 0) {
Write-Error "checksum: Missing file path parameter for matching. Use -Help for usage."
return
}
# Auto-detect algorithm from provided -Match hash string if not explicitly given
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
$Algorithm = Get-AlgorithmFromHashLength -HashString $Match
if (-not $Algorithm) { return }
Write-Verbose "Auto-detected algorithm: $Algorithm"
}
$expectedHash = $Match.Trim().ToLower()
foreach ($pathEntry in $FilePath) {
$resolvedItems = Get-Item -Path $pathEntry -ErrorAction SilentlyContinue
if (-not $resolvedItems) {
Write-Error "checksum: $pathEntry`: No such file or directory"
continue
}
foreach ($item in $resolvedItems) {
if ($item.PSIsContainer) {
Write-Error "checksum: $($item.Name)`: Is a directory"
} else {
$actualHash = (Get-FileHash -Path $item.FullName -Algorithm $Algorithm).Hash.ToLower()
$targetFile = Resolve-Path -Path $item.FullName -Relative
if ($targetFile.StartsWith(".\")) { $targetFile = $targetFile.Substring(2) }
if ($actualHash -eq $expectedHash) {
Write-Host "${targetFile}: " -NoNewline
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host "${targetFile}: " -NoNewline
Write-Host "FAILED" -ForegroundColor Red
}
}
}
}
}
# --- VERIFICATION MODE (-c / -Check) ---
elseif ($PSCmdlet.ParameterSetName -eq 'Verify') {
if (-not (Test-Path -Path $Check -PathType Leaf)) {
Write-Error "checksum: $Check`: No such file or directory"
return
}
$lines = Get-Content -Path $Check
# Auto-detect algorithm based on hash length if not explicitly provided
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
foreach ($line in $lines) {
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith("#")) { continue }
if ($line -match '^([a-fA-F0-9]+)\s+') {
$Algorithm = Get-AlgorithmFromHashLength -HashString $Matches[1]
if (-not $Algorithm) { return }
Write-Verbose "Auto-detected algorithm: $Algorithm"
break
}
}
# Fallback if file contained no parsable hashes
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
$Algorithm = 'SHA256'
}
}
foreach ($line in $lines) {
# Skip empty lines or comments
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith("#")) { continue }
# Match standard checksum output format: "<hash> [* ]<filename>"
if ($line -match '^([a-fA-F0-9]+)\s+[* ]?(.*)$') {
$expectedHash = $Matches[1].ToLower()
# Strip leading whitespace and any leftover leading asterisk
$targetFile = $Matches[2].Trim().TrimStart('*')
if (Test-Path -Path $targetFile -PathType Leaf) {
$actualHash = (Get-FileHash -Path $targetFile -Algorithm $Algorithm).Hash.ToLower()
if ($actualHash -eq $expectedHash) {
Write-Host "${targetFile}: " -NoNewline
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host "${targetFile}: " -NoNewline
Write-Host "FAILED" -ForegroundColor Red
}
} else {
Write-Host "${targetFile}: " -NoNewline
Write-Host "FAILED open or read" -ForegroundColor Red
}
} else {
Write-Warning "checksum: improperly formatted line: $line"
}
}
}
# --- GENERATION MODE ---
else {
# Default to SHA256 if no algorithm was specified in generation mode
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
$Algorithm = 'SHA256'
}
if (-not $FilePath -or $FilePath.Count -eq 0) {
Write-Error "checksum: Missing file path parameter. Use -Help for usage."
return
}
# Clear/initialize output file if specified before writing hashes
if (-not [string]::IsNullOrWhiteSpace($OutFile)) {
$null = New-Item -Path $OutFile -ItemType File -Force
}
foreach ($pathEntry in $FilePath) {
# Resolve wildcards and single file inputs
$resolvedItems = Get-Item -Path $pathEntry -ErrorAction SilentlyContinue
if (-not $resolvedItems) {
Write-Error "checksum: $pathEntry`: No such file or directory"
continue
}
foreach ($item in $resolvedItems) {
# Handle directories like Linux sha256sum does
if ($item.PSIsContainer) {
Write-Error "checksum: $($item.Name)`: Is a directory"
} else {
$hash = (Get-FileHash -Path $item.FullName -Algorithm $Algorithm).Hash.ToLower()
# Format standard relative path (stripping leading '.\')
$relativePath = Resolve-Path -Path $item.FullName -Relative
if ($relativePath.StartsWith(".\")) {
$relativePath = $relativePath.Substring(2)
}
$outputLine = "$hash $relativePath"
# If -OutFile is provided, write line to file
if (-not [string]::IsNullOrWhiteSpace($OutFile)) {
Add-Content -Path $OutFile -Value $outputLine
}
# Output to stdout
Write-Output $outputLine
}
}
}
}
}
end {}
-32
View File
@@ -1,32 +0,0 @@
b960c475a456cd4ca4df9228e6935d26aba2d3de a_very_normal_test_file.txt
49af6ace2910bb5f533149065a7c2ee669c09ea9 alert.ps1
8a0c16f254bb9571708350aab7beb99e0dca3e8b checksum.ps1
8a0c16f254bb9571708350aab7beb99e0dca3e8b checksums.ps1
8393fe88bab4ce86cf9a1f13949b8db371326bf2 ffmpreg_gif_loopy.ps1
f9fd13e485e1254a30279de16c243354e58e411c FIND_THE_FUCKING_PI.ps1
64c0df71f41403614e9d20ea33c710915f90d590 get_wsl_usb.ps1
9e36220ef01b549c8504877d668c8833cd71fa4a gitshit.ps1
a06a596f11d87a8a9a2d87bf7538e9f5c2786d93 gitsync.ps1
4eea8bba2f6f2f12dc85aa6d7ac53f2d1fbbd1b0 IM_SO_TIRED_BOSS.ps1
4f3b3e0add2d3cb3b93c7c39bfbf547695a18a2c md5sum.ps1
79fa68ebfb087c2d2bc2b1a805cc1604ecbd5e7e monitor-copy.txt
6ed64c41888586e4d1c06137a8813fc906d5e5db pi-ascii-powershell.ps1
56c8acf528e19e2cbf9cdbc5648577f35ec74587 redundant-backup.ps1
747560d92967b308de0a467d129f15b0c1136724 scan_subnets_for_port.ps1
a47661cc0dd39493bf6e531fb3448c68c0a93439 sha1sum.ps1
575c1bc33ce2491cf7069b1bc6984d268a84dcc4 sha256sum.ps1
4ad867d4b1b070f49255efc61e80f2098d843b6f sha384sum.ps1
0bf441799d73d07c1223979c5c53640a09b25638 sha512sum.ps1
19ee7ac9242165951ad6056280e014c5811b2b31 ssh-wait-loop.ps1
09bdf386e755f5ca339d2e9edddc7a10bbf88511 subnets.txt
50d093581df1e4031662fd91491c3494dfcc0fd9 sync_media.ps1
086ad24aa6b5d8d97e98392da06faa805e95ee2f syncstatus.ps1
e38f48eea08e3c2f4c28b736d64152a19676cb5d tag.txt
d644db4aaf1e31a7c9b2f5cb41f11d74ae136605 tea-cli.exe
dafe05b34aaf8a9c0ff80ad27cab0dc5780cf2e2 testtime.ps1
75219e011a3aeb01e92546485c5de9d480ccbfd5 wait-on-host.ps1
a02db4524ff453394e8246e950a197cbc691f4bd waypoint.ps1
0a6f65c3aeeacf8a381faab9834a992b5d297a52 webhook.ps1
23171433219f70e576f400bbc88a77ceba7c9822 webhook.txt
6b4ce2df2b7e2d63b6415adc7e7ba45e0ff5c9fa windows-repair.ps1
23a95097cbcbbc536f1e8ef3eb8737fb1b3bbf7b winhash.ps1
+1 -1
View File
@@ -115,7 +115,7 @@ if [ ! -z "$1" ]; then
echo -e "\nexisting oniux found, skipping\n" echo -e "\nexisting oniux found, skipping\n"
else else
echo -e "\nexisting oniux not found, installing\n" echo -e "\nexisting oniux not found, installing\n"
cargo install --git https://gitlab.torproject.org/tpo/core/oniux --tag v0.6.1 oniux cd /tmp && cargo install --git https://gitlab.torproject.org/tpo/core/oniux && cd - && echo -e '## Oniux/Cargo Shit\nPATH=$PATH:$HOME/.cargo/bin' >> ~/.bashrc && source ~/.bashrc && oniux curl https://canhazip.com
fi fi
else else