4545. PARAMETER Proxy
4646 Specifies proxy to use during the installation.
4747. PARAMETER ProxyCredential
48- Specifies credential for the given prxoy .
48+ Specifies credential for the given proxy .
4949. PARAMETER ProxyUseDefaultCredentials
5050 Use the credentials of the current user for the proxy server that is specified by the -Proxy parameter.
5151. PARAMETER RunAsAdmin
@@ -518,6 +518,14 @@ function Add-DefaultConfig {
518518 Add-Config - Name ' last_update' - Value ([System.DateTime ]::Now.ToString(' o' )) | Out-Null
519519}
520520
521+ function Test-CommandAvailable {
522+ param (
523+ [Parameter (Mandatory = $True , Position = 0 )]
524+ [String ] $Command
525+ )
526+ return [Boolean ](Get-Command $Command - ErrorAction Ignore)
527+ }
528+
521529function Install-Scoop {
522530 Write-InstallInfo " Initializing..."
523531 # Validate install parameters
@@ -527,43 +535,64 @@ function Install-Scoop {
527535 # Enable TLS 1.2
528536 Optimize-SecurityProtocol
529537
530- # Download scoop zip from GitHub
531- Write-InstallInfo " Downloading..."
538+ # Download scoop from GitHub
539+ Write-InstallInfo " Downloading ..."
532540 $downloader = Get-Downloader
533- # 1. download scoop
534- $scoopZipfile = " $SCOOP_APP_DIR \scoop.zip"
535- if (! (Test-Path $SCOOP_APP_DIR )) {
536- New-Item - Type Directory $SCOOP_APP_DIR | Out-Null
537- }
538- Write-Verbose " Downloading $SCOOP_PACKAGE_REPO to $scoopZipfile "
539- $downloader.downloadFile ($SCOOP_PACKAGE_REPO , $scoopZipfile )
540- # 2. download scoop main bucket
541- $scoopMainZipfile = " $SCOOP_MAIN_BUCKET_DIR \scoop-main.zip"
542- if (! (Test-Path $SCOOP_MAIN_BUCKET_DIR )) {
543- New-Item - Type Directory $SCOOP_MAIN_BUCKET_DIR | Out-Null
544- }
545- Write-Verbose " Downloading $SCOOP_MAIN_BUCKET_REPO to $scoopMainZipfile "
546- $downloader.downloadFile ($SCOOP_MAIN_BUCKET_REPO , $scoopMainZipfile )
547-
548- # Extract files from downloaded zip
549- Write-InstallInfo " Extracting..."
550- # 1. extract scoop
551- $scoopUnzipTempDir = " $SCOOP_APP_DIR \_tmp"
552- Write-Verbose " Extracting $scoopZipfile to $scoopUnzipTempDir "
553- Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
554- Copy-Item " $scoopUnzipTempDir \scoop-*\*" $SCOOP_APP_DIR - Recurse - Force
555- # 2. extract scoop main bucket
556- $scoopMainUnzipTempDir = " $SCOOP_MAIN_BUCKET_DIR \_tmp"
557- Write-Verbose " Extracting $scoopMainZipfile to $scoopMainUnzipTempDir "
558- Expand-ZipArchive $scoopMainZipfile $scoopMainUnzipTempDir
559- Copy-Item " $scoopMainUnzipTempDir \Main-*\*" $SCOOP_MAIN_BUCKET_DIR - Recurse - Force
560-
561- # Cleanup
562- Remove-Item $scoopUnzipTempDir - Recurse - Force
563- Remove-Item $scoopZipfile
564- Remove-Item $scoopMainUnzipTempDir - Recurse - Force
565- Remove-Item $scoopMainZipfile
566541
542+ if (Test-CommandAvailable (' git' )) {
543+ $old_https = $env: HTTPS_PROXY
544+ $old_http = $env: HTTP_PROXY
545+ try {
546+ if ($downloader.Proxy ) {
547+ # define env vars for git when behind a proxy
548+ $Env: HTTP_PROXY = $downloader.Proxy.Address
549+ $Env: HTTPS_PROXY = $downloader.Proxy.Address
550+ }
551+ Write-Verbose " Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR "
552+ git clone - q $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
553+ Write-Verbose " Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR "
554+ git clone - q $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
555+ } catch {
556+ Get-Error $_
557+ } finally {
558+ $env: HTTPS_PROXY = $old_https
559+ $env: HTTP_PROXY = $old_http
560+ }
561+ } else {
562+ # 1. download scoop
563+ $scoopZipfile = " $SCOOP_APP_DIR \scoop.zip"
564+ if (! (Test-Path $SCOOP_APP_DIR )) {
565+ New-Item - Type Directory $SCOOP_APP_DIR | Out-Null
566+ }
567+ Write-Verbose " Downloading $SCOOP_PACKAGE_REPO to $scoopZipfile "
568+ $downloader.downloadFile ($SCOOP_PACKAGE_REPO , $scoopZipfile )
569+ # 2. download scoop main bucket
570+ $scoopMainZipfile = " $SCOOP_MAIN_BUCKET_DIR \scoop-main.zip"
571+ if (! (Test-Path $SCOOP_MAIN_BUCKET_DIR )) {
572+ New-Item - Type Directory $SCOOP_MAIN_BUCKET_DIR | Out-Null
573+ }
574+ Write-Verbose " Downloading $SCOOP_MAIN_BUCKET_REPO to $scoopMainZipfile "
575+ $downloader.downloadFile ($SCOOP_MAIN_BUCKET_REPO , $scoopMainZipfile )
576+
577+ # Extract files from downloaded zip
578+ Write-InstallInfo " Extracting..."
579+ # 1. extract scoop
580+ $scoopUnzipTempDir = " $SCOOP_APP_DIR \_tmp"
581+ Write-Verbose " Extracting $scoopZipfile to $scoopUnzipTempDir "
582+ Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
583+ Copy-Item " $scoopUnzipTempDir \scoop-*\*" $SCOOP_APP_DIR - Recurse - Force
584+ # 2. extract scoop main bucket
585+ $scoopMainUnzipTempDir = " $SCOOP_MAIN_BUCKET_DIR \_tmp"
586+ Write-Verbose " Extracting $scoopMainZipfile to $scoopMainUnzipTempDir "
587+ Expand-ZipArchive $scoopMainZipfile $scoopMainUnzipTempDir
588+ Copy-Item " $scoopMainUnzipTempDir \Main-*\*" $SCOOP_MAIN_BUCKET_DIR - Recurse - Force
589+
590+ # Cleanup
591+ Remove-Item $scoopUnzipTempDir - Recurse - Force
592+ Remove-Item $scoopZipfile
593+ Remove-Item $scoopMainUnzipTempDir - Recurse - Force
594+ Remove-Item $scoopMainZipfile
595+ }
567596 # Create the scoop shim
568597 Import-ScoopShim
569598 # Finially ensure scoop shims is in the PATH
@@ -616,6 +645,9 @@ $SCOOP_CONFIG_FILE = "$SCOOP_CONFIG_HOME\scoop\config.json"
616645$SCOOP_PACKAGE_REPO = " https://github.com/ScoopInstaller/Scoop/archive/master.zip"
617646$SCOOP_MAIN_BUCKET_REPO = " https://github.com/ScoopInstaller/Main/archive/master.zip"
618647
648+ $SCOOP_PACKAGE_GIT_REPO = " https://github.com/ScoopInstaller/Scoop.git"
649+ $SCOOP_MAIN_BUCKET_GIT_REPO = " https://github.com/ScoopInstaller/Main.git"
650+
619651# Quit if anything goes wrong
620652$oldErrorActionPreference = $ErrorActionPreference
621653$ErrorActionPreference = ' Stop'
0 commit comments