1+ # PowerShell Installation Script for Syncable CLI on Windows
2+ # Usage: powershell -ExecutionPolicy Bypass -File install.ps1
3+
4+ param (
5+ [string ]$Version = " latest" ,
6+ [string ]$InstallDir = " $env: USERPROFILE \.local\bin" ,
7+ [switch ]$Force = $false ,
8+ [switch ]$Help = $false
9+ )
10+
11+ # Color functions for better output
12+ function Write-Success {
13+ param ([string ]$Message )
14+ Write-Host " ✅ $Message " - ForegroundColor Green
15+ }
16+
17+ function Write-Info {
18+ param ([string ]$Message )
19+ Write-Host " ℹ️ $Message " - ForegroundColor Blue
20+ }
21+
22+ function Write-Warning {
23+ param ([string ]$Message )
24+ Write-Host " ⚠️ $Message " - ForegroundColor Yellow
25+ }
26+
27+ function Write-Error {
28+ param ([string ]$Message )
29+ Write-Host " ❌ $Message " - ForegroundColor Red
30+ }
31+
32+ function Write-Step {
33+ param ([string ]$Message )
34+ Write-Host " 🔧 $Message " - ForegroundColor Cyan
35+ }
36+
37+ # Help function
38+ function Show-Help {
39+ Write-Host @"
40+ Syncable CLI Installer for Windows
41+
42+ Usage: powershell -ExecutionPolicy Bypass -File install.ps1 [OPTIONS]
43+
44+ Options:
45+ -Version <version> Install specific version (default: latest)
46+ -InstallDir <path> Installation directory (default: %USERPROFILE%\.local\bin)
47+ -Force Force installation even if already installed
48+ -Help Show this help message
49+
50+ Examples:
51+ .\install.ps1 # Install latest version
52+ .\install.ps1 -Version "0.9.0" # Install specific version
53+ .\install.ps1 -Force # Force reinstall
54+ .\install.ps1 -InstallDir "C:\tools" # Custom installation directory
55+
56+ "@
57+ }
58+
59+ # Check if help is requested
60+ if ($Help ) {
61+ Show-Help
62+ exit 0
63+ }
64+
65+ Write-Host @"
66+ 🚀 Syncable CLI Installer for Windows
67+ ====================================
68+ "@ - ForegroundColor Magenta
69+
70+ # Check if running as administrator (optional, for system-wide installs)
71+ $isAdmin = ([Security.Principal.WindowsPrincipal ] [Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ] " Administrator" )
72+ if ($isAdmin ) {
73+ Write-Info " Running as Administrator - can install system-wide"
74+ } else {
75+ Write-Info " Running as regular user - installing to user directory"
76+ }
77+
78+ # Check if cargo is available
79+ Write-Step " Checking for Rust/Cargo installation..."
80+ try {
81+ $cargoVersion = cargo -- version 2> $null
82+ if ($LASTEXITCODE -eq 0 ) {
83+ Write-Success " Found Cargo: $cargoVersion "
84+ $hasRust = $true
85+ } else {
86+ $hasRust = $false
87+ }
88+ } catch {
89+ $hasRust = $false
90+ }
91+
92+ if (-not $hasRust ) {
93+ Write-Warning " Rust/Cargo not found. Installing via cargo is not available."
94+ Write-Info " To install Rust, visit: https://rustup.rs/"
95+ Write-Info " Or download pre-built binaries from: https://github.com/syncable-dev/syncable-cli/releases"
96+
97+ # Offer to open browser
98+ $response = Read-Host " Would you like to open the Rust installation page? (y/N)"
99+ if ($response -eq " y" -or $response -eq " Y" ) {
100+ Start-Process " https://rustup.rs/"
101+ }
102+ exit 1
103+ }
104+
105+ # Check if sync-ctl is already installed
106+ Write-Step " Checking for existing installation..."
107+ try {
108+ $existingVersion = sync-ctl -- version 2> $null
109+ if ($LASTEXITCODE -eq 0 ) {
110+ Write-Info " Found existing installation: $existingVersion "
111+ if (-not $Force ) {
112+ $response = Read-Host " sync-ctl is already installed. Reinstall? (y/N)"
113+ if ($response -ne " y" -and $response -ne " Y" ) {
114+ Write-Info " Installation cancelled."
115+ exit 0
116+ }
117+ }
118+ }
119+ } catch {
120+ Write-Info " No existing installation found."
121+ }
122+
123+ # Install via cargo
124+ Write-Step " Installing Syncable CLI via Cargo..."
125+ Write-Info " This may take a few minutes..."
126+
127+ try {
128+ if ($Version -eq " latest" ) {
129+ Write-Info " Installing latest version from crates.io..."
130+ $installResult = cargo install syncable- cli 2>&1
131+ } else {
132+ Write-Info " Installing version $Version from crates.io..."
133+ $installResult = cargo install syncable- cli -- version $Version 2>&1
134+ }
135+
136+ if ($LASTEXITCODE -eq 0 ) {
137+ Write-Success " Syncable CLI installed successfully!"
138+ } else {
139+ Write-Error " Installation failed. Cargo output:"
140+ Write-Host $installResult - ForegroundColor Red
141+ exit 1
142+ }
143+ } catch {
144+ Write-Error " Installation failed: $_ "
145+ exit 1
146+ }
147+
148+ # Verify installation
149+ Write-Step " Verifying installation..."
150+ try {
151+ $version = sync-ctl -- version 2> $null
152+ if ($LASTEXITCODE -eq 0 ) {
153+ Write-Success " Installation verified: $version "
154+ } else {
155+ Write-Warning " Installation may have issues. sync-ctl command not found."
156+ }
157+ } catch {
158+ Write-Warning " Could not verify installation."
159+ }
160+
161+ # Check PATH
162+ Write-Step " Checking PATH configuration..."
163+ $cargoPath = " $env: USERPROFILE \.cargo\bin"
164+ $currentPath = $env: PATH
165+ if ($currentPath -like " *$cargoPath *" ) {
166+ Write-Success " Cargo bin directory is already in PATH"
167+ } else {
168+ Write-Warning " Cargo bin directory ($cargoPath ) is not in your PATH"
169+ Write-Info " To add it permanently:"
170+ Write-Info " 1. Open System Properties > Advanced > Environment Variables"
171+ Write-Info " 2. Add '$cargoPath ' to your PATH variable"
172+ Write-Info " 3. Restart your terminal/PowerShell session"
173+ Write-Info " "
174+ Write-Info " Or run this command in an elevated PowerShell:"
175+ Write-Info " [Environment]::SetEnvironmentVariable('PATH', `$ env:PATH + ';$cargoPath ', 'User')"
176+
177+ # Offer to add to PATH automatically
178+ $response = Read-Host " Would you like to add it to PATH now? (y/N)"
179+ if ($response -eq " y" -or $response -eq " Y" ) {
180+ try {
181+ [Environment ]::SetEnvironmentVariable(' PATH' , $env: PATH + " ;$cargoPath " , ' User' )
182+ $env: PATH += " ;$cargoPath " # Update current session
183+ Write-Success " Added to PATH. Restart PowerShell to ensure it takes effect."
184+ } catch {
185+ Write-Error " Failed to add to PATH: $_ "
186+ Write-Info " Please add manually as described above."
187+ }
188+ }
189+ }
190+
191+ # Install vulnerability scanning tools
192+ Write-Step " Setting up vulnerability scanning tools..."
193+ Write-Info " Installing common security tools for better analysis..."
194+
195+ # Install tools that work well on Windows
196+ $tools = @ (
197+ @ {Name = " cargo-audit" ; Command = " cargo install cargo-audit" ; Check = " cargo audit --version" },
198+ @ {Name = " pip-audit" ; Command = " pip install --user pip-audit" ; Check = " pip-audit --version" }
199+ )
200+
201+ foreach ($tool in $tools ) {
202+ Write-Info " Installing $ ( $tool.Name ) ..."
203+ try {
204+ # Check if already installed
205+ $checkResult = Invoke-Expression $tool.Check 2> $null
206+ if ($LASTEXITCODE -eq 0 ) {
207+ Write-Success " $ ( $tool.Name ) is already installed"
208+ continue
209+ }
210+
211+ # Install the tool
212+ $installResult = Invoke-Expression $tool.Command 2>&1
213+ if ($LASTEXITCODE -eq 0 ) {
214+ Write-Success " $ ( $tool.Name ) installed successfully"
215+ } else {
216+ Write-Warning " Failed to install $ ( $tool.Name ) : $installResult "
217+ }
218+ } catch {
219+ Write-Warning " Error installing $ ( $tool.Name ) : $_ "
220+ }
221+ }
222+
223+ # Additional Windows-specific tools
224+ Write-Info " For additional security tools on Windows, consider:"
225+ Write-Info " • Scoop: scoop install grype"
226+ Write-Info " • Chocolatey: choco install grype"
227+ Write-Info " • Manual downloads from GitHub releases"
228+
229+ # Final instructions
230+ Write-Host @"
231+
232+ 🎉 Installation Complete!
233+ ========================
234+ "@ - ForegroundColor Green
235+
236+ Write-Success " Syncable CLI is now installed and ready to use!"
237+ Write-Info " "
238+ Write-Info " Quick Start:"
239+ Write-Info " sync-ctl analyze . # Analyze current directory"
240+ Write-Info " sync-ctl generate --all . # Generate all IaC files"
241+ Write-Info " sync-ctl security . # Run security analysis"
242+ Write-Info " sync-ctl tools status # Check security tools"
243+ Write-Info " "
244+ Write-Info " For help: sync-ctl --help"
245+ Write-Info " Documentation: https://github.com/syncable-dev/syncable-cli"
246+ Write-Info " "
247+ Write-Warning " Remember to restart your PowerShell session if PATH was modified!"
0 commit comments