Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-user install support in windows bootstrap #1133

Closed
wants to merge 3 commits into from
Closed
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
31 changes: 27 additions & 4 deletions scripts/bootstrap/bootstrap-haskell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ param (
# Whether to disable adjusting bashrc (in msys2 env) with PATH
[switch]$DontAdjustBashRc,
# The msys2 environment to use, see https://www.msys2.org/docs/environments/ (defauts to MINGW64, MINGW32 or CLANGARM64, depending on the architecture)
[string]$Msys2Env
[string]$Msys2Env,
# Do a multi-user install (requires administrative privileges to modify system PATH env)
[switch]$MultiUserInstall
)

$DefaultMsys2Version = "20221216"
Expand Down Expand Up @@ -88,6 +90,12 @@ function Create-Shortcut {
Move-Item -LiteralPath $TmpFile -Destination $FinalDest
}

function IsAdmin() {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

function Add-EnvPath {
param(
[Parameter(Mandatory=$true,HelpMessage='The Path to add to Users environment')]
Expand Down Expand Up @@ -191,6 +199,10 @@ function Exec

#### Gather system information and ask user questions ####

if ($MultiUserInstall -and -not (IsAdmin)) {
throw ('Administrative privileges are required for multi-user installation.')
}

# Only x86 32/64-bit is supported
$SupportedArchitectures = 'AMD64', 'x86'
if (!$SupportedArchitectures.contains($env:PROCESSOR_ARCHITECTURE)) {
Expand Down Expand Up @@ -329,7 +341,11 @@ Press enter to accept the default [{0}]:
}

Print-Msg -msg ('Setting env variable GHCUP_INSTALL_BASE_PREFIX to ''{0}''' -f $GhcupBasePrefix)
$null = [Environment]::SetEnvironmentVariable("GHCUP_INSTALL_BASE_PREFIX", $GhcupBasePrefix, [System.EnvironmentVariableTarget]::User)
if ($MultiUserInstall) {
$null = [Environment]::SetEnvironmentVariable("GHCUP_INSTALL_BASE_PREFIX", $GhcupBasePrefix, [System.EnvironmentVariableTarget]::Machine)
} else {
$null = [Environment]::SetEnvironmentVariable("GHCUP_INSTALL_BASE_PREFIX", $GhcupBasePrefix, [System.EnvironmentVariableTarget]::User)
}


$GhcupDir = ('{0}\ghcup' -f $GhcupBasePrefix)
Expand Down Expand Up @@ -656,8 +672,15 @@ if ($Host.Name -eq "ConsoleHost")
$null = New-Item -Path $DesktopDir -Name "Uninstall Haskell.ps1" -ItemType "file" -Force -Value $uninstallShortCut
}

Print-Msg -msg ('Adding {0}\bin to Users Path...' -f $GhcupDir)
Add-EnvPath -Path ('{0}\bin' -f ([System.IO.Path]::GetFullPath("$GhcupDir"))) -Container 'User'
$Container = 'User'
if ($MultiUserInstall) {
Print-Msg -msg ('Adding {0}\bin to System Path...' -f $GhcupDir)
Print-Msg -msg ('Other users that are currently signed in will have to sign out and login again to use ghcup')
$Container = 'Machine'
} else {
Print-Msg -msg ('Adding {0}\bin to Users Path...' -f $GhcupDir)
}
Add-EnvPath -Path ('{0}\bin' -f ([System.IO.Path]::GetFullPath("$GhcupDir"))) -Container $Container



Expand Down
Loading