/
bootstrap.ps1
171 lines (149 loc) · 5.6 KB
/
bootstrap.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#Requires -RunAsAdministrator
# this may be needed to run the script:
# Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
$ErrorActionPreference = "Stop"
$envscope = "Machine"
function Check-ChocoPkg {
param ($pkg)
Write-output "Checking for $pkg..."
if ($choco_list -like "*$pkg*")
{
Write-output "$pkg already installed"
}
else
{
Write-output "Installing $pkg..."
choco install --yes $pkg
refreshenv
}
}
function Rename-IfExist {
param ($path, $from, $to)
if (Test-Path -Path "$path\$from")
{
Write-output "Renaming $path/$from to $to..."
Rename-Item -Path "$path\$from" "$path\$to"
}
}
function Add-ToPath {
param($path)
Write-output "Updating path with $path..."
$cur = [Environment]::GetEnvironmentVariable("Path", "$envscope")
if ($cur -like "*$path*")
{
Write-output "$path already present"
}
else
{
$newpath = $cur + ";$path"
[Environment]::SetEnvironmentVariable("Path", "$newpath", "$envscope")
Write-output "Done"
}
}
function Download-ExtractZip {
param($what, $path, $marker, $url)
if (Test-Path -Path "$path/$marker")
{
Write-output "$what already processed ($marker present)"
return
}
Write-output "Downloading $url in $what.zip..."
$tmp = "$Env:TEMP/$what.zip"
curl.exe -sSL -o "$tmp" $url
if (!$?)
{
throw "Error downloading the archive"
}
Write-output "Extracting $what.zip in $path"
7z.exe x "$tmp" -o"$path"
if (!$?)
{
throw "Error extracting the archive"
}
}
$error.clear()
try {
Write-output "Checking for chocolatey..."
choco -v
Write-output "chocolatey found"
}
catch {
Write-output "Installing chocolatey..."
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
$choco_list = choco list --local-only | Out-String
Check-ChocoPkg activeperl
Check-ChocoPkg python
Check-ChocoPkg openssl
Check-ChocoPkg winflexbison3
Rename-IfExist "C:\ProgramData\chocolatey\bin" "win_flex.exe" "flex.exe"
Rename-IfExist "C:\ProgramData\chocolatey\bin" "win_bison.exe" "bison.exe"
Check-ChocoPkg git
Check-ChocoPkg 7zip
Check-ChocoPkg diffutils
Check-ChocoPkg visualstudio2019buildtools
Check-ChocoPkg visualstudio2019community
Check-ChocoPkg visualstudio2019-workload-vctools
Check-ChocoPkg visualcpp-build-tools
$gettext_ver = "0.18.1.1-2"
$nls_path = "C:/gettext-$gettext_ver"
Download-ExtractZip "gettext-runtime-dev-$gettext_ver" "$nls_path" "lib/libintl.lib" "https://download.gnome.org/binaries/win64/dependencies/gettext-runtime-dev_$($gettext_ver)_win64.zip"
Rename-IfExist "$nls_path/lib" "intl.lib" "libintl.lib"
Download-ExtractZip "gettext-runtime_$gettext_ver" "$nls_path" "bin/libintl-8.dll" "https://download.gnome.org/binaries/win64/dependencies/gettext-runtime_$($gettext_ver)_win64.zip"
Download-ExtractZip "gettext-tools-dev_$gettext_ver" "$nls_path" "bin/msgfmt.exe" "https://download.gnome.org/binaries/win64/dependencies/gettext-tools-dev_$($gettext_ver)_win64.zip"
Add-ToPath "$nls_path/bin"
Write-output "Linking VS 2019 command line tool to the desktop..."
$dev_cmd_bat_name = "LaunchDevCmd.bat"
$dev_cmd_bat_path = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\"
$dest_bat = [Environment]::GetFolderPath('CommonDesktopDirectory') + "\$dev_cmd_bat_name"
if (Test-Path -Path "$dest_bat")
{
Write-output "Link already exists"
}
else
{
New-Item -Path $dest_bat -ItemType SymbolicLink -Value "$dev_cmd_bat_path\$dev_cmd_bat_name"
}
$vcpath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\"
$nmake_path = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64"
$msbuild_path = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
$vcvarsall_path = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build"
Add-ToPath $nmake_path
Add-ToPath $msbuild_path
Add-ToPath $vcvarsall_path
Write-output "Setting VCTargetsPath environment variable..."
[Environment]::SetEnvironmentVariable("VCTargetsPath", "$vcpath", "$envscope")
$launcher = [Environment]::GetFolderPath('CommonDesktopDirectory') + "\postgres.bat"
Write-output "Creating launcher..."
if (Test-Path -Path "$launcher")
{
Write-output "Launcher already exists"
}
else
{
New-Item "$launcher" -ItemType File -Value "@TITLE PostgreSQL dev`r`n"
Add-Content "$launcher" '@%comspec% /k " vcvarsall x64 && cd C:\Users\user/postgres/src/tools/msvc'
Write-output "Done"
}
$config_pl = "C:\config.pl"
Write-output "Creating $config_pl..."
if (Test-Path -Path "$config_pl")
{
Write-output "config.pl already exists"
}
else
{
New-Item "$config_pl" -ItemType File -Value "# Configuration arguments for vcbuild."
Add-Content "$config_pl" "`r`n"
Add-Content "$config_pl" "use strict;"
Add-Content "$config_pl" "use warnings;"
Add-Content "$config_pl" "our `$config;"
Add-Content "$config_pl" "`r`n"
Add-Content "$config_pl" "`$config->{tap_tests} = 1;"
Add-Content "$config_pl" "`$config->{asserts} = 1;"
Add-Content "$config_pl" "`$config->{nls} = '$nls_path';"
Add-Content "$config_pl" "`$config->{perl} = 'C:/Perl64';"
Add-Content "$config_pl" "`$config->{python} = 'C:/Python310';"
Add-Content "$config_pl" "`$config->{openssl} = 'C:/Program Files/OpenSSL-Win64';"
Write-output "Done"
}