Skip to content

Instantly share code, notes, and snippets.

@geovanisouza92
Created September 24, 2013 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geovanisouza92/6683848 to your computer and use it in GitHub Desktop.
Save geovanisouza92/6683848 to your computer and use it in GitHub Desktop.
PowerShell script to get the most recent arduino firmware, for manual upload, with sha256 and md5 checksum's
function Get-FileHash {
param (
[string] $File = $(throw 'a filename is required'),
[string] $Algorithm = 'sha256'
)
$fileStream = [System.IO.File]::OpenRead((Resolve-Path $File))
$hasher = [System.Security.Cryptography.HashAlgorithm]::Create($Algorithm)
$hash = $hasher.ComputeHash($fileStream)
$fileStream.Close()
$fileStream.Dispose()
[System.BitConverter]::ToString($hash) -replace '-',''
}
$all_builds = Get-Item "$($env:temp)\build*"
$all_valid_builds = $all_builds | Where-Object { (Get-ChildItem $_) -ne $null }
$all_sorted_builds = $all_valid_builds | Sort-Object -Descending LastWriteTime
$most_recent_build = ($all_sorted_builds | Select-Object -First 1).Name
$hex_filename = (Get-ChildItem "$($env:temp)\$most_recent_build" *.hex | Select-Object -First 1).Name
$hex_path = "$($env:temp)\$most_recent_build\$hex_filename"
$sha256sum = Get-FileHash -File $hex_path -Algorithm 'sha256'
$md5sum = Get-FileHash -File $hex_path -Algorithm 'md5'
$hex_destination = "$(Get-Location)\program.hex"
Copy-Item $hex_path $hex_destination
$sha256sum > "$hex_destination.sha256"
$md5sum > "$hex_destination.md5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment