Skip to content

Commit

Permalink
Use git for installation when available already
Browse files Browse the repository at this point in the history
  • Loading branch information
xxthunder committed Jan 23, 2023
1 parent f1cf244 commit 84e7cf7
Showing 1 changed file with 57 additions and 36 deletions.
93 changes: 57 additions & 36 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,18 @@ function Add-DefaultConfig {
Add-Config -Name 'last_update' -Value ([System.DateTime]::Now.ToString('o')) | Out-Null
}

function Test-Command-Available {
param (
[Parameter(Mandatory = $True, Position = 0)]
[String] $Command
)
if (Get-Command $Command -ErrorAction SilentlyContinue) {
return $true
} else {
return $false
}
}

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

# Download scoop zip 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
if (Test-Command-Available('git')) {
Write-Verbose "Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR"
git clone $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
Write-Verbose "Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR"
git clone $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
} else {
# Download scoop zip 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
}
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 @@ -575,6 +593,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

0 comments on commit 84e7cf7

Please sign in to comment.