-
Notifications
You must be signed in to change notification settings - Fork 7
/
make.ps1
147 lines (131 loc) · 5.19 KB
/
make.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
# Stop execution on any error
$ErrorActionPreference = "Stop"
# Set the environment variables
. .\env.ps1
function Extract-ZipFile {
param (
[string]$zipFilePath,
[string]$destinationPath
)
if (Test-Path $SEVENZIP) {
& $SEVENZIP x "$zipFilePath" -o"$destinationPath"
Start-Sleep -Seconds 5
} else {
Expand-Archive -Path "$zipFilePath" -DestinationPath "$destinationPath"
}
Remove-Item -Force "$zipFilePath"
}
function Compress-ToZipFile {
param (
[string]$sourcePath,
[string]$destinationPath
)
if (Test-Path $SEVENZIP) {
& $SEVENZIP a "$destinationPath" -y "$sourcePath"
} else {
Compress-Archive -Path "$sourcePath" -DestinationPath "$destinationPath"
}
}
function Start-Bootstrapping {
Write-Host "`n--- Start bootstrapping ---" -ForegroundColor blue
& ./clean.ps1
New-Item -ItemType Directory -Path $MD
Copy-Item "src\*.bat" $MD
Copy-Item "src\*.ps1" $MD
Copy-Item "doc" "$MD\doc" -Recurse
Write-Host "`n--- End bootstrapping ---" -ForegroundColor green
}
function Get-VCRedist {
Write-Host "`n--- Download VCREDIST ---" -ForegroundColor blue
Invoke-WebRequest -Uri $VCREDIST_REF -OutFile "$MD\vc_redist.x64.exe"
Write-Host "`n--- VCREDIST downloaded ---" -ForegroundColor green
}
function Get-ETCD {
Write-Host "`n--- Download ETCD ---" -ForegroundColor blue
Invoke-WebRequest -Uri $ETCD_REF -OutFile "$env:TEMP\etcd.zip"
Extract-ZipFile "$env:TEMP\etcd.zip" "$MD"
Rename-Item "$MD\etcd-*" "etcd"
Copy-Item "src\etcd.yaml" "$MD\etcd"
Write-Host "`n--- ETCD downloaded ---" -ForegroundColor green
}
function Get-Micro {
Write-Host "`n--- Download MICRO ---" -ForegroundColor blue
Invoke-WebRequest -Uri $MICRO_REF -OutFile "$env:TEMP\micro.zip"
Extract-ZipFile "$env:TEMP\micro.zip" "$MD"
Rename-Item "$MD\micro-*" "micro"
Write-Host "`n--- MICRO downloaded ---" -ForegroundColor green
}
function Get-VIPManager {
Write-Host "`n--- Download VIP-MANAGER ---" -ForegroundColor blue
Invoke-WebRequest -Uri $VIP_REF -OutFile "$env:TEMP\vip.zip"
Extract-ZipFile "$env:TEMP\vip.zip" "$MD"
Rename-Item "$MD\vip-manager*" "vip-manager"
Remove-Item "$MD\vip-manager\*.yml" -ErrorAction SilentlyContinue
Copy-Item "src\vip.yaml" "$MD\vip-manager"
Write-Host "`n--- VIP-MANAGER downloaded ---" -ForegroundColor green
}
function Get-PostgreSQL {
Write-Host "`n--- Download POSTGRESQL ---" -ForegroundColor blue
Invoke-WebRequest -Uri $PGSQL_REF -OutFile "$env:TEMP\pgsql.zip"
Extract-ZipFile "$env:TEMP\pgsql.zip" "$MD"
Remove-Item -Recurse -Force "$MD\pgsql\pgAdmin 4", "$MD\pgsql\symbols"
Write-Host "`n--- POSTGRESQL downloaded ---" -ForegroundColor green
}
function Get-Patroni {
Write-Host "`n--- Download PATRONI ---" -ForegroundColor blue
Invoke-WebRequest -Uri $PATRONI_REF -OutFile "$env:TEMP\patroni.zip"
Extract-ZipFile "$env:TEMP\patroni.zip" "$MD"
Rename-Item "$MD\patroni-*" "patroni"
Remove-Item "$MD\patroni\postgres?.yml"
Copy-Item "src\patroni.yaml" "$MD\patroni"
Write-Host "`n--- PATRONI downloaded ---" -ForegroundColor green
}
function Update-PythonAndPIP {
Write-Host "`n--- Update Python and PIP installation ---" -ForegroundColor blue
& "./install-python.ps1"
Move-Item "python-install.exe" "$MD"
Write-Host "`n--- Python and PIP installation updated ---" -ForegroundColor green
}
function Get-PatroniPackages {
Write-Host "`n--- Download PATRONI packages ---" -ForegroundColor blue
Set-Location "$MD\patroni"
& $PIP download -r requirements.txt -d .patroni-packages
& $PIP download pip pip_install setuptools wheel cdiff psycopg2-binary -d .patroni-packages
Set-Location -Path "..\.."
Write-Host "`n--- PATRONI packages downloaded ---" -ForegroundColor green
}
function Get-WinSW {
Write-Host "`n--- Download WINSW ---" -ForegroundColor blue
Invoke-WebRequest -Uri $WINSW_REF -OutFile "$MD\patroni\patroni_service.exe"
Copy-Item "src\patroni_service.xml" "$MD\patroni"
Copy-Item "$MD\patroni\patroni_service.exe" "$MD\etcd\etcd_service.exe" -Force
Copy-Item "src\etcd_service.xml" "$MD\etcd"
Copy-Item "$MD\patroni\patroni_service.exe" "$MD\vip-manager\vip_service.exe" -Force
Copy-Item "src\vip_service.xml" "$MD\vip-manager"
Write-Host "`n--- WINSW downloaded ---" -ForegroundColor green
}
function Export-Assets {
Write-Host "`n--- Creating windows installer ---" -ForegroundColor blue
if (-Not (Test-Path $INNOTOOL)) {
Write-Host "$INNOTOOL does not exist" -ForegroundColor Red
Write-Host "Please install Innotool and set the INNOTOOL environment variable." -ForegroundColor Red
exit 1
}
& $ISCC $ISSFile
Write-Host "`n--- Installer generated successfully ---" -ForegroundColor green
Write-Host "`n--- Prepare archive ---" -ForegroundColor blue
Compress-ToZipFile "$MD" "$MD.zip"
Write-Host "`n--- Archive compressed ---" -ForegroundColor green
}
Start-Bootstrapping
Get-VCRedist
Get-ETCD
Get-Micro
Get-VIPManager
Get-PostgreSQL
Get-Patroni
Update-PythonAndPIP
Get-PatroniPackages
Get-WinSW
Export-Assets
Write-Host "`n--- PACKAGING FINISHED ---" -ForegroundColor green