-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
260 lines (214 loc) · 8.14 KB
/
install.ps1
File metadata and controls
260 lines (214 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<#
.SYNOPSIS
CIN CLI Installer Script for Windows
.DESCRIPTION
This script downloads and installs CIN CLI on Windows systems.
It automatically detects the system architecture and installs the appropriate version.
.AUTHOR
Ayoub Alarjani (Mawi Man)
.LICENSE
Proprietary - All rights reserved to CIN Framework
.EXAMPLE
iwr -useb https://raw.githubusercontent.com/cin-framework/cin-cli/main/install.ps1 | iex
#>
# Set error action preference
$ErrorActionPreference = 'Stop'
# CIN CLI Configuration
$CinCliVersion = "cin-cli-external-panel"
$BaseUrl = "https://github.com/cin-framework/cin-cli/releases/download/$CinCliVersion"
$BinaryName = "cin-cli.exe"
$InstallDir = "$env:LOCALAPPDATA\CIN-CLI"
$TempDir = "$env:TEMP\cin-cli-install"
# Color functions for output
function Write-ColorOutput {
param(
[string]$Message,
[string]$ForegroundColor = 'White'
)
Write-Host $Message -ForegroundColor $ForegroundColor
}
function Write-Info {
param([string]$Message)
Write-ColorOutput "[INFO] $Message" -ForegroundColor 'Cyan'
}
function Write-Success {
param([string]$Message)
Write-ColorOutput "[SUCCESS] $Message" -ForegroundColor 'Green'
}
function Write-Warning {
param([string]$Message)
Write-ColorOutput "[WARNING] $Message" -ForegroundColor 'Yellow'
}
function Write-Error {
param([string]$Message)
Write-ColorOutput "[ERROR] $Message" -ForegroundColor 'Red'
}
# Function to check if running as administrator
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# Function to detect system information
function Get-SystemInfo {
$os = Get-WmiObject -Class Win32_OperatingSystem
$arch = $env:PROCESSOR_ARCHITECTURE
Write-Info "Detected Windows $($os.Version) ($arch)"
return @{
OS = $os
Architecture = $arch
}
}
# Function to setup installation directory
function Initialize-InstallDirectory {
Write-Info "Setting up installation directory: $InstallDir"
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Write-Success "Created installation directory"
}
# Add to PATH if not already there
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($currentPath -notlike "*$InstallDir*") {
Write-Info "Adding $InstallDir to user PATH"
$newPath = "$InstallDir;$currentPath"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
Write-Success "Added to PATH permanently"
# Also add to current session PATH
$env:PATH += ";$InstallDir"
Write-Success "Added to current session PATH"
}
}
# Function to download CIN CLI
function Get-CinCli {
$downloadUrl = "$BaseUrl/$BinaryName"
$tempFile = Join-Path $TempDir $BinaryName
Write-Info "Downloading CIN CLI from: $downloadUrl"
# Create temporary directory
if (-not (Test-Path $TempDir)) {
New-Item -ItemType Directory -Path $TempDir -Force | Out-Null
}
try {
# Download using Invoke-WebRequest
$progressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempFile -UseBasicParsing
Write-Success "Downloaded CIN CLI successfully"
return $tempFile
}
catch {
Write-Error "Failed to download CIN CLI: $($_.Exception.Message)"
throw
}
}
# Function to install CIN CLI
function Install-CinCli {
param([string]$SourceFile)
$destinationFile = Join-Path $InstallDir $BinaryName
Write-Info "Installing CIN CLI to: $destinationFile"
try {
Copy-Item -Path $SourceFile -Destination $destinationFile -Force
Write-Success "CIN CLI installed successfully"
return $destinationFile
}
catch {
Write-Error "Failed to install CIN CLI: $($_.Exception.Message)"
throw
}
}
# Function to cleanup temporary files
function Remove-TempFiles {
Write-Info "Cleaning up temporary files"
if (Test-Path $TempDir) {
Remove-Item -Path $TempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
# Function to verify installation
function Test-Installation {
param([string]$InstallPath)
Write-Info "Verifying installation..."
if (Test-Path $InstallPath) {
try {
# Test direct path execution
$output = & $InstallPath help 2>$null
Write-Success "CIN CLI is installed and working"
Write-Info "Installation path: $InstallPath"
# Test if cin-cli is now available in PATH
try {
$pathTest = & cin-cli help 2>$null
Write-Success "CIN CLI is available in PATH - you can now use 'cin-cli' command"
}
catch {
Write-Warning "CIN CLI installed but not yet available in PATH for this session"
Write-Info "You can use: & '$InstallPath' [command]"
}
Write-Info "Run 'cin-cli' to see available commands"
return $true
}
catch {
Write-Warning "CIN CLI installed but may not be working properly"
return $false
}
}
else {
Write-Error "Installation verification failed"
return $false
}
}
# Function to display post-installation instructions
function Show-PostInstallInstructions {
Write-ColorOutput "`n======================================" -ForegroundColor 'Magenta'
Write-ColorOutput " Installation Complete!" -ForegroundColor 'Green'
Write-ColorOutput "======================================" -ForegroundColor 'Magenta'
Write-ColorOutput ""
Write-ColorOutput "🎉 CIN CLI is ready to use!" -ForegroundColor 'Green'
Write-ColorOutput ""
Write-ColorOutput "♻️ Restart the command line. ♻️" -ForegroundColor 'Red'
Write-ColorOutput ""
Write-ColorOutput "Available commands:" -ForegroundColor 'Yellow'
Write-ColorOutput "cin-cli - Running the Program"
Write-ColorOutput ""
Write-ColorOutput "Installation path: $InstallDir" -ForegroundColor 'Gray'
Write-ColorOutput "For support, visit: https://www.cin-framework.com" -ForegroundColor 'Blue'
Write-ColorOutput "======================================" -ForegroundColor 'Magenta'
}
# Main installation function
function Install-CinCliMain {
try {
Write-ColorOutput "`n======================================" -ForegroundColor 'Magenta'
Write-ColorOutput " CIN CLI Installer for Windows" -ForegroundColor 'Cyan'
Write-ColorOutput " Author: Mawi Man" -ForegroundColor 'White'
Write-ColorOutput " Framework: CIN Framework" -ForegroundColor 'White'
Write-ColorOutput "======================================" -ForegroundColor 'Magenta'
Write-ColorOutput ""
# Check system information
$systemInfo = Get-SystemInfo
# Check if running as administrator
if (Test-Administrator) {
Write-Warning "Running as Administrator. Installing system-wide."
}
# Setup installation directory
Initialize-InstallDirectory
# Download CIN CLI
$downloadedFile = Get-CinCli
# Install CIN CLI
$installedFile = Install-CinCli -SourceFile $downloadedFile
# Verify installation
$installSuccess = Test-Installation -InstallPath $installedFile
if ($installSuccess) {
Show-PostInstallInstructions
}
else {
Write-Error "Installation completed but verification failed"
}
}
catch {
Write-Error "Installation failed: $($_.Exception.Message)"
Write-Info "Please try running the installer as Administrator or check your internet connection"
exit 1
}
finally {
# Always cleanup
Remove-TempFiles
}
}
# Execute main installation
Install-CinCliMain