-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.ps1
93 lines (83 loc) · 2.7 KB
/
bootstrap.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#requires -version 3.0
# Author: Jon Maken
# License: 3-clause BSD
# Revision: 2020-09-27 16:59:04 -0600
param (
[parameter(Mandatory=$false,
Position=0,
HelpMessage='Buildlet to download')]
[alias('b')]
[string] $buildlet = $null
)
$tools = @('7za.exe')
$tools_root = "$PWD\tools"
$tools_uri = 'https://raw.github.com/jonforums/buildlets/master/tools/'
# TODO not DRY enough
$buildlets = @('build_bzip2'
'build_discount'
'build_fossil'
'build_libarchive'
'build_libffi'
'build_libiconv'
'build_liblzma'
'build_libsodium'
'build_libyaml'
'build_lua'
'build_lzo2'
'build_minised'
'build_openssl'
'build_ragel'
'build_sqlite'
'build_tcltk'
'build_unqlite'
'build_zlib'
'build_zstd'
)
$buildlet_uri = 'https://raw.github.com/jonforums/buildlets/master/'
switch -regex ($buildlet) {
'^(?:ls|list)$' {
Write-Host "`n== Available Buildlets ==" -foregroundcolor green
$buildlets | % { Write-Host " $_" -foregroundcolor yellow }
return
}
}
Write-Debug '---> downloading buildlet library and tools'
# download buildlet utility library and required tools
$fetcher = New-Object System.Net.WebClient
if (-not (Test-Path "$PWD\buildlet_utils.ps1")) {
Write-Host '---> fetching buildlet library' -foregroundcolor yellow
try {
$fetcher.DownloadFile('https://raw.github.com/jonforums/buildlets/master/buildlet_utils.ps1',
"$PWD\buildlet_utils.ps1")
}
catch {
throw '[ERROR] unable to fetch required buildlet library'
}
}
if (-not (Test-Path "$tools_root" -type container)) {
Write-Host "---> creating $tools_root" -foregroundcolor yellow
New-Item $tools_root -type directory -force | Out-Null
}
$tools | % {
if (-not (Test-Path (Join-Path "$tools_root" "$_") -type leaf)) {
Write-Host "---> downloading tool: $_" -foregroundcolor yellow
try {
$fetcher.DownloadFile("${tools_uri}$_", $(Join-Path "$tools_root" "$_"))
}
catch {
throw "[ERROR] unable to fetch required build tool $_"
}
}
}
Write-Debug "---> downloading $buildlet"
# download specified buildlet if given
if (($buildlet) -and ($buildlets -contains $buildlet) -and `
(-not (Test-Path "${buildlet}.ps1" -type leaf))) {
Write-Host "---> downloading ${buildlet}.ps1" -foregroundcolor yellow
try {
$fetcher.DownloadFile("${buildlet_uri}${buildlet}.ps1", $(Join-Path "$PWD" "${buildlet}.ps1"))
}
catch {
throw "[ERROR] unable to fetch ${buildlet} buildlet"
}
}