-
-
Notifications
You must be signed in to change notification settings - Fork 662
/
Copy pathWinSetup.ps1
90 lines (72 loc) · 2.89 KB
/
WinSetup.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function Cmd-Path($file) {
try { Split-Path -Parent (Get-Command "$file.exe" -ErrorAction Stop).Source } catch { "" }
}
# resolve Opam binary and repo
# you can choose when opam is installed by setting OPAM_INSTALL_DIR (and OPAMROOT - optional)
$Opam = Cmd-Path "opam"
$OpamRepo = $env:OPAMROOT
$Git = Cmd-Path "git"
if( !$Opam ) { $Opam = $env:OPAM_INSTALL_DIR }
if( !$Opam ) { $Opam = (Get-Item .).FullName + "\opam" }
if( !$OpamRepo ) { $OpamRepo = "$Opam\repo" }
$CygRoot = "$OpamRepo\.cygwin\root"
$WinSysPath = "$env:SystemRoot\System32"
$Neko = Cmd-Path "neko"
$RegPath = "HKCU:\Environment"
$MbedVer = "2.16.3"
$MbedTLS = "https://github.com/Simn/mingw64-mbedtls/releases/download/$MbedVer/mingw64-x86_64-mbedtls-$MbedVer-1.tar.xz"
function Install-Init {
if( !$Git ) {
echo "**ERROR** git.exe could not be found in PATH"
Exit
}
if( !$Neko ) {
echo "**ERROR** Neko.exe could not be found in PATH"
Exit
}
# reset PATH to prevent conflicting cygwin or existing install
Set-Item -Path env:PATH -Value "$CygRoot\usr\x86_64-w64-mingw32\bin;$CygRoot\bin;$Opam;$Neko;$Git;$WinSysPath"
# set OPAM root dir
Set-Item -Path env:OPAMROOT -Value "$OpamRepo"
}
function Install-Opam {
# download opam binary
Invoke-Expression "& { $(Invoke-RestMethod https://opam.ocaml.org/install.ps1)} -OpamBinDir $Opam"
# init opam, assume that we have windows GIT installed
Invoke-Expression "opam init --cygwin-internal-install --no-git-location --shell=powershell --shell-setup"
}
function Install-Haxe-Deps {
Invoke-Expression "opam install . --deps-only --confirm-level=yes"
# install mbedtls mingw package
$tmpFile = "./mbed.tgz"
Invoke-Expression "curl $MbedTLS -o $tmpFile"
Invoke-Expression "tar -C / -xvf $tmpFile"
Remove-Item "$tmpFile"
# install lsp server
Invoke-Expression "opam install ocaml-lsp-server --confirm-level=yes"
}
function Add-Path($NewPath) {
$CurrentPath = (Get-ItemProperty -Path $RegPath -Name Path).Path
if ($CurrentPath -notlike "*$NewPath*") {
$CurrentPath = "$NewPath;$CurrentPath"
Set-ItemProperty -Path $RegPath -Name Path -Value $CurrentPath
}
}
function Setup-Paths {
Add-Path "$OpamRepo\default\bin"
Add-Path "$CygRoot\bin"
Add-Path "$CygRoot\usr\x86_64-w64-mingw32\bin"
Add-Path "$CygRoot\usr\x86_64-w64-mingw32\sys-root\mingw\bin"
Set-ItemProperty -Path $RegPath -Name OPAMROOT -Value $OpamRepo
# refresh for all processes (no need to restart)
$signature = @"
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult);
"@
$SendMessageTimeout = Add-Type -MemberDefinition $signature -Name "Win32SendMessageTimeout" -Namespace Win32Functions -PassThru
$SendMessageTimeout::SendMessageTimeout([IntPtr]0xFFFF, 0x1A, [IntPtr]::Zero, "Environment", 2, 5000, [ref][IntPtr]::Zero)
}
Install-Init
Install-Opam
Install-Haxe-Deps
Setup-Paths