-
Notifications
You must be signed in to change notification settings - Fork 10
/
install.ps1
110 lines (86 loc) · 2.75 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$ErrorActionPreference = "Stop"
$installDirectory = [IO.Path]::Combine($home, ".shorebird")
function Test-GitInstalled {
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Debug "Git is installed."
}
else {
Write-Output "No git installation detected. Git is required to use shorebird."
exit 1
}
}
function Compare-GitVersions {
param (
[string]$version1,
[string]$version2
)
$version1Components = $version1 -split '\.'
$version2Components = $version2 -split '\.'
for ($i = 0; $i -lt 3; $i++) {
$version1Number = [int]$version1Components[$i]
$version2Number = [int]$version2Components[$i]
if ($version1Number -lt $version2Number) {
return -1
}
elseif ($version1Number -gt $version2Number) {
return 1
}
}
return 0
}
function Test-GitVersion {
$minGitVersion = "2.25.1"
$gitVersion = (Get-Item (Get-Command git).Source).VersionInfo.ProductVersionRaw
$comparisonResult = Compare-GitVersions -version1 $gitVersion -version2 $minGitVersion
if ($comparisonResult -eq -1) {
Write-Output "Installed git version $gitVersion is older than required git version $minGitVersion."
exit 1
}
}
function Update-Path {
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($path.contains($installDirectory)) {
return $false
}
$binPath = [IO.Path]::Combine($installDirectory, "bin")
[Environment]::SetEnvironmentVariable(
"Path", $path + [IO.Path]::PathSeparator + $binPath, "User"
)
return $true
}
Test-GitInstalled
Test-GitVersion
$force = $args -contains "--force"
if (Test-Path $installDirectory) {
if ($force) {
Write-Output "Existing Shorebird installation detected. Overwriting..."
Remove-Item -Recurse -Force $installDirectory
}
else {
Write-Output "Error: Existing Shorebird installation detected. Use --force to overwrite."
return
}
}
Write-Output "Installing Shorebird to $installDirectory..."
& git clone https://github.com/shorebirdtech/shorebird.git -b stable $installDirectory
Push-Location $installDirectory\bin
& .\shorebird.ps1 --version
Pop-Location
$wasPathUpdated = Update-Path
# 1F426 is the code for 🐦. See https://unicode.org/emoji/charts/full-emoji-list.html#1f426.
$birdEmoji = [System.Char]::ConvertFromUtf32([System.Convert]::toInt32("1F426", 16))
Write-Output @"
$birdEmoji Shorebird has been installed!
"@
if ($wasPathUpdated) {
Write-Output @"
Please restart your terminal to start using Shorebird.
"@
}
Write-Output @"
To create an account, visit: https://console.shorebird.dev
Then login using:
shorebird login
For more information, visit:
https://docs.shorebird.dev
"@