diff --git a/static/install.ps1 b/static/install.ps1 index c7838d4..5e3321f 100644 --- a/static/install.ps1 +++ b/static/install.ps1 @@ -38,6 +38,25 @@ function Get-Architecture { } } +# Get the current installed version +function Get-CurrentVersion { + try { + # Check if docfind is in PATH and can be executed + $currentVersionOutput = & $BinaryName --version 2>&1 + if ($LASTEXITCODE -eq 0 -and $currentVersionOutput) { + # Extract version from "docfind X.Y.Z" output + $versionMatch = $currentVersionOutput -match "^$BinaryName\s+(.+)$" + if ($versionMatch -and $Matches[1]) { + return $Matches[1].Trim() + } + } + } + catch { + # Binary not found or not executable + } + return $null +} + # Get the latest release version function Get-LatestVersion { Write-Info "Fetching latest release..." @@ -218,6 +237,22 @@ function Main { Write-Info "Detected platform: $target" $version = Get-LatestVersion + + # Check if already installed with the same version + $currentVersion = Get-CurrentVersion + if ($currentVersion) { + Write-Info "Current version: $currentVersion" + # Strip 'v' prefix from version if present for comparison + $latestVersionNum = $version -replace '^v', '' + if ($currentVersion -eq $latestVersionNum -or $currentVersion -eq $version) { + Write-Info "$BinaryName $currentVersion is already installed (latest version)" + Write-Host "" + Write-Host "If you want to reinstall, please uninstall first:" -ForegroundColor Cyan + Write-Host " Remove-Item (Get-Command $BinaryName).Path" -ForegroundColor Green + exit 0 + } + } + Install-Binary -Version $version -Target $target $pathUpdated = $false diff --git a/static/install.sh b/static/install.sh index b4eb972..fd47946 100644 --- a/static/install.sh +++ b/static/install.sh @@ -62,6 +62,17 @@ detect_platform() { info "Detected platform: $TARGET" } +# Get the current installed version +get_current_version() { + if command -v "$BINARY_NAME" >/dev/null 2>&1; then + # Extract version from "docfind X.Y.Z" output + CURRENT_VERSION=$("$BINARY_NAME" --version 2>/dev/null | sed -E 's/^[^ ]+ //') + if [ -n "$CURRENT_VERSION" ]; then + echo "$CURRENT_VERSION" + fi + fi +} + # Get the latest release version get_latest_version() { info "Fetching latest release..." @@ -184,6 +195,22 @@ main() { detect_platform get_latest_version + + # Check if already installed with the same version + CURRENT_VERSION=$(get_current_version) + if [ -n "$CURRENT_VERSION" ]; then + info "Current version: $CURRENT_VERSION" + # Strip 'v' prefix from VERSION if present for comparison + LATEST_VERSION_NUM=$(echo "$VERSION" | sed 's/^v//') + if [ "$CURRENT_VERSION" = "$LATEST_VERSION_NUM" ] || [ "$CURRENT_VERSION" = "$VERSION" ]; then + info "$BINARY_NAME $CURRENT_VERSION is already installed (latest version)" + echo "" + echo "If you want to reinstall, please uninstall first:" + echo " ${GREEN}rm \$(which $BINARY_NAME)${NC}" + exit 0 + fi + fi + install_binary post_install }