forked from dagger/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
93 lines (78 loc) · 2.71 KB
/
install.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 7.0
param (
[Parameter(Mandatory = $false)] [System.Management.Automation.SemanticVersion]$DaggerVersion,
[Parameter(Mandatory = $false)] [string]$InstallPath = $env:HOMEPATH + '\dagger',
[Parameter(Mandatory = $false)] [System.Boolean]$InteractiveInstall = $false
)
# ---------------------------------------------------------------------------------
# Author: Alessandro Festa
# Co Author: Brittan DeYoung
# Dagger Installation Utility for Windows users
# ---------------------------------------------------------------------------------
$name="dagger"
$base="https://dl.dagger.io"
function execute {
$url = base_url
$filename = tarball
$url = $url + "/" + $filename
write-host $url
if ($InteractiveInstall) {
Pause
}
Invoke-WebRequest -Uri $url -OutFile $env:temp/$filename -ErrorAction Stop
Expand-Archive -Path $env:temp/$filename -DestinationPath $InstallPath -Force -ErrorVariable ProcessError;
If ($ProcessError) {
@"
---------------------------------------------------------------------------
Whoops apparently we had an issue in unzipping the file, please check
you have the right permission to do so and try to unzip manually the file.
Currently we saved Dagger at your temp folder.
---------------------------------------------------------------------------
"@
exit
} else {
@"
Thank You for downloading Dagger!
-----------------------------------------------------
Dagger has been saved at <YOUR HOME FOLDER>/dagger/
Please add dagger.exe to your PATH in order to use it
----------------------------------------------------
"@
}
}
function latest_version {
$response = Invoke-RestMethod 'http://dl.dagger.io/dagger/latest_version' -Method 'GET' -Body $body -ErrorAction SilentlyContinue -ErrorVariable DownloadError
If ($DownloadError) {
@"
---------------------------------------------------------------------------
Houston we have a problem!
Apparently we had an issue in downloading the file, please try again
run the script and if it still fail please open an issue on the Dagger repo.
----------------------------------------------------------------------------
"@
exit
}
$response=$response -replace '[""]'
$response=$response -replace '\n'
return $response
}
function base_url {
if ($DaggerVersion) {
$version = $DaggerVersion
} else {
$version = latest_version
}
$url = $base + "/" + $name + "/releases/" + $version
return $url
}
function tarball {
if ($DaggerVersion) {
$version = $DaggerVersion
} else {
$version = latest_version
}
$fileName="dagger_v" + $version + "_windows_amd64"
$filename = $filename + ".zip"
return $filename
}
execute