Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,36 @@ function Write-InstallInfo {
$host.UI.RawUI.ForegroundColor = $backup
}

function Deny-Install {
function Exit-Install {
param(
[String] $message,
[Int] $errorCode = 1
[Int] $ErrorCode = 1
)

Write-InstallInfo -String $message -ForegroundColor DarkRed
Write-InstallInfo 'Abort.'

# Don't abort if invoked with iex that would close the PS session
if ($IS_EXECUTED_FROM_IEX) {
break
} else {
exit $errorCode
exit $ErrorCode
}
}

function Deny-Install {
param(
[String] $Message,
[Int] $ErrorCode = 1
)

Write-InstallInfo -String $Message -ForegroundColor DarkRed
Write-InstallInfo 'Abort.'
Exit-Install -ErrorCode $ErrorCode
}

function Test-LanguageMode {
if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage') {
# `Write-InstallInfo` cannot be used here as it depends on FullLanguage mode
Write-Output 'Scoop requires PowerShell FullLanguage mode to run, current PowerShell environment is restricted.'
Write-Output 'Abort.'

if ($IS_EXECUTED_FROM_IEX) {
break
} else {
exit $errorCode
}
Exit-Install
}
}

Expand Down Expand Up @@ -167,7 +170,7 @@ function Test-Prerequisite {

# Test if scoop is installed, by checking if scoop command exists.
if (Test-CommandAvailable('scoop')) {
Deny-Install "Scoop is already installed. Run 'scoop update' to get the latest version."
Deny-Install "Scoop is already installed. Run 'scoop update' to get the latest version." -ErrorCode 0
}
}

Expand Down Expand Up @@ -457,7 +460,7 @@ function Add-ShimsDirToPath {
}

if (!($h -eq '\')) {
$friendlyPath = "$SCOOP_SHIMS_DIR" -Replace ([Regex]::Escape($h)), '~\'
$friendlyPath = "$SCOOP_SHIMS_DIR" -replace ([Regex]::Escape($h)), '~\'
Write-InstallInfo "Adding $friendlyPath to your path."
} else {
Write-InstallInfo "Adding $SCOOP_SHIMS_DIR to your path."
Expand Down Expand Up @@ -593,12 +596,12 @@ function Install-Scoop {
}
Write-Verbose "Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR"
git clone -q $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
if (-Not $?) {
if (-not $?) {
throw 'Cloning failed. Falling back to downloading zip files.'
}
Write-Verbose "Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR"
git clone -q $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
if (-Not $?) {
if (-not $?) {
throw 'Cloning failed. Falling back to downloading zip files.'
}
$downloadZipsRequired = $False
Expand Down