Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions static/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions static/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down Expand Up @@ -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
}
Expand Down
Loading