Skip to content

Commit b55fb36

Browse files
committed
[SP-3605] fix: update installation scripts
1 parent eab3438 commit b55fb36

File tree

4 files changed

+111
-14
lines changed

4 files changed

+111
-14
lines changed

INSTALLATION.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ If you prefer manual installation:
160160

161161
**Installation Options:**
162162

163-
**Option 1: Portable Use**
163+
### Option 1: Portable Use
164+
164165
- Run directly from Downloads or any location
165166
- No installation required
166167
- Ideal for USB drives or temporary usage
167168

168-
**Option 2: Install to Program Files (Recommended)**
169+
### Option 2: Install to Program Files (Recommended)
170+
169171
```powershell
170172
# In PowerShell (Run as Administrator)
171173
New-Item -Path "C:\Program Files\SCANOSS" -ItemType Directory -Force
@@ -311,7 +313,7 @@ $env:Path -split ';' | Select-String SCANOSS
311313
**Issue:** Application won't start or crashes immediately
312314

313315
**Solution:** SCANOSS Code Compare requires WebView2 runtime. It's typically pre-installed on Windows 11, but Windows 10 users may need to install it:
314-
- Download from: https://developer.microsoft.com/en-us/microsoft-edge/webview2/
316+
- Download from: [Microsoft WebView2 Runtime](https://developer.microsoft.com/en-us/microsoft-edge/webview2/)
315317
- Or the app will prompt to download it automatically on first launch
316318

317319
### Linux

scripts/install-macos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ else
2424
curl -fsSL "https://raw.githubusercontent.com/$REPO/main/scripts/lib/github-api.sh" -o "$TEMP_LIB_DIR/github-api.sh"
2525
source "$TEMP_LIB_DIR/common.sh"
2626
source "$TEMP_LIB_DIR/github-api.sh"
27-
trap "rm -rf '$TEMP_LIB_DIR'" EXIT
27+
trap 'rm -rf "$TEMP_LIB_DIR"' EXIT
2828
fi
2929

3030
# Check if Homebrew is installed

scripts/install-windows.ps1

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# SCANOSS Code Compare - Windows Installer
22
# This script installs SCANOSS Code Compare on Windows
3+
#
4+
# Parameters:
5+
# -InstallPath : Installation directory (default: C:\Program Files\SCANOSS)
6+
# -NoPath : Skip adding to system PATH
7+
# -NoShortcuts : Skip creating Start Menu shortcuts
8+
# -NoVerify : Skip SHA256 checksum verification (not recommended)
9+
# -Version : Specific version to install (default: latest)
10+
#
11+
# Examples:
12+
# # Standard installation
13+
# .\install-windows.ps1
14+
#
15+
# # Install without PATH modification
16+
# .\install-windows.ps1 -NoPath
17+
#
18+
# # Install specific version
19+
# .\install-windows.ps1 -Version "0.9.0"
20+
#
21+
# # Skip checksum verification (not recommended)
22+
# .\install-windows.ps1 -NoVerify
323

424
#Requires -Version 5.1
525

@@ -8,6 +28,7 @@ param(
828
[string]$InstallPath = "$env:ProgramFiles\SCANOSS",
929
[switch]$NoPath,
1030
[switch]$NoShortcuts,
31+
[switch]$NoVerify,
1132
[string]$Version
1233
)
1334

@@ -135,6 +156,41 @@ function Get-AssetUrl {
135156
}
136157
}
137158

159+
# Get checksum for a specific asset from SHA256SUMS file
160+
function Get-AssetChecksum {
161+
param(
162+
[string]$Version,
163+
[string]$AssetName
164+
)
165+
166+
Write-Debug-Info "Fetching checksum for: $AssetName"
167+
168+
$checksumsUrl = "https://github.com/$Script:Repo/releases/download/v$Version/SHA256SUMS"
169+
170+
try {
171+
$checksums = (Invoke-WebRequest -Uri $checksumsUrl -UseBasicParsing -ErrorAction SilentlyContinue).Content
172+
173+
if ($checksums) {
174+
# Parse the SHA256SUMS file (format: "hash filename")
175+
$lines = $checksums -split "`n"
176+
foreach ($line in $lines) {
177+
if ($line -match "^\s*([a-fA-F0-9]+)\s+.*$AssetName") {
178+
$checksum = $matches[1]
179+
Write-Debug-Info "Found checksum: $checksum"
180+
return $checksum
181+
}
182+
}
183+
}
184+
185+
Write-Warn "No checksum file found for this release"
186+
return $null
187+
}
188+
catch {
189+
Write-Debug-Info "Failed to fetch checksums: $_"
190+
return $null
191+
}
192+
}
193+
138194
# Check if WebView2 is installed
139195
function Test-WebView2 {
140196
$webView2Key = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
@@ -264,10 +320,33 @@ function Install-ScanossCodeCompare {
264320
# Download
265321
$downloadUrl = Get-AssetUrl -Version $Version
266322
$zipPath = "$tempDir\$Script:AppName.zip"
323+
$assetName = "$Script:AppName-win.zip"
267324

268325
Get-FileWithProgress -Url $downloadUrl -OutputPath $zipPath
269326

327+
# Verify checksum (unless -NoVerify is set)
328+
if (-not $NoVerify) {
329+
Write-Host ""
330+
$expectedChecksum = Get-AssetChecksum -Version $Version -AssetName $assetName
331+
332+
if ($expectedChecksum) {
333+
if (-not (Test-Checksum -FilePath $zipPath -ExpectedHash $expectedChecksum)) {
334+
# Checksum failed - clean up and abort
335+
Remove-Item -Path $zipPath -Force -ErrorAction SilentlyContinue
336+
throw "Checksum verification failed! The downloaded file may be corrupted or tampered with."
337+
}
338+
}
339+
else {
340+
Write-Warn "No checksum available for verification"
341+
Write-Warn "Installation will proceed without checksum verification"
342+
}
343+
}
344+
else {
345+
Write-Warn "Checksum verification skipped (--NoVerify flag set)"
346+
}
347+
270348
# Extract
349+
Write-Host ""
271350
Write-Info "Extracting..."
272351
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
273352

scripts/lib/github-api.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,18 @@ get_asset_checksum() {
6666
local checksums_url="https://github.com/$GITHUB_REPO/releases/download/v$version/SHA256SUMS"
6767
local checksum=""
6868

69+
# Temporarily disable errexit to handle missing checksums gracefully
70+
set +e
71+
6972
if command_exists curl; then
70-
checksum=$(curl -fsSL "$checksums_url" 2>/dev/null | grep "$asset_name" | awk '{print $1}')
73+
checksum=$(curl -sSL "$checksums_url" 2>/dev/null | grep "$asset_name" | awk '{print $1}')
7174
elif command_exists wget; then
7275
checksum=$(wget -qO- "$checksums_url" 2>/dev/null | grep "$asset_name" | awk '{print $1}')
7376
fi
7477

78+
# Restore errexit
79+
set -e
80+
7581
if [ -z "$checksum" ]; then
7682
log_warn "No checksum file found for this release"
7783
log_warn "Installation will proceed without checksum verification"
@@ -86,18 +92,28 @@ get_asset_checksum() {
8692
version_exists() {
8793
local version="$1"
8894
local release_url="$GITHUB_API_URL/releases/tags/v$version"
95+
local http_code=""
96+
97+
# Temporarily disable errexit to handle HTTP errors gracefully
98+
set +e
8999

90100
if command_exists curl; then
91-
if curl -fsSL -o /dev/null -w "%{http_code}" "$release_url" | grep -q "200"; then
92-
return 0
93-
fi
101+
# Get HTTP status code without failing on 4xx/5xx
102+
http_code=$(curl -sSL -o /dev/null -w "%{http_code}" "$release_url" 2>/dev/null)
94103
elif command_exists wget; then
95-
if wget -q --spider "$release_url" 2>&1 | grep -q "200"; then
96-
return 0
97-
fi
104+
# Get HTTP status code from wget
105+
http_code=$(wget --spider -S "$release_url" 2>&1 | grep "HTTP/" | tail -n 1 | awk '{print $2}')
98106
fi
99107

100-
return 1
108+
# Restore errexit
109+
set -e
110+
111+
# Check if we got a 200 response
112+
if [ "$http_code" = "200" ]; then
113+
return 0
114+
else
115+
return 1
116+
fi
101117
}
102118

103119
# List available versions
@@ -158,8 +174,8 @@ download_and_verify_asset() {
158174
download_file "$download_url" "$output_path"
159175

160176
# Try to verify checksum
161-
local expected_checksum=$(get_asset_checksum "$version" "$asset_name")
162-
if [ -n "$expected_checksum" ]; then
177+
local expected_checksum=""
178+
if expected_checksum=$(get_asset_checksum "$version" "$asset_name" 2>/dev/null); then
163179
if ! verify_checksum "$output_path" "$expected_checksum"; then
164180
abort "Checksum verification failed! The downloaded file may be corrupted or tampered with."
165181
fi

0 commit comments

Comments
 (0)