Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add buildlet utility library

  • Loading branch information...
commit 8052aab8db007cc6074915a7510edd9225dd1bf7 1 parent f224f3c
@jonforums authored
Showing with 57 additions and 0 deletions.
  1. +57 −0 buildlet_utils.ps1
View
57 buildlet_utils.ps1
@@ -0,0 +1,57 @@
+#requires -version 2.0
+
+# Author: Jon Maken
+# License: 3-clause BSD
+# Revision: 2013-03-21 21:33:45 -0600
+
+function Write-Status($msg, $leader='--->', $color='Yellow') {
+ Write-Host "$leader $msg" -foregroundcolor $color
+}
+
+function Require-BuildletLibrary() {
+ if (Test-Path "$PWD\buildlet_utils.ps1") { return }
+
+ $fetcher = New-Object System.Net.WebClient
+ $fetcher.DownloadFile('https://raw.github.com/jonforums/buildlets/master/buildlet_utils.ps1',
+ "$PWD\buildlet_utils.ps1")
+
+ if (Test-Path "$PWD\buildlet_utils.ps1") {
+ . "$PWD\buildlet_utils.ps1"
+ } else {
+ throw '[ERROR] unable to fetch required buildlet library'
+ }
+}
+
+function Fetch-Archive($uri, $target) {
+ if (-not (Test-Path $target)) {
+ Import-Module BitsTransfer
+ Write-Status "downloading $uri"
+ Start-BitsTransfer $uri "$PWD\$target"
+ }
+}
+
+function Validate-Archive($target, $hash_uri) {
+ try {
+ $fetcher = New-Object System.Net.WebClient
+ $hash = ConvertFrom-StringData $fetcher.DownloadString($hash_uri)
+
+ $hasher = New-Object System.Security.Cryptography.SHA1Cng
+ $fs = New-Object System.IO.FileStream "$PWD\$target", 'Open', 'Read'
+ $test_hash = [BitConverter]::ToString($hasher.ComputeHash($fs)).Replace('-','').ToLower()
+ }
+ catch {
+ throw "[ERROR] unable to validate $target"
+ }
+ finally {
+ $fs.Close()
+ }
+
+ if ($test_hash -ne $hash[$version].ToLower()) {
+ throw "[ERROR] $target fingerprint different than expected value"
+ }
+}
+
+function Extract-Archive($archive) {
+ $tar_file = "$($source.Substring(0, $source.LastIndexOf('-')))*.tar"
+ (& "$7ZA" "x" $source) -and (& "$7ZA" "x" $tar_file) -and (rm $tar_file) | Out-Null
+}
Please sign in to comment.
Something went wrong with that request. Please try again.