-
Notifications
You must be signed in to change notification settings - Fork 22
/
Run-Setup.ps1
68 lines (65 loc) · 2.33 KB
/
Run-Setup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
param ([switch]$Force)
Set-StrictMode -Version 3.0
$ErrorActionPreference = 'Stop'
if (!$IsWindows) {
Write-Warning "This script ($PSCommandPath) is only for Windows."
exit
}
$script:setupDir = Join-Path $PSScriptRoot Setup
$script:isDotSourced = $MyInvocation.InvocationName -eq '.' -or $MyInvocation.Line -eq ''
if (!$isDotSourced) {
if ($Force) {
if (Test-Path $setupDir/.setupran) {
Remove-Item $setupDir/.setupran -Force
}
if (Test-Path $setupDir/.setupran-nonelevated) {
Remove-Item $setupDir/.setupran-nonelevated -Force
}
if (Test-Path $setupDir/.setupdonotrun) {
Remove-Item $setupDir/.setupdonotrun -Force
}
}
}
$script:profileDir = Join-Path $PSScriptRoot Profile
. "$profileDir/Functions.ps1"
if (Test-Elevated) {
if ($PSEdition -eq 'Core') {
. "$PSScriptRoot/Setup/Setup-Check.ps1"
CheckSetup
} else {
. "$PSScriptRoot/Setup/Setup-Bootstrap.ps1"
if ($null -eq (Get-Command pwsh -ErrorAction SilentlyContinue)) {
Write-Warning "PowerShell Core is not available and Setup cannot run. Install it from https://aka.ms/PSWindows, and then start PowerShell again."
} else {
pwsh.exe -NoProfile -Command ". `"$PSScriptRoot/Setup/Setup-Check.ps1`"; CheckSetup"
Test-Error
Sync-Path
}
}
} else {
if ($PSEdition -eq 'Core') {
. "$PSScriptRoot/Setup/Setup-NonElevated.ps1"
CheckSetupNonElevated
} else {
. "$PSScriptRoot/Setup/Setup-Bootstrap.ps1"
if ($null -eq (Get-Command pwsh -ErrorAction SilentlyContinue)) {
Write-Warning "PowerShell Core is not available and Setup cannot run. Install it from https://aka.ms/PSWindows, and then start PowerShell again."
} else {
pwsh.exe -NoProfile -Command ". `"$PSScriptRoot/Setup/Setup-NonElevated.ps1`"; CheckSetupNonElevated"
Test-Error
Sync-Path
}
}
}
if (Test-Path Function:\CheckSetup) {
Remove-Item -Path Function:\CheckSetup
}
if (Test-Path Function:\CheckSetupNonElevated) {
Remove-Item -Path Function:\CheckSetupNonElevated
}
if (Test-Path Function:\RunSetupNonElevated) {
Remove-Item -Path Function:\RunSetupNonElevated
}
if (Test-Path Function:\RunSetup) {
Remove-Item -Path Function:\RunSetup
}