Skip to content

Commit 7df9af3

Browse files
authored
Update Install.ps1
1 parent a978dad commit 7df9af3

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

Install.ps1

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,50 @@ param (
22
[string]$Version
33
)
44

5+
# Function to get the installed dcli version
6+
function Get-InstalledDcliVersion {
7+
try {
8+
$output = & dcli -v 2>$null
9+
if ($output -match 'dcli version (\d+\.\d+\.\d+)') {
10+
return $matches[1]
11+
}
12+
} catch {
13+
# dcli is not installed or not in PATH
14+
}
15+
return $null
16+
}
17+
18+
# Determine the version to install
519
if (-not $Version) {
6-
Write-Host "🔍 No version provided, fetching latest release..."
20+
Write-Host "No version provided, fetching latest release..."
721
$Version = (Invoke-RestMethod -Uri "https://api.github.com/repos/we-dcode/dcli/releases/latest").tag_name
822
}
923

24+
# Check the installed version
25+
$installedVersion = Get-InstalledDcliVersion
26+
if ($installedVersion -eq $Version) {
27+
Write-Host "dcli version $Version is already installed. Skipping download."
28+
exit 0
29+
}
30+
31+
# Proceed with installation
1032
$Os = "windows"
1133
$Arch = "amd64"
1234
$ZipName = "dcli_${Version}_${Os}_${Arch}.zip"
1335
$DownloadUrl = "https://github.com/we-dcode/dcli/releases/download/$Version/$ZipName"
1436
$TargetDir = "C:\Program Files\Dcode"
1537
$TempZip = "$env:TEMP\dcli.zip"
1638

17-
Write-Host "📦 Downloading dcli $Version for $Os/$Arch..."
39+
Write-Host "Downloading dcli $Version for $Os/$Arch..."
1840
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip
1941

20-
Write-Host "📂 Extracting to $TargetDir..."
42+
Write-Host "Extracting to $TargetDir..."
2143
if (!(Test-Path -Path $TargetDir)) {
2244
New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null
2345
}
24-
2546
Expand-Archive -Path $TempZip -DestinationPath $TargetDir -Force
2647

2748
Write-Host "✅ dcli installed to '$TargetDir\dcli.exe'"
2849

29-
Write-Host "`n👉 Add to PATH if needed:"
30-
Write-Host " setx PATH '`$env:PATH;$TargetDir' /M"
50+
Write-Host "`nAdd to PATH if needed:"
51+
Write-Host "setx PATH '`$env:PATH;$TargetDir' /M"

0 commit comments

Comments
 (0)