Skip to content

Commit 9e06aa9

Browse files
committed
Replace source archive download with git clone
- instead of checking version and downloading zip, use git clone (it will also resolve false-positive virus notification)
1 parent d5f28ac commit 9e06aa9

2 files changed

Lines changed: 21 additions & 91 deletions

File tree

‎install.ps1‎

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
$ErrorActionPreference = "Stop"
22
$targetScheme = if ($args.Count -gt 0) { $args[0] } else { $null }
33

4+
if (!(Get-Command git -ErrorAction SilentlyContinue)) {
5+
Write-Host "Error: git is required but not installed." -ForegroundColor Red
6+
Pause
7+
exit 1
8+
}
9+
410
$nodeIsGood = $false
511
if (Get-Command node -ErrorAction SilentlyContinue) {
612
$nodeVersion = (node -v) -replace '^v',''
@@ -159,63 +165,25 @@ Write-Host ""
159165

160166
try {
161167

162-
$page = 1
163-
$latestTag = $null
164-
165-
while ($page -le 10 -and !$latestTag) {
166-
$tagsUrl = "https://api.github.com/repos/robertpiosik/CodeWebChat/tags?page=$page"
167-
try {
168-
$tags = Invoke-RestMethod -Uri $tagsUrl
169-
if (!$tags -or $tags.Count -eq 0) { break }
170-
$latestTag = $tags | Where-Object { $_.name -match '-vscode$' } | Select-Object -First 1
171-
} catch {
172-
Write-Host "Error: Failed to fetch tags." -ForegroundColor Red
173-
Pause
174-
exit 1
175-
}
176-
$page++
177-
}
178-
179-
if (!$latestTag) {
180-
Write-Host "Error: Could not find latest vscode tag." -ForegroundColor Red
181-
Pause
182-
exit 1
183-
}
184-
185-
$zipUrl = $latestTag.zipball_url
186-
187168
$tmpDir = Join-Path $env:TEMP ("CWC_Install_" + [Guid]::NewGuid().ToString().Substring(0,8))
188169
New-Item -ItemType Directory -Path $tmpDir | Out-Null
189170

190-
$zipPath = Join-Path $tmpDir "source.zip"
191-
$spinner = Start-Spinner "Downloading source code..."
192-
try {
193-
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing
194-
Stop-Spinner $spinner $true
195-
} catch {
196-
Stop-Spinner $spinner $false
197-
Write-Host "Error: Download failed." -ForegroundColor Red
198-
Pause
199-
exit 1
200-
}
201-
202-
try {
203-
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
204-
} catch {
205-
Write-Host "Error: Extraction failed." -ForegroundColor Red
206-
Pause
207-
exit 1
208-
}
171+
$extractedDir = Join-Path $tmpDir "source"
209172

210-
$extractedDir = Get-ChildItem -Path $tmpDir -Directory | Select-Object -First 1
173+
$spinner = Start-Spinner "Cloning repository..."
174+
$ErrorActionPreference = "Continue"
175+
git clone --quiet https://github.com/robertpiosik/CodeWebChat.git $extractedDir *>$null
176+
$cmdSuccess = $?
177+
$ErrorActionPreference = "Stop"
178+
Stop-Spinner $spinner $cmdSuccess
211179

212-
if (!$extractedDir) {
213-
Write-Host "Error: Extraction failed." -ForegroundColor Red
180+
if (!$cmdSuccess) {
181+
Write-Host "Error: Cloning repository failed." -ForegroundColor Red
214182
Pause
215183
exit 1
216184
}
217185

218-
Push-Location $extractedDir.FullName
186+
Push-Location $extractedDir
219187

220188
$spinner = Start-Spinner "Installing dependencies..."
221189
$ErrorActionPreference = "Continue"

‎install.sh‎

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
if ! command -v curl &> /dev/null; then
5-
echo "Error: curl is required but not installed."
6-
exit 1
7-
fi
8-
9-
if ! command -v unzip &> /dev/null; then
10-
echo "Error: unzip is required but not installed."
4+
if ! command -v git &> /dev/null; then
5+
echo "Error: git is required but not installed."
116
exit 1
127
fi
138

@@ -160,50 +155,17 @@ stop_spinner() {
160155
}
161156

162157
echo ""
163-
PAGE=1
164-
ZIP_URL=""
165-
166-
while [ $PAGE -le 10 ]; do
167-
TAGS_JSON=$(curl -s "https://api.github.com/repos/robertpiosik/CodeWebChat/tags?per_page=100&page=$PAGE")
168-
169-
if [[ "$TAGS_JSON" == *"\"message\":"* ]] || [[ "$TAGS_JSON" == "[]" ]] || [[ -z "$TAGS_JSON" ]]; then
170-
break
171-
fi
172-
173-
TAG_NAME=$(echo "$TAGS_JSON" | grep -o '"name": *"[^"]*-vscode"' | head -n 1 | sed -e 's/"name": *"//' -e 's/"$//')
174-
ZIP_URL=$(echo "$TAGS_JSON" | grep -o '"zipball_url": *"[^"]*-vscode"' | head -n 1 | sed -e 's/"zipball_url": *"//' -e 's/"$//')
175-
176-
if [ -n "$ZIP_URL" ]; then
177-
break
178-
fi
179-
180-
PAGE=$((PAGE + 1))
181-
done
182158

183-
if [ -z "$ZIP_URL" ]; then
184-
echo "Error: Could not find latest vscode tag."
185-
exit 1
186-
fi
187-
188-
printf " Downloading source code..."
159+
printf " Cloning repository..."
189160
start_spinner &
190161
SPINNER_PID=$!
191-
if ! curl -sL "$ZIP_URL" -o "$TMP_DIR/source.zip"; then
162+
if ! git clone --quiet https://github.com/robertpiosik/CodeWebChat.git "$TMP_DIR/source" > /dev/null 2>&1; then
192163
stop_spinner $SPINNER_PID 1
193164
exit 1
194165
fi
195166
stop_spinner $SPINNER_PID 0
196167

197-
if ! unzip -q "$TMP_DIR/source.zip" -d "$TMP_DIR"; then
198-
exit 1
199-
fi
200-
201-
EXTRACTED_DIR=$(find "$TMP_DIR" -mindepth 1 -maxdepth 1 -type d | head -n 1)
202-
203-
if [ -z "$EXTRACTED_DIR" ]; then
204-
echo "Error: Extraction failed."
205-
exit 1
206-
fi
168+
EXTRACTED_DIR="$TMP_DIR/source"
207169

208170
cd "$EXTRACTED_DIR"
209171

0 commit comments

Comments
 (0)