Files
Claude-Code-Workflow/install-remote.ps1
catlog22 c39f311a20 feat: Add version selection support to installation scripts
Enhanced both Windows and Linux/macOS installation scripts with flexible version selection:

New Features:
- Version selection: stable (default), latest, or branch
- Specific release tag installation (e.g., v3.2.0)
- Auto-detection of latest stable release via GitHub API
- Clear version information displayed during installation

Installation Script Updates:
- install-remote.ps1: Added -Version, -Tag parameters
- install-remote.sh: Added --version, --tag flags
- Updated help documentation with examples
- Improved user prompts with version information

Documentation Updates:
- README.md: Added installation examples for all version types
- README_CN.md: Added Chinese installation examples
- Clear distinction between stable, latest, and specific versions

Examples:
- Stable (recommended): Default one-liner installation
- Latest: --version latest flag
- Specific: --version stable --tag v3.2.0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 12:37:29 +08:00

434 lines
13 KiB
PowerShell

#!/usr/bin/env pwsh
<#
.SYNOPSIS
Claude Code Workflow (CCW) - Remote Installation Script
.DESCRIPTION
One-liner remote installation for Claude Code Workflow system.
Downloads and installs CCW from GitHub with flexible version selection.
.PARAMETER Version
Installation version type:
- "stable" (default): Latest stable release tag
- "latest": Latest main branch (development version)
- "branch": Install from specific branch
.PARAMETER Tag
Specific release tag to install (e.g., "v3.2.0")
Only used when Version is "stable"
.PARAMETER Branch
Branch name to install from (default: "main")
Only used when Version is "branch"
.PARAMETER Global
Install to global user directory (~/.claude)
.PARAMETER Directory
Install to custom directory
.PARAMETER Force
Skip confirmation prompts
.PARAMETER NoBackup
Skip backup of existing installation
.PARAMETER NonInteractive
Run in non-interactive mode
.PARAMETER BackupAll
Backup all files including git-ignored files
.EXAMPLE
# Install latest stable release (recommended)
.\install-remote.ps1
.EXAMPLE
# Install specific stable version
.\install-remote.ps1 -Version stable -Tag "v3.2.0"
.EXAMPLE
# Install latest development version
.\install-remote.ps1 -Version latest
.EXAMPLE
# Install from specific branch
.\install-remote.ps1 -Version branch -Branch "feature/new-feature"
.EXAMPLE
# Install to global directory without prompts
.\install-remote.ps1 -Global -Force
.LINK
https://github.com/catlog22/Claude-Code-Workflow
#>
[CmdletBinding()]
param(
[ValidateSet("stable", "latest", "branch")]
[string]$Version = "stable",
[string]$Tag = "",
[string]$Branch = "main",
[switch]$Global,
[string]$Directory = "",
[switch]$Force,
[switch]$NoBackup,
[switch]$NonInteractive,
[switch]$BackupAll
)
# Set encoding for proper Unicode support
if ($PSVersionTable.PSVersion.Major -ge 6) {
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
} else {
# Windows PowerShell 5.1
$OutputEncoding = [System.Text.Encoding]::UTF8
chcp 65001 | Out-Null
}
# Script metadata
$ScriptName = "Claude Code Workflow (CCW) Remote Installer"
$InstallerVersion = "2.2.0"
# Colors for output
$ColorSuccess = "Green"
$ColorInfo = "Cyan"
$ColorWarning = "Yellow"
$ColorError = "Red"
function Write-ColorOutput {
param(
[string]$Message,
[string]$Color = "White"
)
Write-Host $Message -ForegroundColor $Color
}
function Show-Header {
Write-ColorOutput "==== $ScriptName v$InstallerVersion ====" $ColorInfo
Write-ColorOutput "========================================================" $ColorInfo
Write-Host ""
}
function Test-Prerequisites {
# Test PowerShell version
if ($PSVersionTable.PSVersion.Major -lt 5) {
Write-ColorOutput "ERROR: PowerShell 5.1 or higher is required" $ColorError
Write-ColorOutput "Current version: $($PSVersionTable.PSVersion)" $ColorError
return $false
}
# Test internet connectivity
try {
$null = Invoke-WebRequest -Uri "https://github.com" -Method Head -TimeoutSec 10 -UseBasicParsing
Write-ColorOutput "Network connection OK" $ColorSuccess
} catch {
Write-ColorOutput "ERROR: Cannot connect to GitHub" $ColorError
Write-ColorOutput "Please check your network connection: $($_.Exception.Message)" $ColorError
return $false
}
return $true
}
function Get-TempDirectory {
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) "claude-code-workflow-install"
if (Test-Path $tempDir) {
Remove-Item -Path $tempDir -Recurse -Force
}
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
return $tempDir
}
function Get-LatestRelease {
try {
$apiUrl = "https://api.github.com/repos/catlog22/Claude-Code-Workflow/releases/latest"
$response = Invoke-RestMethod -Uri $apiUrl -UseBasicParsing
return $response.tag_name
} catch {
Write-ColorOutput "WARNING: Failed to fetch latest release, using 'main' branch" $ColorWarning
return $null
}
}
function Download-Repository {
param(
[string]$TempDir,
[string]$Version = "stable",
[string]$Branch = "main",
[string]$Tag = ""
)
$repoUrl = "https://github.com/catlog22/Claude-Code-Workflow"
# Determine download URL based on version type
if ($Version -eq "stable") {
# Download latest stable release
if ([string]::IsNullOrEmpty($Tag)) {
$latestTag = Get-LatestRelease
if ($latestTag) {
$Tag = $latestTag
} else {
# Fallback to main branch if API fails
$zipUrl = "$repoUrl/archive/refs/heads/main.zip"
$downloadType = "main branch (fallback)"
}
}
if (-not [string]::IsNullOrEmpty($Tag)) {
$zipUrl = "$repoUrl/archive/refs/tags/$Tag.zip"
$downloadType = "stable release $Tag"
}
} elseif ($Version -eq "latest") {
# Download latest main branch
$zipUrl = "$repoUrl/archive/refs/heads/main.zip"
$downloadType = "latest main branch"
} else {
# Download specific branch
$zipUrl = "$repoUrl/archive/refs/heads/$Branch.zip"
$downloadType = "branch $Branch"
}
$zipPath = Join-Path $TempDir "repo.zip"
Write-ColorOutput "Downloading from GitHub..." $ColorInfo
Write-ColorOutput "Source: $repoUrl" $ColorInfo
Write-ColorOutput "Type: $downloadType" $ColorInfo
try {
# Download with progress
$progressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing
$ProgressPreference = $progressPreference
if (Test-Path $zipPath) {
$fileSize = (Get-Item $zipPath).Length
Write-ColorOutput "Download complete ($([math]::Round($fileSize/1024/1024, 2)) MB)" $ColorSuccess
return $zipPath
} else {
throw "Downloaded file does not exist"
}
} catch {
Write-ColorOutput "Download failed: $($_.Exception.Message)" $ColorError
return $null
}
}
function Extract-Repository {
param(
[string]$ZipPath,
[string]$TempDir
)
Write-ColorOutput "Extracting files..." $ColorInfo
try {
# Use .NET to extract zip
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipPath, $TempDir)
# Find the extracted directory (usually repo-name-branch)
$extractedDirs = Get-ChildItem -Path $TempDir -Directory
$repoDir = $extractedDirs | Where-Object { $_.Name -like "Claude-Code-Workflow-*" } | Select-Object -First 1
if ($repoDir) {
Write-ColorOutput "Extraction complete: $($repoDir.FullName)" $ColorSuccess
return $repoDir.FullName
} else {
throw "Could not find extracted repository directory"
}
} catch {
Write-ColorOutput "Extraction failed: $($_.Exception.Message)" $ColorError
return $null
}
}
function Invoke-LocalInstaller {
param(
[string]$RepoDir
)
$installerPath = Join-Path $RepoDir "Install-Claude.ps1"
if (-not (Test-Path $installerPath)) {
Write-ColorOutput "ERROR: Install-Claude.ps1 not found" $ColorError
return $false
}
Write-ColorOutput "Running local installer..." $ColorInfo
Write-Host ""
# Build parameters for local installer
$params = @{}
if ($Global) { $params["InstallMode"] = "Global" }
if ($Directory) {
$params["InstallMode"] = "Custom"
$params["TargetPath"] = $Directory
}
if ($Force) { $params["Force"] = $Force }
if ($NoBackup) { $params["NoBackup"] = $NoBackup }
if ($NonInteractive) { $params["NonInteractive"] = $NonInteractive }
if ($BackupAll) { $params["BackupAll"] = $BackupAll }
try {
# Change to repo directory and run installer
Push-Location $RepoDir
if ($params.Count -gt 0) {
$paramList = ($params.GetEnumerator() | ForEach-Object { "-$($_.Key) $($_.Value)" }) -join " "
Write-ColorOutput "Executing: & `"$installerPath`" $paramList" $ColorInfo
& $installerPath @params
} else {
Write-ColorOutput "Executing: & `"$installerPath`"" $ColorInfo
& $installerPath
}
Pop-Location
return $true
} catch {
Pop-Location
Write-ColorOutput "Installation script failed: $($_.Exception.Message)" $ColorError
return $false
}
}
function Cleanup-TempFiles {
param(
[string]$TempDir
)
if (Test-Path $TempDir) {
try {
Remove-Item -Path $TempDir -Recurse -Force
Write-ColorOutput "Temporary files cleaned up" $ColorInfo
} catch {
Write-ColorOutput "WARNING: Failed to clean temporary files: $($_.Exception.Message)" $ColorWarning
}
}
}
function Wait-ForUserConfirmation {
param(
[string]$Message = "Press any key to continue...",
[switch]$ExitAfter
)
if (-not $NonInteractive) {
Write-Host ""
Write-ColorOutput $Message $ColorInfo
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}
if ($ExitAfter) {
exit 0
}
}
function Main {
Show-Header
Write-ColorOutput "This will download and install Claude Code Workflow System from GitHub." $ColorInfo
Write-Host ""
# Test prerequisites
Write-ColorOutput "Checking system requirements..." $ColorInfo
if (-not (Test-Prerequisites)) {
Wait-ForUserConfirmation "System check failed! Press any key to exit..." -ExitAfter
}
# Determine version information for display
$versionInfo = switch ($Version) {
"stable" {
if ($Tag) { "Stable release: $Tag" }
else { "Latest stable release (auto-detected)" }
}
"latest" { "Latest main branch (development)" }
"branch" { "Custom branch: $Branch" }
}
# Confirm installation
if (-not $NonInteractive -and -not $Force) {
Write-Host ""
Write-ColorOutput "INSTALLATION DETAILS:" $ColorInfo
Write-Host "- Repository: https://github.com/catlog22/Claude-Code-Workflow"
Write-Host "- Version: $versionInfo"
Write-Host "- Features: Intelligent workflow orchestration with multi-agent coordination"
Write-Host ""
Write-ColorOutput "SECURITY NOTE:" $ColorWarning
Write-Host "- This script will download and execute code from GitHub"
Write-Host "- Please ensure you trust this source"
Write-Host ""
$choice = Read-Host "Continue with installation? (y/N)"
if ($choice -notmatch '^[Yy]') {
Write-ColorOutput "Installation cancelled" $ColorWarning
Wait-ForUserConfirmation -ExitAfter
}
}
# Create temp directory
$tempDir = Get-TempDirectory
Write-ColorOutput "Temporary directory: $tempDir" $ColorInfo
try {
# Download repository
$zipPath = Download-Repository -TempDir $tempDir -Version $Version -Branch $Branch -Tag $Tag
if (-not $zipPath) {
throw "Download failed"
}
# Extract repository
$repoDir = Extract-Repository $zipPath $tempDir
if (-not $repoDir) {
throw "Extraction failed"
}
# Run local installer
$success = Invoke-LocalInstaller $repoDir
if (-not $success) {
throw "Installation script failed"
}
Write-Host ""
Write-ColorOutput "Remote installation completed successfully!" $ColorSuccess
} catch {
Write-Host ""
Write-ColorOutput "Remote installation failed: $($_.Exception.Message)" $ColorError
Wait-ForUserConfirmation "Installation failed! Press any key to exit..." -ExitAfter
} finally {
# Cleanup
Cleanup-TempFiles $tempDir
}
Write-Host ""
Write-ColorOutput "Next steps:" $ColorInfo
Write-Host "1. Review CLAUDE.md for project-specific guidelines"
Write-Host "2. Try /workflow commands for Agent coordination"
Write-Host "3. Use /update-memory to manage distributed documentation"
Wait-ForUserConfirmation "Remote installation done! Press any key to exit..." -ExitAfter
}
# Run main function
try {
Main
} catch {
Write-ColorOutput "CRITICAL ERROR: $($_.Exception.Message)" $ColorError
Write-Host ""
Wait-ForUserConfirmation "A critical error occurred! Press any key to exit..." -ExitAfter
}