|
<# |
|
.SYNOPSIS |
|
Installs aria2 on Windows, sets up default configuration, and adds to PATH. |
|
|
|
.DESCRIPTION |
|
- Creates the folder C:\Tools\aria2. |
|
- Downloads aria2 64-bit (version 1.36.0). |
|
- Extracts all files into C:\Tools\aria2. |
|
- Creates aria2.conf with default settings (resume, 10 connections, etc.). |
|
- Adds C:\Tools\aria2 to the user PATH. |
|
#> |
|
|
|
[CmdletBinding()] |
|
param() |
|
|
|
Write-Host "`n=== Starting aria2 installation... ===`n" |
|
|
|
# 1) Create the target folder if it doesn't exist |
|
$destFolder = "C:\Tools\aria2" |
|
if (!(Test-Path $destFolder)) { |
|
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null |
|
Write-Host "Created folder: $destFolder" |
|
} else { |
|
Write-Host "Folder already exists: $destFolder" |
|
} |
|
|
|
# 2) Download aria2 release to %TEMP% |
|
$Aria2Url = "https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0-win-64bit-build1.zip" |
|
$ZipPath = "$env:TEMP\aria2_temp.zip" |
|
Write-Host "`nDownloading aria2 from $Aria2Url..." |
|
Invoke-WebRequest -Uri $Aria2Url -OutFile $ZipPath |
|
Write-Host "Download complete: $ZipPath" |
|
|
|
# 3) Unzip to destination folder |
|
Write-Host "`nExtracting zip file..." |
|
Expand-Archive -Path $ZipPath -DestinationPath $destFolder -Force |
|
Write-Host "Extraction complete." |
|
|
|
# 4) Move the extracted files from subfolder to C:\Tools\aria2 |
|
# Typically, they are in: C:\Tools\aria2\aria2-1.36.0-win-64bit-build1 |
|
$extractedFolder = Join-Path $destFolder "aria2-1.36.0-win-64bit-build1" |
|
if (Test-Path $extractedFolder) { |
|
Move-Item -Path (Join-Path $extractedFolder "*") -Destination $destFolder -Force |
|
Remove-Item -Path $extractedFolder -Recurse -Force |
|
Write-Host "`nMoved extracted files to $destFolder" |
|
} else { |
|
Write-Host "`nWARNING: $extractedFolder not found. Check the version/paths." |
|
} |
|
|
|
# 5) Create aria2.conf with recommended settings |
|
$configFile = Join-Path $destFolder "aria2.conf" |
|
$configContent = @" |
|
# Resume downloads when possible |
|
continue=true |
|
|
|
# Parallel connections |
|
max-connection-per-server=10 |
|
split=10 |
|
min-split-size=20M |
|
|
|
# Disable pre-allocation on Windows |
|
file-allocation=none |
|
"@ |
|
Write-Host "`nCreating aria2.conf: $configFile" |
|
$configContent | Out-File $configFile -Encoding UTF8 |
|
Write-Host "Configuration file created." |
|
|
|
# 6) Add C:\Tools\aria2 to the user PATH |
|
# Change to "Machine" for all users (run as admin if so). |
|
$envScope = "User" |
|
$oldPath = [System.Environment]::GetEnvironmentVariable("Path", $envScope) |
|
if ($oldPath -notlike "*$destFolder*") { |
|
$newPath = $oldPath + ";$destFolder" |
|
[System.Environment]::SetEnvironmentVariable("Path", $newPath, $envScope) |
|
Write-Host "`nAdded '$destFolder' to the PATH ($envScope scope)." |
|
} else { |
|
Write-Host "`n'$destFolder' is already in PATH." |
|
} |
|
|
|
Write-Host "`n=== aria2 installation complete! ===" |
|
Write-Host "Open a NEW Command Prompt or PowerShell and type:" |
|
Write-Host " aria2c https://example.com/file.iso" |
|
Write-Host "The file will be downloaded into the CURRENT directory." |