-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall-windows.sh
More file actions
72 lines (58 loc) · 2.99 KB
/
install-windows.sh
File metadata and controls
72 lines (58 loc) · 2.99 KB
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
$ErrorActionPreference = "Stop"
# =============================================================================
# Define base variables
# =============================================================================
$name = "smbcloud-cli"
$binary="$name.exe"
$version="0.3.26"
$githubRepo="https://github.com/smbcloudXYZ/smbcloud-cli"
$downloadBaseUrl="https://github.com/$githubRepo/releases/download/$version"
if ($version -eq "latest") {
# The latest version is accessible from a slightly different URL
$downloadBaseUrl="https://github.com/$githubRepo/releases/latest/download"
}
# =============================================================================
# Determine system architecture and obtain the relevant binary to download
# - you can add more "if" conditions to support additional architectures
# =============================================================================
$type = (Get-ComputerInfo).CsSystemType.ToLower()
if ($type.StartsWith("x64")) {
$downloadFile = "smb"
} else {
Write-Host "[Error]" -ForegroundColor Red
Write-Host "Unsupported Archi<tecture: $type" -ForegroundColor Red
[Environment]::Exit(1)
}
# =============================================================================
# Create installation directory
# =============================================================================
$destDir = "$env:USERPROFILE\AppData\Local\$name"
$destBin = "$destDir\$binary"
Write-Host "Creating Install Directory" -ForegroundColor White
Write-Host " $destDir"
# Create the directory if it doesn't exist
if (-Not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir
}
# =============================================================================
# Download the binary to the installation directory
# =============================================================================
$downloadUrl = "$downloadBaseUrl/$downloadFile"
Write-Host "Downloading Binary" -ForegroundColor White
Write-Host " From: $downloadUrl"
Write-Host " Path: $destBin"
Invoke-WebRequest -Uri $downloadUrl -OutFile "$destBin"
# =============================================================================
# Add installation directory to the user's PATH if not present
# =============================================================================
$currentPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)
if (-Not ($currentPath -like "*$destDir*")) {
Write-Host "Adding Install Directory To System Path" -ForegroundColor White
Write-Host " $destBin"
[System.Environment]::SetEnvironmentVariable('Path', "$currentPath;$destDir", [System.EnvironmentVariableTarget]::User)
}
# =============================================================================
# Display post installation message
# =============================================================================
Write-Host "Installation Complete" -ForegroundColor Green
Write-Host " Restart your shell to starting using '$binary'. Run '$binary --help' for more information"