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+
571618function 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
0 commit comments