Skip to content

Commit be60c54

Browse files
committed
feat: add check-update and update commands
1 parent 8f8a106 commit be60c54

3 files changed

Lines changed: 135 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ claude-code-sync pull
103103
| `reset` | Delete all sync data (⚠️ deletes key!) |
104104
| `reset --keep-key` | Reset but preserve your private key |
105105
| `unlink` | Disconnect from remote repo (keep local data) |
106+
| `check-update` | Check if a new version is available |
107+
| `update` | Download and install latest version |
106108
| `help` | Show help |
107109

108110
## What Gets Synced

claude-code-sync

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,66 @@ cmd_unlink() {
599599
fi
600600
}
601601

602+
get_remote_version() {
603+
local url="https://raw.githubusercontent.com/felixisaac/claude-code-sync/main/claude-code-sync"
604+
local content
605+
content=$(curl -fsSL --connect-timeout 10 "$url" 2>/dev/null) || return 1
606+
echo "$content" | grep -oP 'VERSION="\K[^"]+' | head -1
607+
}
608+
609+
cmd_check_update() {
610+
log_info "Checking for updates..."
611+
612+
local remote_version
613+
remote_version=$(get_remote_version)
614+
615+
if [[ -z "$remote_version" ]]; then
616+
log_warn "Could not fetch remote version. Check your internet connection."
617+
return
618+
fi
619+
620+
echo "Local version: v$VERSION"
621+
echo "Remote version: v$remote_version"
622+
623+
if [[ "$VERSION" == "$remote_version" ]]; then
624+
log_success "You're up to date!"
625+
else
626+
echo ""
627+
echo -e "Update available! Run: ${BLUE}claude-code-sync update${NC}"
628+
fi
629+
}
630+
631+
cmd_update() {
632+
log_info "Checking for updates..."
633+
634+
local remote_version
635+
remote_version=$(get_remote_version)
636+
637+
if [[ -z "$remote_version" ]]; then
638+
die "Could not fetch remote version. Check your internet connection."
639+
fi
640+
641+
if [[ "$VERSION" == "$remote_version" ]]; then
642+
log_success "Already up to date (v$VERSION)"
643+
return
644+
fi
645+
646+
log_info "Updating v$VERSION -> v$remote_version..."
647+
648+
# Find where we're installed
649+
local script_path
650+
script_path=$(command -v claude-code-sync 2>/dev/null || echo "$HOME/.local/bin/claude-code-sync")
651+
652+
# Download new version
653+
local url="https://raw.githubusercontent.com/felixisaac/claude-code-sync/main/claude-code-sync"
654+
if curl -fsSL "$url" -o "$script_path"; then
655+
chmod +x "$script_path"
656+
log_success "Updated to v$remote_version!"
657+
else
658+
die "Failed to download update"
659+
fi
660+
}
661+
602662
cmd_version() {
603663
echo "claude-code-sync v$VERSION"
604664
}
@@ -621,6 +681,8 @@ COMMANDS:
621681
reset Delete all sync data (WARNING: deletes key!)
622682
reset --keep-key Reset but preserve your private key
623683
unlink Disconnect from remote repo (keep local data)
684+
check-update Check if a new version is available
685+
update Download and install latest version
624686
version Show version
625687
help Show this help
626688
@@ -678,6 +740,8 @@ main() {
678740
reset) cmd_reset "$@" ;;
679741
destroy) cmd_reset "$@" ;; # Alias for reset
680742
unlink) cmd_unlink "$@" ;;
743+
check-update) cmd_check_update ;;
744+
update) cmd_update ;;
681745
version|-v|--version) cmd_version ;;
682746
help|-h|--help) cmd_help ;;
683747
*) die "Unknown command: $cmd. Run 'claude-code-sync help' for usage." ;;

claude-code-sync.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,71 @@ function Invoke-Unlink {
615615
}
616616
}
617617

618+
function Get-RemoteVersion {
619+
try {
620+
$url = "https://raw.githubusercontent.com/felixisaac/claude-code-sync/main/claude-code-sync.ps1"
621+
$content = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 10
622+
if ($content.Content -match '\$VERSION\s*=\s*"([^"]+)"') {
623+
return $Matches[1]
624+
}
625+
} catch {
626+
return $null
627+
}
628+
return $null
629+
}
630+
631+
function Invoke-CheckUpdate {
632+
Write-Info "Checking for updates..."
633+
$remoteVersion = Get-RemoteVersion
634+
635+
if (-not $remoteVersion) {
636+
Write-Warn "Could not fetch remote version. Check your internet connection."
637+
return
638+
}
639+
640+
Write-Host "Local version: v$VERSION"
641+
Write-Host "Remote version: v$remoteVersion"
642+
643+
if ($VERSION -eq $remoteVersion) {
644+
Write-Success "You're up to date!"
645+
} else {
646+
Write-Host ""
647+
Write-Host "Update available! Run: " -NoNewline
648+
Write-Host "claude-code-sync update" -ForegroundColor Cyan
649+
}
650+
}
651+
652+
function Invoke-Update {
653+
Write-Info "Checking for updates..."
654+
$remoteVersion = Get-RemoteVersion
655+
656+
if (-not $remoteVersion) {
657+
throw "Could not fetch remote version. Check your internet connection."
658+
}
659+
660+
if ($VERSION -eq $remoteVersion) {
661+
Write-Success "Already up to date (v$VERSION)"
662+
return
663+
}
664+
665+
Write-Info "Updating v$VERSION -> v$remoteVersion..."
666+
667+
# Find where we're installed
668+
$scriptPath = $MyInvocation.ScriptName
669+
if (-not $scriptPath) {
670+
$scriptPath = Join-Path (Join-Path $env:USERPROFILE ".local\bin") "claude-code-sync.ps1"
671+
}
672+
673+
# Download new version
674+
$url = "https://raw.githubusercontent.com/felixisaac/claude-code-sync/main/claude-code-sync.ps1"
675+
try {
676+
Invoke-WebRequest -Uri $url -OutFile $scriptPath -UseBasicParsing
677+
Write-Success "Updated to v$remoteVersion!"
678+
} catch {
679+
throw "Failed to download update: $_"
680+
}
681+
}
682+
618683
function Show-Version {
619684
Write-Host "claude-code-sync v$VERSION"
620685
}
@@ -637,6 +702,8 @@ COMMANDS:
637702
reset Delete all sync data (WARNING: deletes key!)
638703
reset --keep-key Reset but preserve your private key
639704
unlink Disconnect from remote repo (keep local data)
705+
check-update Check if a new version is available
706+
update Download and install latest version
640707
version Show version
641708
help Show this help
642709
@@ -674,6 +741,8 @@ switch ($Command.ToLower()) {
674741
}
675742
"destroy" { Invoke-Reset } # Alias for reset
676743
"unlink" { Invoke-Unlink }
744+
"check-update" { Invoke-CheckUpdate }
745+
"update" { Invoke-Update }
677746
"version" { Show-Version }
678747
"-v" { Show-Version }
679748
"--version" { Show-Version }

0 commit comments

Comments
 (0)