Skip to content

Commit 481ee16

Browse files
committed
fixes #128 using internal boxstarter function for downloading http resources
1 parent b582003 commit 481ee16

15 files changed

+80
-33
lines changed

BoxStarter.Common/Boxstarter.Common.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Export-ModuleMember Confirm-Choice,`
66
Enter-BoxstarterLogable,`
77
Enter-DotNet4,`
88
Get-CurrentUser,`
9+
Get-HttpResource,`
910
Get-IsMicrosoftUpdateEnabled,`
1011
Get-IsRemote,`
1112
Invoke-FromTask,`

BoxStarter.Common/Enter-DotNet4.ps1

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Enable-Net40 {
4646
if(!(test-path "$env:windir\Microsoft.Net\$fx\v4.0.30319")) {
4747
if((Test-PendingReboot) -and $Boxstarter.RebootOk) {return Invoke-Reboot}
4848
Write-BoxstarterMessage "Downloading .net 4.5..."
49-
Get-HttpToFile "http://download.microsoft.com/download/b/a/4/ba4a7e71-2906-4b2d-a0e1-80cf16844f5f/dotnetfx45_full_x86_x64.exe" "$env:temp\net45.exe"
49+
Get-HttpResource "http://download.microsoft.com/download/b/a/4/ba4a7e71-2906-4b2d-a0e1-80cf16844f5f/dotnetfx45_full_x86_x64.exe" "$env:temp\net45.exe"
5050
Write-BoxstarterMessage "Installing .net 4.5..."
5151
if(Get-IsRemote) {
5252
Invoke-FromTask @"
@@ -59,23 +59,3 @@ Start-Process "$env:temp\net45.exe" -verb runas -wait -argumentList "/quiet /nor
5959
}
6060
}
6161
}
62-
63-
function Get-HttpToFile ($url, $file){
64-
Write-BoxstarterMessage "Downloading $url to $file" -Verbose
65-
Invoke-RetriableScript -RetryScript {
66-
if(Test-Path $args[1]){Remove-Item $args[1] -Force}
67-
$downloader=new-object net.webclient
68-
$wp=[system.net.WebProxy]::GetDefaultProxy()
69-
$wp.UseDefaultCredentials=$true
70-
$downloader.Proxy=$wp
71-
try {
72-
$downloader.DownloadFile($args[0], $args[1])
73-
}
74-
catch{
75-
if($VerbosePreference -eq "Continue"){
76-
Write-Error $($_.Exception | fl * -Force | Out-String)
77-
}
78-
throw $_
79-
}
80-
} $url $file
81-
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
function Get-HttpResource {
2+
<#
3+
.SYNOPSIS
4+
Downloads the contents from a URL
5+
6+
.DESCRIPTION
7+
Get-HttpResource downloads the contents of an HTTP url.
8+
When -PassThru is specified it returns the string content.
9+
10+
.PARAMETER Url
11+
The url containing the content to download.
12+
13+
.PARAMETER OutputPath
14+
If provided, the content will be saved to this path.
15+
16+
.PARAMETER PassThru
17+
If provided, the string will be output to the pipeline.
18+
19+
.EXAMPLE
20+
$content = Get-HttpResource -Url 'http://my/url' `
21+
-OutputPath 'c:\myfile.txt' `
22+
-PassThru
23+
24+
This downloads the content located at http://my/url and
25+
saves it to a file at c:\myfile.txt and also returns
26+
the downloaded string.
27+
28+
.LINK
29+
http://boxstarter.org
30+
31+
#>
32+
param (
33+
[string]$Url,
34+
[string]$OutputPath = $null,
35+
[switch]$PassThru
36+
)
37+
Write-BoxstarterMessage "Downloading $url" -Verbose
38+
$str = Invoke-RetriableScript -RetryScript {
39+
$downloader=new-object net.webclient
40+
$wp=[system.net.WebProxy]::GetDefaultProxy()
41+
$wp.UseDefaultCredentials=$true
42+
$downloader.Proxy=$wp
43+
try {
44+
$httpString = $downloader.DownloadString($args[0])
45+
if($args[1]) {
46+
Write-BoxstarterMessage "Saving $httpString to $($args[1])" -Verbose
47+
if(Test-Path $args[1]){Remove-Item $args[1] -Force}
48+
$httpString | Out-File -FilePath $args[1] -Encoding utf8
49+
}
50+
$httpString
51+
}
52+
catch{
53+
if($VerbosePreference -eq "Continue"){
54+
Write-Error $($_.Exception | fl * -Force | Out-String)
55+
}
56+
throw $_
57+
}
58+
} $Url $OutputPath
59+
60+
if($PassThru) { Write-Output $str }
61+
}

Boxstarter.Chocolatey/New-PackageFromScript.ps1

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@ about_boxstarter_chocolatey
5858
Call-Chocolatey
5959
$chocoInstall = [System.Environment]::GetEnvironmentVariable('ChocolateyInstall', 'MACHINE')
6060
}
61-
if(!(test-path function:\Get-WebFile)){
62-
. "$chocoInstall\helpers\functions\Format-FileSize.ps1"
63-
. "$chocoInstall\helpers\functions\Get-WebFile.ps1"
64-
}
6561
if($source -like "*://*"){
66-
try {$text = Get-WebFile -url $Source -passthru } catch{
62+
try {$text = Get-HttpResource -url $Source -passthru } catch{
6763
throw "Unable to retrieve script from $source `r`nInner Exception is:`r`n$_"
6864
}
6965
}

BuildScripts/nuget/Boxstarter.Azure.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<dependency id="WindowsAzureLibsForNet" version="2.5" />
1818
</dependencies>
1919
<releaseNotes>
20+
- Use internal function to download http gist scripts.
2021
- No longer vendors a legacy version of Chocolatey. Leverages the current beta Chocolatey library API for all Chocolatey interaction.
2122
</releaseNotes>
2223
</metadata>

BuildScripts/nuget/Boxstarter.Bootstrapper.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<dependency id="Boxstarter.WinConfig" version="$version$" />
1717
</dependencies>
1818
<releaseNotes>
19+
- Use internal function to download http gist scripts.
1920
- No longer vendors a legacy version of Chocolatey. Leverages the current beta Chocolatey library API for all Chocolatey interaction.
2021
</releaseNotes>
2122
</metadata>

BuildScripts/nuget/Boxstarter.Chocolatey.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<dependency id="Boxstarter.Bootstrapper" version="$version$" />
1818
</dependencies>
1919
<releaseNotes>
20+
- Use internal function to download http gist scripts.
2021
- No longer vendors a legacy version of Chocolatey. Leverages the current beta Chocolatey library API for all Chocolatey interaction.
2122
</releaseNotes>
2223
</metadata>

BuildScripts/nuget/Boxstarter.Common.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>Provides common functions used by multiple Boxstarter Modules.</description>
1414
<releaseNotes xmlns="">
15+
- Use internal function to download http gist scripts.
1516
- No longer vendors a legacy version of Chocolatey. Leverages the current beta Chocolatey library API for all Chocolatey interaction.
1617
</releaseNotes>
1718
</metadata>

BuildScripts/nuget/Boxstarter.HyperV.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<dependency id="Boxstarter.Chocolatey" version="$version$" />
1717
</dependencies>
1818
<releaseNotes>
19+
- Use internal function to download http gist scripts.
1920
- No longer vendors a legacy version of Chocolatey. Leverages the current beta Chocolatey library API for all Chocolatey interaction.
2021
</releaseNotes>
2122
</metadata>

BuildScripts/nuget/Boxstarter.TestRunner.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<dependency id="Boxstarter.Azure" version="$version$" />
1717
</dependencies>
1818
<releaseNotes>
19+
- Use internal function to download http gist scripts.
1920
- No longer vendors a legacy version of Chocolatey. Leverages the current beta Chocolatey library API for all Chocolatey interaction.
2021
</releaseNotes>
2122
</metadata>

0 commit comments

Comments
 (0)