-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.ps1
99 lines (91 loc) · 2.38 KB
/
setup.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
94
95
96
97
98
99
# Store the current location to restore it at the end of the script.
$current_location = Get-Location
# Determine the release archive for the used platform and architecture.
# For this Windows script this is currently only x64.
$platform = [System.Environment]::OSVersion.Platform
$architecture = [System.Environment]::Is64BitOperatingSystem
switch -wildcard ($platform)
{
"Win32NT"
{
switch -wildcard ($architecture)
{
"True"
{
$archive = "webui-windows-msvc-x64.zip"
}
default
{
Write-Host "The setup script currently does not support $arch architectures on Windows."
exit 1
}
}
}
default
{
Write-Host "The setup script currently does not support $platform."
exit 1
}
}
# Parse CLI arguments.
# Defaults
$output = Join-Path $PSScriptRoot "webui"
# Default to `nightly` until WebUI 2.5.0 release. Earlier versions do not support odin-webui.
$version = "nightly"
for ($i = 0; $i -lt $args.Length; $i++)
{
switch -wildcard ($args[$i])
{
'--output'
{
$output = $args[$i + 1]
$i++
break
}
'--nightly'
{
$version = "nightly"
break
}
'--help'
{
Write-Host "Usage: setup.ps1 [flags]"
Write-Host ""
Write-Host "Flags:"
Write-Host " -o, --output: Specify the output directory"
Write-Host " --nightly: Download the latest nightly release"
Write-Host " -h, --help: Display this help message"
exit 0
}
default
{
Write-Host "Unknown option: $($args[$i])"
exit 1
}
}
}
$archive_dir = $archive.Replace(".zip", "")
# Clean old library files in case they exist.
Remove-Item -Path $archive -ErrorAction SilentlyContinue
Remove-Item -Path $archive_dir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path $output -Recurse -Force -ErrorAction SilentlyContinue
$release_base_url = "https://github.com/webui-dev/webui/releases"
if ($version -eq "nightly")
{
$url = "$release_base_url/download/$version/$archive"
} else
{
$url = "$release_base_url/latest/download/$archive"
}
Write-Host "$url"
# Download and extract the archive.
Write-Host "Downloading WebUI@$version..."
Invoke-WebRequest -Uri $url -OutFile $archive
Write-Host "Extracting..."
Expand-Archive -LiteralPath $archive
Move-Item -Path $archive_dir\$archive_dir -Destination $output
# Clean downloaded files and residues.
Remove-Item -Path $archive -Force
Remove-Item -Path $archive_dir -Recurse -Force
Write-Host "Done."
Set-Location $current_location