Skip to content

Commit 84e7cf7

Browse files
committed
Use git for installation when available already
1 parent f1cf244 commit 84e7cf7

File tree

1 file changed

+57
-36
lines changed

1 file changed

+57
-36
lines changed

install.ps1

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,18 @@ function Add-DefaultConfig {
477477
Add-Config -Name 'last_update' -Value ([System.DateTime]::Now.ToString('o')) | Out-Null
478478
}
479479

480+
function Test-Command-Available {
481+
param (
482+
[Parameter(Mandatory = $True, Position = 0)]
483+
[String] $Command
484+
)
485+
if (Get-Command $Command -ErrorAction SilentlyContinue) {
486+
return $true
487+
} else {
488+
return $false
489+
}
490+
}
491+
480492
function Install-Scoop {
481493
Write-InstallInfo "Initializing..."
482494
# Validate install parameters
@@ -486,43 +498,49 @@ function Install-Scoop {
486498
# Enable TLS 1.2
487499
Optimize-SecurityProtocol
488500

489-
# Download scoop zip from GitHub
490-
Write-InstallInfo "Downloading..."
491-
$downloader = Get-Downloader
492-
# 1. download scoop
493-
$scoopZipfile = "$SCOOP_APP_DIR\scoop.zip"
494-
if (!(Test-Path $SCOOP_APP_DIR)) {
495-
New-Item -Type Directory $SCOOP_APP_DIR | Out-Null
496-
}
497-
Write-Verbose "Downloading $SCOOP_PACKAGE_REPO to $scoopZipfile"
498-
$downloader.downloadFile($SCOOP_PACKAGE_REPO, $scoopZipfile)
499-
# 2. download scoop main bucket
500-
$scoopMainZipfile = "$SCOOP_MAIN_BUCKET_DIR\scoop-main.zip"
501-
if (!(Test-Path $SCOOP_MAIN_BUCKET_DIR)) {
502-
New-Item -Type Directory $SCOOP_MAIN_BUCKET_DIR | Out-Null
501+
if (Test-Command-Available('git')) {
502+
Write-Verbose "Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR"
503+
git clone $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
504+
Write-Verbose "Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR"
505+
git clone $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
506+
} else {
507+
# Download scoop zip from GitHub
508+
Write-InstallInfo "Downloading..."
509+
$downloader = Get-Downloader
510+
# 1. download scoop
511+
$scoopZipfile = "$SCOOP_APP_DIR\scoop.zip"
512+
if (!(Test-Path $SCOOP_APP_DIR)) {
513+
New-Item -Type Directory $SCOOP_APP_DIR | Out-Null
514+
}
515+
Write-Verbose "Downloading $SCOOP_PACKAGE_REPO to $scoopZipfile"
516+
$downloader.downloadFile($SCOOP_PACKAGE_REPO, $scoopZipfile)
517+
# 2. download scoop main bucket
518+
$scoopMainZipfile = "$SCOOP_MAIN_BUCKET_DIR\scoop-main.zip"
519+
if (!(Test-Path $SCOOP_MAIN_BUCKET_DIR)) {
520+
New-Item -Type Directory $SCOOP_MAIN_BUCKET_DIR | Out-Null
521+
}
522+
Write-Verbose "Downloading $SCOOP_MAIN_BUCKET_REPO to $scoopMainZipfile"
523+
$downloader.downloadFile($SCOOP_MAIN_BUCKET_REPO, $scoopMainZipfile)
524+
525+
# Extract files from downloaded zip
526+
Write-InstallInfo "Extracting..."
527+
# 1. extract scoop
528+
$scoopUnzipTempDir = "$SCOOP_APP_DIR\_tmp"
529+
Write-Verbose "Extracting $scoopZipfile to $scoopUnzipTempDir"
530+
Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
531+
Copy-Item "$scoopUnzipTempDir\scoop-*\*" $SCOOP_APP_DIR -Recurse -Force
532+
# 2. extract scoop main bucket
533+
$scoopMainUnzipTempDir = "$SCOOP_MAIN_BUCKET_DIR\_tmp"
534+
Write-Verbose "Extracting $scoopMainZipfile to $scoopMainUnzipTempDir"
535+
Expand-ZipArchive $scoopMainZipfile $scoopMainUnzipTempDir
536+
Copy-Item "$scoopMainUnzipTempDir\Main-*\*" $SCOOP_MAIN_BUCKET_DIR -Recurse -Force
537+
538+
# Cleanup
539+
Remove-Item $scoopUnzipTempDir -Recurse -Force
540+
Remove-Item $scoopZipfile
541+
Remove-Item $scoopMainUnzipTempDir -Recurse -Force
542+
Remove-Item $scoopMainZipfile
503543
}
504-
Write-Verbose "Downloading $SCOOP_MAIN_BUCKET_REPO to $scoopMainZipfile"
505-
$downloader.downloadFile($SCOOP_MAIN_BUCKET_REPO, $scoopMainZipfile)
506-
507-
# Extract files from downloaded zip
508-
Write-InstallInfo "Extracting..."
509-
# 1. extract scoop
510-
$scoopUnzipTempDir = "$SCOOP_APP_DIR\_tmp"
511-
Write-Verbose "Extracting $scoopZipfile to $scoopUnzipTempDir"
512-
Expand-ZipArchive $scoopZipfile $scoopUnzipTempDir
513-
Copy-Item "$scoopUnzipTempDir\scoop-*\*" $SCOOP_APP_DIR -Recurse -Force
514-
# 2. extract scoop main bucket
515-
$scoopMainUnzipTempDir = "$SCOOP_MAIN_BUCKET_DIR\_tmp"
516-
Write-Verbose "Extracting $scoopMainZipfile to $scoopMainUnzipTempDir"
517-
Expand-ZipArchive $scoopMainZipfile $scoopMainUnzipTempDir
518-
Copy-Item "$scoopMainUnzipTempDir\Main-*\*" $SCOOP_MAIN_BUCKET_DIR -Recurse -Force
519-
520-
# Cleanup
521-
Remove-Item $scoopUnzipTempDir -Recurse -Force
522-
Remove-Item $scoopZipfile
523-
Remove-Item $scoopMainUnzipTempDir -Recurse -Force
524-
Remove-Item $scoopMainZipfile
525-
526544
# Create the scoop shim
527545
Import-ScoopShim
528546
# Finially ensure scoop shims is in the PATH
@@ -575,6 +593,9 @@ $SCOOP_CONFIG_FILE = "$SCOOP_CONFIG_HOME\scoop\config.json"
575593
$SCOOP_PACKAGE_REPO = "https://github.com/ScoopInstaller/Scoop/archive/master.zip"
576594
$SCOOP_MAIN_BUCKET_REPO = "https://github.com/ScoopInstaller/Main/archive/master.zip"
577595

596+
$SCOOP_PACKAGE_GIT_REPO = "https://github.com/ScoopInstaller/Scoop.git"
597+
$SCOOP_MAIN_BUCKET_GIT_REPO = "https://github.com/ScoopInstaller/Main.git"
598+
578599
# Quit if anything goes wrong
579600
$oldErrorActionPreference = $ErrorActionPreference
580601
$ErrorActionPreference = 'Stop'

0 commit comments

Comments
 (0)