1 $ErrorActionPreference = "Stop"
2
3 # =============================================================================
4 # Define base variables
5 # =============================================================================
6
7 $name = "smbcloud-cli"
8 $binary="$name.exe"
9 $version="0.3.26"
10 $githubRepo="https://github.com/smbcloudXYZ/smbcloud-cli"
11 $downloadBaseUrl="https://github.com/$githubRepo/releases/download/$version"
12
13 if ($version -eq "latest") {
14 # The latest version is accessible from a slightly different URL
15 $downloadBaseUrl="https://github.com/$githubRepo/releases/latest/download"
16 }
17
18 # =============================================================================
19 # Determine system architecture and obtain the relevant binary to download
20 # - you can add more "if" conditions to support additional architectures
21 # =============================================================================
22
23 $type = (Get-ComputerInfo).CsSystemType.ToLower()
24 if ($type.StartsWith("x64")) {
25 $downloadFile = "smb"
26 } else {
27 Write-Host "[Error]" -ForegroundColor Red
28 Write-Host "Unsupported Archi<tecture: $type" -ForegroundColor Red
29 [Environment]::Exit(1)
30 }
31
32 # =============================================================================
33 # Create installation directory
34 # =============================================================================
35
36 $destDir = "$env:USERPROFILE\AppData\Local\$name"
37 $destBin = "$destDir\$binary"
38 Write-Host "Creating Install Directory" -ForegroundColor White
39 Write-Host " $destDir"
40
41 # Create the directory if it doesn't exist
42 if (-Not (Test-Path $destDir)) {
43 New-Item -ItemType Directory -Path $destDir
44 }
45
46 # =============================================================================
47 # Download the binary to the installation directory
48 # =============================================================================
49
50 $downloadUrl = "$downloadBaseUrl/$downloadFile"
51 Write-Host "Downloading Binary" -ForegroundColor White
52 Write-Host " From: $downloadUrl"
53 Write-Host " Path: $destBin"
54 Invoke-WebRequest -Uri $downloadUrl -OutFile "$destBin"
55
56 # =============================================================================
57 # Add installation directory to the user's PATH if not present
58 # =============================================================================
59
60 $currentPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)
61 if (-Not ($currentPath -like "*$destDir*")) {
62 Write-Host "Adding Install Directory To System Path" -ForegroundColor White
63 Write-Host " $destBin"
64 [System.Environment]::SetEnvironmentVariable('Path', "$currentPath;$destDir", [System.EnvironmentVariableTarget]::User)
65 }
66
67 # =============================================================================
68 # Display post installation message
69 # =============================================================================
70
71 Write-Host "Installation Complete" -ForegroundColor Green
72 Write-Host " Restart your shell to starting using '$binary'. Run '$binary --help' for more information"