-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.ps1
109 lines (80 loc) · 4.19 KB
/
index.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
# Copyright (c) 2022 SurrealDB Ltd.
# This is a simple script that can be downloaded and run from
# https://windows.surrealdb.com in order to install the SurrealDB
# command-line tools and database server. It automatically detects
# the host operating platform, and cpu architecture type, and
# downloads the latest binary for the relevant platform.
# This install script attempts to install the SurrealDB binary
# automatically, or otherwise it will prompt the user to specify
# the desired install location.
Param(
[Parameter(Mandatory=$false)]
[Switch]$Nightly
)
function Install {
Write-Output ""
Write-Output " .d8888b. 888 8888888b. 888888b."
Write-Output "d88P Y88b 888 888 'Y88b 888 '88b"
Write-Output "Y88b. 888 888 888 888 .88P"
Write-Output " 'Y888b. 888 888 888d888 888d888 .d88b. 8888b. 888 888 888 8888888K."
Write-Output " 'Y88b. 888 888 888P' 888P' d8P Y8b '88b 888 888 888 888 'Y88b"
Write-Output " '888 888 888 888 888 88888888 .d888888 888 888 888 888 888"
Write-Output "Y88b d88P Y88b 888 888 888 Y8b. 888 888 888 888 .d88P 888 d88P"
Write-Output " 'Y8888P' 'Y88888 888 888 'Y8888 'Y888888 888 8888888P' 8888888P'"
Write-Output ""
# Bail immediately on any error.
$ErrorActionPreference = 'Stop'
# Prevent the pointless progress overlay produced by iwr.
$ProgressPreference = 'SilentlyContinue'
# Specify the base url for binary files
$BaseUrl = "https://download.surrealdb.com"
# Specify the base url for version info
$VersUrl = "https://version.surrealdb.com"
# Ensure proper transport layer security
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Fetch the latest SurrealDB version
if ($Nightly -eq $false) {
Write-Output "Fetching the latest database version..."
$Version = (Invoke-WebRequest $VersUrl -UseBasicParsing).Content.trim()
} else {
$Version = "nightly"
}
# Compute the current system architecture
Write-Output "Fetching the host system architecture..."
$Arch = "windows-" + "amd64"
# Define the latest SurrealDB download url
$DownloadUrl = "$BaseUrl/${Version}/surreal-${Version}.${Arch}.exe"
Write-Output "Installing surreal-$Version for $Arch..."
try {
$Directory = Join-Path "C:" "Program Files"
$Directory = Join-Path $Directory "SurrealDB"
$Executable = Join-Path $Directory "surreal.exe"
# Create a new directory for the SurrealDB binary
New-Item $Directory -Force -ItemType Directory | Out-Null
# Download and install the latest SurrealDB binary
Invoke-WebRequest $DownloadUrl -OutFile $Executable -UseBasicParsing
# Update the user environment variable to include SurrealDB
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";" + $Directory, "User")
} catch {
$Directory = Join-Path $env:LOCALAPPDATA "SurrealDB"
$Executable = Join-Path $Directory "surreal.exe"
# Create a new directory for the SurrealDB binary
New-Item $Directory -Force -ItemType Directory | Out-Null
# Download and install the latest SurrealDB binary
Invoke-WebRequest $DownloadUrl -OutFile $Executable -UseBasicParsing
# Update the user environment variable to include SurrealDB
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";" + $Directory, "User")
}
Write-Output ""
Write-Output "SurrealDB successfully installed in:"
Write-Output " $Executable"
Write-Output ""
Write-Output "To see the command-line options run:"
Write-Output " surreal help"
Write-Output "To start an in-memory database server run:"
Write-Output " surreal start --log debug --user root --pass root memory"
Write-Output "For help with getting started visit:"
Write-Output " https://surrealdb.com/docs"
Write-Output ""
}
Install