Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ jobs:
- name: Test Scoop Installer
shell: powershell
run: ./test/bin/test.ps1
- name: Test Scoop Install command
shell: powershell
run: |
./install.ps1 -RunAsAdmin
echo "$Env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Test scoop command availability
shell: powershell
run: scoop help
test_pwsh:
name: PowerShell
runs-on: windows-latest
Expand All @@ -37,3 +45,11 @@ jobs:
- name: Test Scoop Installer
shell: pwsh
run: ./test/bin/test.ps1
- name: Test Scoop Install command
shell: pwsh
run: |
./install.ps1 -RunAsAdmin
echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Test scoop command availability
shell: pwsh
run: scoop help
104 changes: 68 additions & 36 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
.PARAMETER Proxy
Specifies proxy to use during the installation.
.PARAMETER ProxyCredential
Specifies credential for the given prxoy.
Specifies credential for the given proxy.
.PARAMETER ProxyUseDefaultCredentials
Use the credentials of the current user for the proxy server that is specified by the -Proxy parameter.
.PARAMETER RunAsAdmin
Expand Down Expand Up @@ -518,6 +518,14 @@ function Add-DefaultConfig {
Add-Config -Name 'last_update' -Value ([System.DateTime]::Now.ToString('o')) | Out-Null
}

function Test-CommandAvailable {
param (
[Parameter(Mandatory = $True, Position = 0)]
[String] $Command
)
return [Boolean](Get-Command $Command -ErrorAction Ignore)
}

function Install-Scoop {
Write-InstallInfo "Initializing..."
# Validate install parameters
Expand All @@ -527,43 +535,64 @@ function Install-Scoop {
# Enable TLS 1.2
Optimize-SecurityProtocol

# Download scoop zip from GitHub
Write-InstallInfo "Downloading..."
# Download scoop from GitHub
Write-InstallInfo "Downloading ..."
$downloader = Get-Downloader
# 1. download scoop
$scoopZipfile = "$SCOOP_APP_DIR\scoop.zip"
if (!(Test-Path $SCOOP_APP_DIR)) {
New-Item -Type Directory $SCOOP_APP_DIR | Out-Null
}
Write-Verbose "Downloading $SCOOP_PACKAGE_REPO to $scoopZipfile"
$downloader.downloadFile($SCOOP_PACKAGE_REPO, $scoopZipfile)
# 2. download scoop main bucket
$scoopMainZipfile = "$SCOOP_MAIN_BUCKET_DIR\scoop-main.zip"
if (!(Test-Path $SCOOP_MAIN_BUCKET_DIR)) {
New-Item -Type Directory $SCOOP_MAIN_BUCKET_DIR | Out-Null
}
Write-Verbose "Downloading $SCOOP_MAIN_BUCKET_REPO to $scoopMainZipfile"
$downloader.downloadFile($SCOOP_MAIN_BUCKET_REPO, $scoopMainZipfile)

# Extract files from downloaded zip
Write-InstallInfo "Extracting..."
# 1. extract scoop
$scoopUnzipTempDir = "$SCOOP_APP_DIR\_tmp"
Write-Verbose "Extracting $scoopZipfile to $scoopUnzipTempDir"
Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
Copy-Item "$scoopUnzipTempDir\scoop-*\*" $SCOOP_APP_DIR -Recurse -Force
# 2. extract scoop main bucket
$scoopMainUnzipTempDir = "$SCOOP_MAIN_BUCKET_DIR\_tmp"
Write-Verbose "Extracting $scoopMainZipfile to $scoopMainUnzipTempDir"
Expand-ZipArchive $scoopMainZipfile $scoopMainUnzipTempDir
Copy-Item "$scoopMainUnzipTempDir\Main-*\*" $SCOOP_MAIN_BUCKET_DIR -Recurse -Force

# Cleanup
Remove-Item $scoopUnzipTempDir -Recurse -Force
Remove-Item $scoopZipfile
Remove-Item $scoopMainUnzipTempDir -Recurse -Force
Remove-Item $scoopMainZipfile

if (Test-CommandAvailable('git')) {
$old_https = $env:HTTPS_PROXY
$old_http = $env:HTTP_PROXY
try {
if ($downloader.Proxy) {
#define env vars for git when behind a proxy
$Env:HTTP_PROXY = $downloader.Proxy.Address
$Env:HTTPS_PROXY = $downloader.Proxy.Address
}
Write-Verbose "Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR"
git clone -q $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
Write-Verbose "Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR"
git clone -q $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
} catch {
Get-Error $_
} finally {
$env:HTTPS_PROXY = $old_https
$env:HTTP_PROXY = $old_http
}
} else {
# 1. download scoop
$scoopZipfile = "$SCOOP_APP_DIR\scoop.zip"
if (!(Test-Path $SCOOP_APP_DIR)) {
New-Item -Type Directory $SCOOP_APP_DIR | Out-Null
}
Write-Verbose "Downloading $SCOOP_PACKAGE_REPO to $scoopZipfile"
$downloader.downloadFile($SCOOP_PACKAGE_REPO, $scoopZipfile)
# 2. download scoop main bucket
$scoopMainZipfile = "$SCOOP_MAIN_BUCKET_DIR\scoop-main.zip"
if (!(Test-Path $SCOOP_MAIN_BUCKET_DIR)) {
New-Item -Type Directory $SCOOP_MAIN_BUCKET_DIR | Out-Null
}
Write-Verbose "Downloading $SCOOP_MAIN_BUCKET_REPO to $scoopMainZipfile"
$downloader.downloadFile($SCOOP_MAIN_BUCKET_REPO, $scoopMainZipfile)

# Extract files from downloaded zip
Write-InstallInfo "Extracting..."
# 1. extract scoop
$scoopUnzipTempDir = "$SCOOP_APP_DIR\_tmp"
Write-Verbose "Extracting $scoopZipfile to $scoopUnzipTempDir"
Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
Copy-Item "$scoopUnzipTempDir\scoop-*\*" $SCOOP_APP_DIR -Recurse -Force
# 2. extract scoop main bucket
$scoopMainUnzipTempDir = "$SCOOP_MAIN_BUCKET_DIR\_tmp"
Write-Verbose "Extracting $scoopMainZipfile to $scoopMainUnzipTempDir"
Expand-ZipArchive $scoopMainZipfile $scoopMainUnzipTempDir
Copy-Item "$scoopMainUnzipTempDir\Main-*\*" $SCOOP_MAIN_BUCKET_DIR -Recurse -Force

# Cleanup
Remove-Item $scoopUnzipTempDir -Recurse -Force
Remove-Item $scoopZipfile
Remove-Item $scoopMainUnzipTempDir -Recurse -Force
Remove-Item $scoopMainZipfile
}
# Create the scoop shim
Import-ScoopShim
# Finially ensure scoop shims is in the PATH
Expand Down Expand Up @@ -616,6 +645,9 @@ $SCOOP_CONFIG_FILE = "$SCOOP_CONFIG_HOME\scoop\config.json"
$SCOOP_PACKAGE_REPO = "https://github.com/ScoopInstaller/Scoop/archive/master.zip"
$SCOOP_MAIN_BUCKET_REPO = "https://github.com/ScoopInstaller/Main/archive/master.zip"

$SCOOP_PACKAGE_GIT_REPO = "https://github.com/ScoopInstaller/Scoop.git"
$SCOOP_MAIN_BUCKET_GIT_REPO = "https://github.com/ScoopInstaller/Main.git"

# Quit if anything goes wrong
$oldErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
Expand Down
29 changes: 29 additions & 0 deletions test/install.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BeforeAll {
# Load SUT
$sut = (Split-Path -Leaf $PSCommandPath).Replace('.Tests.ps1', '.ps1')
. ".\$sut"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this will actually trigger an installation of Scoop, it tries to expose functions for unit tests below but it imports the whole install script. I noticed it when implementing #76 and the ci kept failing. ;p

}

Describe 'Get-Downloader' -Tag 'Proxy' {
Context 'No proxy given via script parameter' {
It 'Returns WebClient without proxy' {
$NoProxy = $true
Test-ValidateParameter
(Get-Downloader).Proxy | Should -Be $null
}
It 'Returns WebClient without proxy although proxy is given' {
$NoProxy = $true
$Proxy = New-Object System.Uri('http://donotcare')
Test-ValidateParameter
(Get-Downloader).Proxy | Should -Be $null
}
}
Context 'Proxy given via script parameter' {
It 'Returns WebClient with proxy' {
$ProxyString = 'http://some.proxy.with.port:8080'
$Proxy = New-Object System.Uri($ProxyString)
Test-ValidateParameter
(Get-Downloader).Proxy.Address | Should -Be "$ProxyString/"
}
}
}