-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDownload-Software.ps1
58 lines (51 loc) · 2 KB
/
Download-Software.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Download software
# RFE :: Can this be cross-platform, in PS-Core?
$destinationDir = Join-Path -Path $HOME -ChildPath 'Downloads' -ErrorAction Stop
Function Initialize-PackageSettings {
[CmdletBinding(SupportsShouldProcess)]
param (
# Parameter help description
[Parameter(
Mandatory,
Position=0
)]
[Alias('FileName','json')]
[String]
$Name = 'bootstrap.json'
)
Write-Debug -Message "`$script:Settings = (Get-Content -Path $(join-path -Path $(Split-Path -Path $((Get-PSCallStack).ScriptName | Sort-Object -Unique) -Parent) -ChildPath $Name)) -join ""``n"" | ConvertFrom-Json"
$PackageSettingsPath = $(join-path -Path $(Split-Path -Path $PSCommandPath -Parent) -ChildPath $Name)
try {
$script:Settings = (Get-Content -Path $PackageSettingsPath) -join "`n" | ConvertFrom-Json
Write-Verbose -Message 'Settings imported. Run Show-Settings to see details.'
}
catch {
throw "Critical Error loading settings from from $PackageSettingsPath"
}
}
$script:packages = @{}
$script:Settings | ForEach-Object {
Write-Debug -Message "$($PSItem.Name) = $($ExecutionContext.InvokeCommand.ExpandString($PSItem.Path))"
$script:knownPaths.Add("$($PSItem.Name)",$ExecutionContext.InvokeCommand.ExpandString($PSItem.Path))
}
foreach ($download in $software.Keys) {
$uri = $software.$download
$file = $download
if (-not (test-path -Path "$destinationDir\$file"))
{
write-output -InputObject "Downloading $file from $uri"
$webclient.DownloadFile($uri,"$destinationDir\$file")
if ($?)
{
start-sleep -seconds 1
write-output -InputObject "Starting $file"
& "$destinationDir\$file"
start-sleep -seconds 5
}
}
else
{
write-warning -Message "$destinationDir\$file already exists."
write-output -InputObject ' To re-download / re-setup, first delete this file and try again.'
}
}