-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall-windows
67 lines (52 loc) · 2.98 KB
/
install-windows
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
$nargoHome = "$env:USERPROFILE\.nargo"
$nargoHomeBin = "$nargoHome\bin"
$nargoUri = "https://github.com/noir-lang/noir/releases/download/nightly/nargo-x86_64-pc-windows-msvc.zip"
# Get the ID and security principal of the current user account
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
# Get the security principal for the administrator role
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
Write-Output $myInvocation.MyCommand.Definition
# Check to see if we are currently running as an administrator
if ($myWindowsPrincipal.IsInRole($adminRole))
{
# We are running as an administrator, so change the title and background colour to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated Nargo Installation)";
Clear-Host;
# Remove-Item -Force -R $nargoHome
# Remove-Item -Force -R $env:APPDATA\noir-lang
Write-Output "Nargo Home set to $nargoHome"
Write-Output "Nargo Home set to $nargoHomeBin"
mkdir -f -p $nargoHomeBin
Write-Output "Nargo Home folder '$nargoHomeBin' created."
$tmp = New-TemporaryFile | Rename-Item -PassThru -NewName { $_ -replace 'tmp$', 'zip' }
Write-Output "Downloading '$nargoUri' to '$tmp'";
Invoke-RestMethod -Method Get -Uri $nargoUri -OutFile $tmp
Write-Output "Expanding '$tmp' to '$nargoHomeBin'";
Expand-Archive -Force -Path $tmp -DestinationPath $nargoHomeBin
Write-Output "Moving '$nargoHomeBin\noir-lang' to '$env:APPDATA\noir-lang'";
Move-Item -Force -Path "$nargoHomeBin\noir-lang" -Destination "$env:APPDATA\noir-lang"
$Reg = "Registry::HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
$OldPath = (Get-ItemProperty -Path "$Reg" -Name PATH).Path
if ($OldPath -split ';' -contains $nargoHomeBin) {
Write-Host "$nargoHomeBin already set..."
}
else {
Write-Output "Setting system path to '$nargoHomeBin\'";
$NewPath= $OldPath + ";" + "$nargoHomeBin"
Set-ItemProperty -Path $Reg -Name PATH -Value $NewPath;
Write-Host "Please restart any shell process before using nargo command..."
}
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
} else {
# Create a new process object that starts PowerShell
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
}
# Note: Meant to be run as "iex (iwr https://noir-lang.dev/install).Content"