Skip to content

Commit 6eb0bfe

Browse files
committed
feat: support other sources of scoop and main repo
1 parent ff4eedd commit 6eb0bfe

File tree

3 files changed

+190
-42
lines changed

3 files changed

+190
-42
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
test_powershell:
10-
name: WindowsPowerShell
10+
name: Test (WindowsPowerShell)
1111
runs-on: windows-latest
1212
steps:
1313
- name: Checkout
@@ -25,13 +25,14 @@ jobs:
2525
- name: Test Scoop Install command
2626
shell: powershell
2727
run: |
28+
$VerbosePreference = "Continue"
2829
./install.ps1 -RunAsAdmin
2930
echo "$Env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
3031
- name: Test scoop command availability
3132
shell: powershell
3233
run: scoop help
3334
test_pwsh_cloning:
34-
name: PowerShell (with cloning)
35+
name: Test (PowerShell, with cloning)
3536
runs-on: windows-latest
3637
steps:
3738
- name: Checkout
@@ -49,13 +50,14 @@ jobs:
4950
- name: Test Scoop Install command
5051
shell: pwsh
5152
run: |
53+
$VerbosePreference = "Continue"
5254
./install.ps1 -RunAsAdmin
5355
echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
5456
- name: Test scoop command availability
5557
shell: pwsh
5658
run: scoop help
57-
test_pwsh_download:
58-
name: PowerShell (with downloading)
59+
install_pwsh_download:
60+
name: Installation (using download due to failing git clone)
5961
runs-on: windows-latest
6062
steps:
6163
- name: Checkout
@@ -66,8 +68,26 @@ jobs:
6668
shell: pwsh
6769
run: |
6870
git config --global protocol.https.allow never
71+
$VerbosePreference = "Continue"
6972
./install.ps1 -RunAsAdmin
7073
echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
7174
- name: Test scoop command availability
7275
shell: pwsh
7376
run: scoop help
77+
install_pwsh_args:
78+
name: Installation (using download of given source)
79+
runs-on: windows-latest
80+
steps:
81+
- name: Checkout
82+
uses: actions/checkout@main
83+
with:
84+
fetch-depth: 2
85+
- name: Test Scoop Install command
86+
shell: pwsh
87+
run: |
88+
$VerbosePreference = "Continue"
89+
./install.ps1 -ScoopAppRepoZip "https://github.com/ScoopInstaller/Scoop/archive/master.zip" -RunAsAdmin
90+
echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
91+
- name: Test scoop command availability
92+
shell: pwsh
93+
run: scoop help

install.ps1

Lines changed: 95 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@
4040
.PARAMETER ScoopCacheDir
4141
Specifies cache directory.
4242
If not specified, caches will be downloaded to '$ScoopDir\cache'.
43+
.PARAMETER ScoopAppRepoZip
44+
Specifies the source of Scoop app as zip file.
45+
If not specified, the default app repository zip will be used.
46+
.PARAMETER ScoopAppRepoGit
47+
Specifies the source of Scoop app as git repository.
48+
If not specified, the default app git repository will be used.
49+
.PARAMETER ScoopMainBucketRepoZip
50+
Specifies the source of Scoop main bucket as zip file.
51+
If not specified, but a Scoop app source is specified, no main bucket will be installed.
52+
Otherwise, the default main bucket repository zip will be used.
53+
.PARAMETER ScoopMainBucketRepoGit
54+
Specifies the source of Scoop main bucket as git repository.
55+
If not specified, but a Scoop app source is specified, no main bucket will be installed.
56+
Otherwise, the default main bucket git repository will be used.
4357
.PARAMETER NoProxy
4458
Bypass system proxy during the installation.
4559
.PARAMETER Proxy
@@ -59,6 +73,10 @@ param(
5973
[String] $ScoopDir,
6074
[String] $ScoopGlobalDir,
6175
[String] $ScoopCacheDir,
76+
[String] $ScoopAppRepoZip,
77+
[String] $ScoopAppRepoGit,
78+
[String] $ScoopMainBucketRepoZip,
79+
[String] $ScoopMainBucketRepoGit,
6280
[Switch] $NoProxy,
6381
[Uri] $Proxy,
6482
[System.Management.Automation.PSCredential] $ProxyCredential,
@@ -568,6 +586,35 @@ function Test-CommandAvailable {
568586
return [Boolean](Get-Command $Command -ErrorAction SilentlyContinue)
569587
}
570588

589+
function Get-Scoop-Source {
590+
param (
591+
[Parameter(Mandatory = $False, Position = 0)]
592+
[String] $ScoopAppRepoZip = "",
593+
[Parameter(Mandatory = $False, Position = 1)]
594+
[String] $ScoopAppRepoGit = "",
595+
[Parameter(Mandatory = $False, Position = 2)]
596+
[String] $ScoopMainBucketRepoZip = "",
597+
[Parameter(Mandatory = $False, Position = 3)]
598+
[String] $ScoopMainBucketRepoGit = ""
599+
)
600+
$ScoopSource = @{}
601+
if ($ScoopAppRepoZip -or $Env:SCOOP_APP_REPO_ZIP -or
602+
$ScoopAppRepoGit -or $Env:SCOOP_APP_REPO_GIT) {
603+
# In case of any app repo source is provided, we expect all repo source parameters are provided.
604+
# Otherwise we skip the main bucket source.
605+
$ScoopSource.AppRepoZip = $ScoopAppRepoZip, $Env:SCOOP_APP_REPO_ZIP | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
606+
$ScoopSource.AppRepoGit = $ScoopAppRepoGit, $Env:SCOOP_APP_REPO_GIT | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
607+
$ScoopSource.MainBucketRepoZip = $ScoopMainBucketRepoZip, $Env:SCOOP_MAIN_BUCKET_REPO_ZIP | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
608+
$ScoopSource.MainBucketRepoGit = $ScoopMainBucketRepoGit, $Env:SCOOP_MAIN_BUCKET_REPO_GIT | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
609+
} else {
610+
$ScoopSource.AppRepoZip = "https://github.com/ScoopInstaller/Scoop/archive/master.zip"
611+
$ScoopSource.AppRepoGit = "https://github.com/ScoopInstaller/Scoop.git"
612+
$ScoopSource.MainBucketRepoZip = $ScoopMainBucketRepoZip, $Env:SCOOP_MAIN_BUCKET_REPO_ZIP, "https://github.com/ScoopInstaller/Main/archive/master.zip" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
613+
$ScoopSource.MainBucketRepoGit = $ScoopMainBucketRepoGit, $Env:SCOOP_MAIN_BUCKET_REPO_GIT, "https://github.com/ScoopInstaller/Main.git" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
614+
}
615+
return $ScoopSource
616+
}
617+
571618
function Install-Scoop {
572619
Write-InstallInfo 'Initializing...'
573620
# Validate install parameters
@@ -578,11 +625,18 @@ function Install-Scoop {
578625
Optimize-SecurityProtocol
579626

580627
# Download scoop from GitHub
581-
Write-InstallInfo 'Downloading...'
628+
Write-InstallInfo 'Installing ...'
582629
$downloader = Get-Downloader
583-
[bool]$downloadZipsRequired = $True
630+
[bool]$downloadAppZipRequired = $True
631+
[bool]$downloadMainBucketZipRequired = $True
584632

585-
if (Test-CommandAvailable('git')) {
633+
# Create buckets dir as it might not be created in case no
634+
# initial bucket is provided
635+
if (!(Test-Path $SCOOP_BUCKETS_DIR)) {
636+
New-Item -Type Directory $SCOOP_BUCKETS_DIR | Out-Null
637+
}
638+
639+
if (($ScoopSources.AppRepoGit -or $ScoopSources.MainBucketRepoGit) -and (Test-CommandAvailable('git'))) {
586640
$old_https = $env:HTTPS_PROXY
587641
$old_http = $env:HTTP_PROXY
588642
try {
@@ -591,17 +645,22 @@ function Install-Scoop {
591645
$Env:HTTP_PROXY = $downloader.Proxy.Address
592646
$Env:HTTPS_PROXY = $downloader.Proxy.Address
593647
}
594-
Write-Verbose "Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR"
595-
git clone -q $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
596-
if (-Not $?) {
597-
throw 'Cloning failed. Falling back to downloading zip files.'
648+
if ($ScoopSources.AppRepoGit) {
649+
Write-Verbose ("Cloning {0} to $SCOOP_APP_DIR" -f $ScoopSources.AppRepoGit)
650+
git clone -q $ScoopSources.AppRepoGit $SCOOP_APP_DIR
651+
if (-Not $?) {
652+
throw 'Cloning failed. Falling back to downloading zip files.'
653+
}
654+
$downloadAppZipRequired = $False
598655
}
599-
Write-Verbose "Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR"
600-
git clone -q $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
601-
if (-Not $?) {
602-
throw 'Cloning failed. Falling back to downloading zip files.'
656+
if ($ScoopSources.MainBucketRepoGit) {
657+
Write-Verbose ("Cloning {0} to $SCOOP_MAIN_BUCKET_DIR" -f $ScoopSources.MainBucketRepoGit)
658+
git clone -q $ScoopSources.MainBucketRepoGit $SCOOP_MAIN_BUCKET_DIR
659+
if (-Not $?) {
660+
throw 'Cloning failed. Falling back to downloading zip files.'
661+
}
662+
$downloadMainBucketZipRequired = $False
603663
}
604-
$downloadZipsRequired = $False
605664
} catch {
606665
Write-Warning "$($_.Exception.Message)"
607666
$Global:LastExitCode = 0
@@ -611,41 +670,42 @@ function Install-Scoop {
611670
}
612671
}
613672

614-
if ($downloadZipsRequired) {
615-
# 1. download scoop
673+
if ($ScoopSources.AppRepoZip -and $downloadAppZipRequired) {
674+
# 1. download scoop app
616675
$scoopZipfile = "$SCOOP_APP_DIR\scoop.zip"
617676
if (!(Test-Path $SCOOP_APP_DIR)) {
618677
New-Item -Type Directory $SCOOP_APP_DIR | Out-Null
619678
}
620-
Write-Verbose "Downloading $SCOOP_PACKAGE_REPO to $scoopZipfile"
621-
$downloader.downloadFile($SCOOP_PACKAGE_REPO, $scoopZipfile)
679+
Write-Verbose ("Downloading {0} to $scoopZipfile" -f $ScoopSources.AppRepoZip)
680+
$downloader.downloadFile($ScoopSources.AppRepoZip, $scoopZipfile)
681+
# extract
682+
$scoopUnzipTempDir = "$SCOOP_APP_DIR\_tmp"
683+
Write-Verbose "Extracting $scoopZipfile to $scoopUnzipTempDir"
684+
Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
685+
Copy-Item "$scoopUnzipTempDir\scoop-*\*" $SCOOP_APP_DIR -Recurse -Force
686+
# cleanup
687+
Remove-Item $scoopUnzipTempDir -Recurse -Force
688+
Remove-Item $scoopZipfile
689+
}
690+
691+
if ($ScoopSources.MainBucketRepoZip -and $downloadMainBucketZipRequired) {
622692
# 2. download scoop main bucket
623693
$scoopMainZipfile = "$SCOOP_MAIN_BUCKET_DIR\scoop-main.zip"
624694
if (!(Test-Path $SCOOP_MAIN_BUCKET_DIR)) {
625695
New-Item -Type Directory $SCOOP_MAIN_BUCKET_DIR | Out-Null
626696
}
627-
Write-Verbose "Downloading $SCOOP_MAIN_BUCKET_REPO to $scoopMainZipfile"
628-
$downloader.downloadFile($SCOOP_MAIN_BUCKET_REPO, $scoopMainZipfile)
629-
630-
# Extract files from downloaded zip
631-
Write-InstallInfo 'Extracting...'
632-
# 1. extract scoop
633-
$scoopUnzipTempDir = "$SCOOP_APP_DIR\_tmp"
634-
Write-Verbose "Extracting $scoopZipfile to $scoopUnzipTempDir"
635-
Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
636-
Copy-Item "$scoopUnzipTempDir\scoop-*\*" $SCOOP_APP_DIR -Recurse -Force
637-
# 2. extract scoop main bucket
697+
Write-Verbose ("Downloading {0} to $scoopMainZipfile" -f $ScoopSources.MainBucketRepoZip)
698+
$downloader.downloadFile($ScoopSources.MainBucketRepoZip, $scoopMainZipfile)
699+
# extract
638700
$scoopMainUnzipTempDir = "$SCOOP_MAIN_BUCKET_DIR\_tmp"
639701
Write-Verbose "Extracting $scoopMainZipfile to $scoopMainUnzipTempDir"
640702
Expand-ZipArchive $scoopMainZipfile $scoopMainUnzipTempDir
641703
Copy-Item "$scoopMainUnzipTempDir\Main-*\*" $SCOOP_MAIN_BUCKET_DIR -Recurse -Force
642-
643-
# Cleanup
644-
Remove-Item $scoopUnzipTempDir -Recurse -Force
645-
Remove-Item $scoopZipfile
704+
# cleanup
646705
Remove-Item $scoopMainUnzipTempDir -Recurse -Force
647706
Remove-Item $scoopMainZipfile
648707
}
708+
649709
# Create the scoop shim
650710
Import-ScoopShim
651711
# Finially ensure scoop shims is in the PATH
@@ -689,20 +749,17 @@ $SCOOP_GLOBAL_DIR = $ScoopGlobalDir, $env:SCOOP_GLOBAL, "$env:ProgramData\scoop"
689749
$SCOOP_CACHE_DIR = $ScoopCacheDir, $env:SCOOP_CACHE, "$SCOOP_DIR\cache" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
690750
# Scoop shims directory
691751
$SCOOP_SHIMS_DIR = "$SCOOP_DIR\shims"
752+
# Scoop buckets directory
753+
$SCOOP_BUCKETS_DIR = "$SCOOP_DIR\buckets"
692754
# Scoop itself directory
693755
$SCOOP_APP_DIR = "$SCOOP_DIR\apps\scoop\current"
694756
# Scoop main bucket directory
695-
$SCOOP_MAIN_BUCKET_DIR = "$SCOOP_DIR\buckets\main"
757+
$SCOOP_MAIN_BUCKET_DIR = "$SCOOP_BUCKETS_DIR\main"
696758
# Scoop config file location
697759
$SCOOP_CONFIG_HOME = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Select-Object -First 1
698760
$SCOOP_CONFIG_FILE = "$SCOOP_CONFIG_HOME\scoop\config.json"
699761

700-
# TODO: Use a specific version of Scoop and the main bucket
701-
$SCOOP_PACKAGE_REPO = 'https://github.com/ScoopInstaller/Scoop/archive/master.zip'
702-
$SCOOP_MAIN_BUCKET_REPO = 'https://github.com/ScoopInstaller/Main/archive/master.zip'
703-
704-
$SCOOP_PACKAGE_GIT_REPO = 'https://github.com/ScoopInstaller/Scoop.git'
705-
$SCOOP_MAIN_BUCKET_GIT_REPO = 'https://github.com/ScoopInstaller/Main.git'
762+
$ScoopSources = Get-Scoop-Source -ScoopAppRepoZip $ScoopAppRepoZip -ScoopAppRepoGit $ScoopAppRepoGit -ScoopMainBucketRepoZip $ScoopMainBucketRepoZip -ScoopMainBucketRepoGit $ScoopMainBucketRepoGit
706763

707764
# Quit if anything goes wrong
708765
$oldErrorActionPreference = $ErrorActionPreference

test/install.Tests.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,74 @@ Describe 'Test-CommandAvailable' -Tag 'CommandLine' {
4040
}
4141
}
4242
}
43+
44+
Describe 'Get-Scoop-Source' -Tag 'Scoop' {
45+
Context 'No source parameters provided' {
46+
It 'Returns default source URLs' {
47+
$expectedSource = @{
48+
AppRepoZip = "https://github.com/ScoopInstaller/Scoop/archive/master.zip"
49+
AppRepoGit = "https://github.com/ScoopInstaller/Scoop.git"
50+
MainBucketRepoZip = "https://github.com/ScoopInstaller/Main/archive/master.zip"
51+
MainBucketRepoGit = "https://github.com/ScoopInstaller/Main.git"
52+
}
53+
$actualSource = Get-Scoop-Source
54+
$actualSourceJson = $actualSource | ConvertTo-Json
55+
$expectedSourceJson = $expectedSource | ConvertTo-Json
56+
$actualSourceJson | Should -Be $expectedSourceJson
57+
}
58+
}
59+
60+
Context 'Selected source parameters provided' {
61+
It 'Provide all source parameters as arguments' {
62+
$providedSource = @{
63+
AppRepoZip = "https://example.com/apprepo.zip"
64+
AppRepoGit = "https://example.com/apprepo.git"
65+
MainBucketRepoZip = "https://example.com/mainbucket.zip"
66+
MainBucketRepoGit = "https://example.com/mainbucket.git"
67+
}
68+
$actualSource = Get-Scoop-Source -ScoopAppRepoZip $providedSource.AppRepoZip `
69+
-ScoopAppRepoGit $providedSource.AppRepoGit `
70+
-ScoopMainBucketRepoZip $providedSource.MainBucketRepoZip `
71+
-ScoopMainBucketRepoGit $providedSource.MainBucketRepoGit
72+
$actualSourceJson = $actualSource | ConvertTo-Json
73+
$expectedSourceJson = $providedSource | ConvertTo-Json
74+
$actualSourceJson | Should -Be $expectedSourceJson
75+
}
76+
77+
It 'Provide app repo zip url as argument' {
78+
$actualSource = Get-Scoop-Source -ScoopAppRepoZip "https://example.com/apprepo.zip"
79+
$actualSourceJson = $actualSource | ConvertTo-Json
80+
$expectedSourceJson = @{
81+
AppRepoZip = "https://example.com/apprepo.zip"
82+
AppRepoGit = $null
83+
MainBucketRepoZip = $null
84+
MainBucketRepoGit = $null
85+
} | ConvertTo-Json
86+
$actualSourceJson | Should -Be $expectedSourceJson
87+
}
88+
89+
It 'Provide app repo git url as argument' {
90+
$actualSource = Get-Scoop-Source -ScoopAppRepoGit "https://example.com/apprepo.git"
91+
$actualSourceJson = $actualSource | ConvertTo-Json
92+
$expectedSourceJson = @{
93+
AppRepoZip = $null
94+
AppRepoGit = "https://example.com/apprepo.git"
95+
MainBucketRepoZip = $null
96+
MainBucketRepoGit = $null
97+
} | ConvertTo-Json
98+
$actualSourceJson | Should -Be $expectedSourceJson
99+
}
100+
101+
It 'Provide main bucket repo zip url as argument' {
102+
$actualSource = Get-Scoop-Source -ScoopMainBucketRepoZip "https://example.com/mainbucket.zip"
103+
$actualSourceJson = $actualSource | ConvertTo-Json
104+
$expectedSourceJson = @{
105+
AppRepoZip = "https://github.com/ScoopInstaller/Scoop/archive/master.zip"
106+
AppRepoGit = "https://github.com/ScoopInstaller/Scoop.git"
107+
MainBucketRepoZip = "https://example.com/mainbucket.zip"
108+
MainBucketRepoGit = "https://github.com/ScoopInstaller/Main.git"
109+
} | ConvertTo-Json
110+
$actualSourceJson | Should -Be $expectedSourceJson
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)