Created
September 24, 2013 12:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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